Skip to content

Commit 557a45a

Browse files
marainodopey
authored andcommitted
Update template tests.
1 parent b179ad3 commit 557a45a

File tree

4 files changed

+19
-4
lines changed

4 files changed

+19
-4
lines changed

authority/ssh_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ func TestAuthority_GetSSHConfig(t *testing.T) {
407407
}
408408
userOutputWithUserData := []templates.Output{
409409
{Name: "include.tpl", Type: templates.File, Comment: "#", Path: "ssh/include", Content: []byte("Host *\n\tInclude /home/user/.step/ssh/config")},
410-
{Name: "config.tpl", Type: templates.File, Comment: "#", Path: "ssh/config", Content: []byte("Match exec \"step ssh check-host %h\"\n\tForwardAgent yes\n\tUserKnownHostsFile /home/user/.step/ssh/known_hosts")},
410+
{Name: "config.tpl", Type: templates.File, Comment: "#", Path: "ssh/config", Content: []byte("Match exec \"step ssh check-host %h\"\n\tForwardAgent yes\n\tUserKnownHostsFile /home/user/.step/ssh/known_hosts\n\tProxyCommand step ssh proxycommand %r %h %p\n")},
411411
}
412412
hostOutputWithUserData := []templates.Output{
413413
{Name: "sshd_config.tpl", Type: templates.File, Comment: "#", Path: "/etc/ssh/sshd_config", Content: []byte("TrustedUserCAKeys /etc/ssh/ca.pub\nHostCertificate /etc/ssh/ssh_host_ecdsa_key-cert.pub\nHostKey /etc/ssh/ssh_host_ecdsa_key")},
+10-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
11
Match exec "step ssh check-host %h"
22
ForwardAgent yes
3-
UserKnownHostsFile {{.User.StepPath}}/ssh/known_hosts
3+
{{- if .User.User }}
4+
User {{.User.User}}
5+
{{- end }}
6+
{{- if or .User.GOOS "none" | eq "windows" }}
7+
UserKnownHostsFile {{.User.StepPath}}\ssh\known_hosts
8+
ProxyCommand C:\Windows\System32\cmd.exe /c step ssh proxycommand %r %h %p
9+
{{- else }}
10+
UserKnownHostsFile {{.User.StepPath}}/ssh/known_hosts
11+
ProxyCommand step ssh proxycommand %r %h %p
12+
{{- end }}
+5-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
11
Host *
2-
Include {{.User.StepPath}}/ssh/config
2+
{{- if or .User.GOOS "linux" | eq "windows" }}
3+
Include {{ .User.StepPath | replace "\\" "/" | trimPrefix "C:" }}/ssh/config
4+
{{- else }}
5+
Include {{.User.StepPath}}/ssh/config
6+
{{- end }}

templates/templates_test.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,8 @@ func TestTemplate_Render(t *testing.T) {
230230
},
231231
"User": map[string]string{
232232
"StepPath": "/tmp/.step",
233+
"User": "john",
234+
"GOOS": "linux",
233235
},
234236
}
235237

@@ -271,7 +273,7 @@ func TestTemplate_Render(t *testing.T) {
271273
return
272274
}
273275
if !reflect.DeepEqual(got, tt.want) {
274-
t.Errorf("Template.Render() = %v, want %v", got, tt.want)
276+
t.Errorf("Template.Render() = %v, want %v", string(got), string(tt.want))
275277
}
276278
})
277279
}

0 commit comments

Comments
 (0)