Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 29 additions & 8 deletions cli/update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -578,13 +578,15 @@ func TestUpdateValidateRichParameters(t *testing.T) {
coderdtest.AwaitTemplateVersionJob(t, client, version.ID)
template := coderdtest.CreateTemplate(t, client, user.OrganizationID, version.ID)

// Create new workspace
inv, root := clitest.New(t, "create", "my-workspace", "--yes", "--template", template.Name, "--parameter", fmt.Sprintf("%s=%s", stringParameterName, "2nd"))
clitest.SetupConfig(t, client, root)
err := inv.Run()
require.NoError(t, err)

// Update template
updatedTemplateParameters := []*proto.RichParameter{
// The order of rich parameter options must be maintained because `cliui.Select` automatically selects the first option during tests.
{Name: stringParameterName, Type: "string", Mutable: true, Required: true, Options: []*proto.RichParameterOption{
{Name: "first_option", Description: "This is first option", Value: "1"},
{Name: "second_option", Description: "This is second option", Value: "2"},
Expand All @@ -602,12 +604,16 @@ func TestUpdateValidateRichParameters(t *testing.T) {
// Update the workspace
inv, root = clitest.New(t, "update", "my-workspace")
clitest.SetupConfig(t, client, root)

doneChan := make(chan struct{})
pty := ptytest.New(t).Attach(inv)
clitest.Start(t, inv)
go func() {
defer close(doneChan)
err := inv.Run()
assert.NoError(t, err)
}()

matches := []string{
stringParameterName, "second_option",
// `cliui.Select` will automatically pick the first option
"Planning workspace...", "",
}
for i := 0; i < len(matches); i += 2 {
Expand All @@ -619,6 +625,8 @@ func TestUpdateValidateRichParameters(t *testing.T) {
pty.WriteLine(value)
}
}

<-doneChan
})

t.Run("ParameterOptionDisappeared", func(t *testing.T) {
Expand All @@ -639,16 +647,19 @@ func TestUpdateValidateRichParameters(t *testing.T) {
coderdtest.AwaitTemplateVersionJob(t, client, version.ID)
template := coderdtest.CreateTemplate(t, client, user.OrganizationID, version.ID)

// Create new workspace
inv, root := clitest.New(t, "create", "my-workspace", "--yes", "--template", template.Name, "--parameter", fmt.Sprintf("%s=%s", stringParameterName, "2nd"))
clitest.SetupConfig(t, client, root)
ptytest.New(t).Attach(inv)
err := inv.Run()
require.NoError(t, err)

// Update template - 2nd option disappeared, 4th option added
updatedTemplateParameters := []*proto.RichParameter{
// The order of rich parameter options must be maintained because `cliui.Select` automatically selects the first option during tests.
{Name: stringParameterName, Type: "string", Mutable: true, Required: true, Options: []*proto.RichParameterOption{
{Name: "First option", Description: "This is first option", Value: "1st"},
{Name: "Third option", Description: "This is third option", Value: "3rd"},
{Name: "First option", Description: "This is first option", Value: "1st"},
{Name: "Fourth option", Description: "This is fourth option", Value: "4th"},
}},
}
Expand All @@ -663,11 +674,16 @@ func TestUpdateValidateRichParameters(t *testing.T) {
// Update the workspace
inv, root = clitest.New(t, "update", "my-workspace")
clitest.SetupConfig(t, client, root)
doneChan := make(chan struct{})
pty := ptytest.New(t).Attach(inv)
clitest.Start(t, inv)
go func() {
defer close(doneChan)
err := inv.Run()
assert.NoError(t, err)
}()

matches := []string{
stringParameterName, "Third option",
// `cliui.Select` will automatically pick the first option
"Planning workspace...", "",
}
for i := 0; i < len(matches); i += 2 {
Expand All @@ -679,6 +695,8 @@ func TestUpdateValidateRichParameters(t *testing.T) {
pty.WriteLine(value)
}
}

<-doneChan
})

t.Run("ImmutableRequiredParameterExists_MutableRequiredParameterAdded", func(t *testing.T) {
Expand Down Expand Up @@ -742,6 +760,7 @@ func TestUpdateValidateRichParameters(t *testing.T) {
pty.WriteLine(value)
}
}

<-doneChan
})

Expand Down Expand Up @@ -771,10 +790,11 @@ func TestUpdateValidateRichParameters(t *testing.T) {
// Update template: add required, immutable parameter
updatedTemplateParameters := []*proto.RichParameter{
templateParameters[0],
// The order of rich parameter options must be maintained because `cliui.Select` automatically selects the first option during tests.
{Name: immutableParameterName, Type: "string", Mutable: false, Required: true, Options: []*proto.RichParameterOption{
{Name: "thi", Description: "This is third option for immutable parameter", Value: "III"},
{Name: "fir", Description: "This is first option for immutable parameter", Value: "I"},
{Name: "sec", Description: "This is second option for immutable parameter", Value: "II"},
{Name: "thi", Description: "This is third option for immutable parameter", Value: "III"},
}},
}

Expand All @@ -797,7 +817,7 @@ func TestUpdateValidateRichParameters(t *testing.T) {
}()

matches := []string{
immutableParameterName, "thi",
// `cliui.Select` will automatically pick the first option
"Planning workspace...", "",
}
for i := 0; i < len(matches); i += 2 {
Expand All @@ -809,6 +829,7 @@ func TestUpdateValidateRichParameters(t *testing.T) {
pty.WriteLine(value)
}
}

<-doneChan
})
}