Skip to content

Commit abf3a3a

Browse files
committed
cli test
1 parent a4431a6 commit abf3a3a

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

cli/create_test.go

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,8 @@ func TestCreateValidateRichParameters(t *testing.T) {
453453
stringParameterName = "string_parameter"
454454
stringParameterValue = "abc"
455455

456+
listOfStringsParameterName = "list_of_strings_parameter"
457+
456458
numberParameterName = "number_parameter"
457459
numberParameterValue = "7"
458460

@@ -468,6 +470,10 @@ func TestCreateValidateRichParameters(t *testing.T) {
468470
{Name: stringParameterName, Type: "string", Mutable: true, ValidationRegex: "^[a-z]+$", ValidationError: "this is error"},
469471
}
470472

473+
listOfStringsRichParameters := []*proto.RichParameter{
474+
{Name: listOfStringsParameterName, Type: "list(string)", Mutable: true, DefaultValue: `["aaa","bbb","ccc"]`},
475+
}
476+
471477
boolRichParameters := []*proto.RichParameter{
472478
{Name: boolParameterName, Type: "bool", Mutable: true},
473479
}
@@ -607,6 +613,43 @@ func TestCreateValidateRichParameters(t *testing.T) {
607613
}
608614
<-doneChan
609615
})
616+
617+
t.Run("ValidateListOfStrings", func(t *testing.T) {
618+
t.Parallel()
619+
620+
client := coderdtest.New(t, &coderdtest.Options{IncludeProvisionerDaemon: true})
621+
user := coderdtest.CreateFirstUser(t, client)
622+
version := coderdtest.CreateTemplateVersion(t, client, user.OrganizationID, prepareEchoResponses(listOfStringsRichParameters))
623+
coderdtest.AwaitTemplateVersionJob(t, client, version.ID)
624+
template := coderdtest.CreateTemplate(t, client, user.OrganizationID, version.ID)
625+
626+
cmd, root := clitest.New(t, "create", "my-workspace", "--template", template.Name)
627+
clitest.SetupConfig(t, client, root)
628+
doneChan := make(chan struct{})
629+
pty := ptytest.New(t)
630+
cmd.SetIn(pty.Input())
631+
cmd.SetOut(pty.Output())
632+
go func() {
633+
defer close(doneChan)
634+
err := cmd.Execute()
635+
assert.NoError(t, err)
636+
}()
637+
638+
matches := []string{
639+
listOfStringsParameterName, "",
640+
"aaa, bbb, ccc", "",
641+
"Confirm create?", "yes",
642+
}
643+
for i := 0; i < len(matches); i += 2 {
644+
match := matches[i]
645+
value := matches[i+1]
646+
pty.ExpectMatch(match)
647+
if value != "" {
648+
pty.WriteLine(value)
649+
}
650+
}
651+
<-doneChan
652+
})
610653
}
611654

612655
func TestCreateWithGitAuth(t *testing.T) {

0 commit comments

Comments
 (0)