Skip to content

Commit 0da0b47

Browse files
committed
test: ParameterOptionChanged
1 parent 349c6ca commit 0da0b47

File tree

1 file changed

+60
-1
lines changed

1 file changed

+60
-1
lines changed

cli/update_test.go

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -593,12 +593,71 @@ func TestUpdateValidateRichParameters(t *testing.T) {
593593
assert.NoError(t, err)
594594
}()
595595

596+
pty.ExpectMatch("Planning workspace...")
597+
<-doneChan
598+
})
599+
600+
t.Run("ParameterOptionChanged", func(t *testing.T) {
601+
t.Parallel()
602+
603+
// Create template and workspace
604+
client := coderdtest.New(t, &coderdtest.Options{IncludeProvisionerDaemon: true})
605+
user := coderdtest.CreateFirstUser(t, client)
606+
607+
templateParameters := []*proto.RichParameter{
608+
{Name: stringParameterName, Type: "string", Mutable: true, Required: true, Options: []*proto.RichParameterOption{
609+
{Name: "First option", Description: "This is first option", Value: "1st"},
610+
{Name: "Second option", Description: "This is second option", Value: "2nd"},
611+
{Name: "Third option", Description: "This is third option", Value: "3rd"},
612+
}},
613+
}
614+
version := coderdtest.CreateTemplateVersion(t, client, user.OrganizationID, prepareEchoResponses(templateParameters))
615+
coderdtest.AwaitTemplateVersionJob(t, client, version.ID)
616+
template := coderdtest.CreateTemplate(t, client, user.OrganizationID, version.ID)
617+
618+
inv, root := clitest.New(t, "create", "my-workspace", "--yes", "--template", template.Name, "--parameter", fmt.Sprintf("%s=%s", stringParameterName, "2nd"))
619+
clitest.SetupConfig(t, client, root)
620+
err := inv.Run()
621+
require.NoError(t, err)
622+
623+
// Update template
624+
updatedTemplateParameters := []*proto.RichParameter{
625+
{Name: stringParameterName, Type: "string", Mutable: true, Required: true, Options: []*proto.RichParameterOption{
626+
{Name: "first_option", Description: "This is first option", Value: "1"},
627+
{Name: "second_option", Description: "This is second option", Value: "2"},
628+
{Name: "third_option", Description: "This is third option", Value: "3"},
629+
}},
630+
}
631+
632+
updatedVersion := coderdtest.UpdateTemplateVersion(t, client, user.OrganizationID, prepareEchoResponses(updatedTemplateParameters), template.ID)
633+
coderdtest.AwaitTemplateVersionJob(t, client, updatedVersion.ID)
634+
err = client.UpdateActiveTemplateVersion(context.Background(), template.ID, codersdk.UpdateActiveTemplateVersion{
635+
ID: updatedVersion.ID,
636+
})
637+
require.NoError(t, err)
638+
639+
// Update the workspace
640+
inv, root = clitest.New(t, "update", "my-workspace")
641+
clitest.SetupConfig(t, client, root)
642+
doneChan := make(chan struct{})
643+
pty := ptytest.New(t).Attach(inv)
644+
go func() {
645+
defer close(doneChan)
646+
err := inv.Run()
647+
assert.NoError(t, err)
648+
}()
649+
596650
matches := []string{
597-
"Planning workspace...", "",
651+
"aaaa", "",
598652
}
599653
for i := 0; i < len(matches); i += 2 {
600654
match := matches[i]
655+
value := matches[i+1]
601656
pty.ExpectMatch(match)
657+
658+
if value != "" {
659+
pty.WriteLine(value)
660+
}
602661
}
603662
<-doneChan
604663
})

0 commit comments

Comments
 (0)