Skip to content

Commit 9401f38

Browse files
committed
Unit test
1 parent ceebc75 commit 9401f38

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

cli/templatepush_test.go

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -613,6 +613,48 @@ func TestTemplatePush(t *testing.T) {
613613
require.Equal(t, "second_variable", templateVariables[1].Name)
614614
require.Equal(t, "foobar", templateVariables[1].Value)
615615
})
616+
617+
t.Run("CreateTemplate", func(t *testing.T) {
618+
t.Parallel()
619+
client := coderdtest.New(t, &coderdtest.Options{IncludeProvisionerDaemon: true})
620+
user := coderdtest.CreateFirstUser(t, client)
621+
source := clitest.CreateTemplateVersionSource(t, &echo.Responses{
622+
Parse: echo.ParseComplete,
623+
ProvisionApply: provisionCompleteWithAgent,
624+
})
625+
626+
const templateName = "my-template"
627+
args := []string{
628+
"templates",
629+
"push",
630+
templateName,
631+
"--directory", source,
632+
"--test.provisioner", string(database.ProvisionerTypeEcho),
633+
"--create",
634+
}
635+
inv, root := clitest.New(t, args...)
636+
clitest.SetupConfig(t, client, root)
637+
pty := ptytest.New(t).Attach(inv)
638+
639+
waiter := clitest.StartWithWaiter(t, inv)
640+
641+
matches := []struct {
642+
match string
643+
write string
644+
}{
645+
{match: "Upload", write: "yes"},
646+
}
647+
for _, m := range matches {
648+
pty.ExpectMatch(m.match)
649+
pty.WriteLine(m.write)
650+
}
651+
652+
waiter.RequireSuccess()
653+
654+
template, err := client.TemplateByName(context.Background(), user.OrganizationID, templateName)
655+
require.NoError(t, err)
656+
require.Equal(t, templateName, template.Name)
657+
})
616658
})
617659
}
618660

0 commit comments

Comments
 (0)