Skip to content

Commit ff32746

Browse files
committed
Add test case for error executing template.
1 parent e3ae751 commit ff32746

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

authority/ssh_test.go

+18-1
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,14 @@ func TestAuthority_GetSSHConfig(t *testing.T) {
398398
{Name: "config.tpl", Type: templates.File, TemplatePath: "./testdata/templates/config.tpl", Path: "ssh/config", Comment: "#"},
399399
},
400400
Host: []templates.Template{
401-
{Name: "sshd_config.tpl", Type: templates.File, TemplatePath: "./testdata/templates/sshd_config.tpl", Path: "/etc/ssh/sshd_config", Comment: "#"},
401+
{
402+
Name: "sshd_config.tpl",
403+
Type: templates.File,
404+
TemplatePath: "./testdata/templates/sshd_config.tpl",
405+
Path: "/etc/ssh/sshd_config",
406+
Comment: "#",
407+
RequiredData: []string{"Certificate", "Key"},
408+
},
402409
},
403410
},
404411
Data: map[string]interface{}{
@@ -429,6 +436,14 @@ func TestAuthority_GetSSHConfig(t *testing.T) {
429436
},
430437
}
431438

439+
tmplConfigFail := &templates.Templates{
440+
SSH: &templates.SSHTemplates{
441+
User: []templates.Template{
442+
{Name: "fail.tpl", Type: templates.File, TemplatePath: "./testdata/templates/fail.tpl", Path: "ssh/fail", Comment: "#"},
443+
},
444+
},
445+
}
446+
432447
type fields struct {
433448
templates *templates.Templates
434449
userSigner ssh.Signer
@@ -456,6 +471,8 @@ func TestAuthority_GetSSHConfig(t *testing.T) {
456471
{"userError", fields{tmplConfigErr, userSigner, hostSigner}, args{"user", nil}, nil, true},
457472
{"hostError", fields{tmplConfigErr, userSigner, hostSigner}, args{"host", map[string]string{"Function": "foo"}}, nil, true},
458473
{"noTemplates", fields{nil, userSigner, hostSigner}, args{"user", nil}, nil, true},
474+
{"missingData", fields{tmplConfigWithUserData, userSigner, hostSigner}, args{"host", map[string]string{"Certificate": "ssh_host_ecdsa_key-cert.pub"}}, nil, true},
475+
{"failError", fields{tmplConfigFail, userSigner, hostSigner}, args{"user", nil}, nil, true},
459476
}
460477
for _, tt := range tests {
461478
t.Run(tt.name, func(t *testing.T) {

authority/testdata/templates/fail.tpl

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{{ fail "This template will fail" }}

0 commit comments

Comments
 (0)