Skip to content

fix: prompt when parameter options are incompatible #9247

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Aug 23, 2023
Prev Previous commit
Next Next commit
After merge
  • Loading branch information
mtojek committed Aug 23, 2023
commit e617d16b1fcd97ea5c1c5a0d7f3520f1900523b2
67 changes: 0 additions & 67 deletions cli/update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -597,73 +597,6 @@ func TestUpdateValidateRichParameters(t *testing.T) {
<-doneChan
})

t.Run("RequiredImmutableParameterAdded", func(t *testing.T) {
t.Parallel()

// Create template and workspace
client := coderdtest.New(t, &coderdtest.Options{IncludeProvisionerDaemon: true})
user := coderdtest.CreateFirstUser(t, client)

templateParameters := []*proto.RichParameter{
{Name: stringParameterName, Type: "string", Mutable: true, Required: true, Options: []*proto.RichParameterOption{
{Name: "First option", Description: "This is first option", Value: "1st"},
{Name: "Second option", Description: "This is second option", Value: "2nd"},
{Name: "Third option", Description: "This is third option", Value: "3rd"},
}},
}
version := coderdtest.CreateTemplateVersion(t, client, user.OrganizationID, prepareEchoResponses(templateParameters))
coderdtest.AwaitTemplateVersionJob(t, client, version.ID)
template := coderdtest.CreateTemplate(t, client, user.OrganizationID, version.ID)

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: add required, immutable parameter
updatedTemplateParameters := []*proto.RichParameter{
templateParameters[0],
{Name: immutableParameterName, Type: "string", Mutable: false, Required: true, Options: []*proto.RichParameterOption{
{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"},
}},
}

updatedVersion := coderdtest.UpdateTemplateVersion(t, client, user.OrganizationID, prepareEchoResponses(updatedTemplateParameters), template.ID)
coderdtest.AwaitTemplateVersionJob(t, client, updatedVersion.ID)
err = client.UpdateActiveTemplateVersion(context.Background(), template.ID, codersdk.UpdateActiveTemplateVersion{
ID: updatedVersion.ID,
})
require.NoError(t, err)

// 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)
go func() {
defer close(doneChan)
err := inv.Run()
assert.NoError(t, err)
}()

matches := []string{
immutableParameterName, "thi",
"Planning workspace...", "",
}
for i := 0; i < len(matches); i += 2 {
match := matches[i]
value := matches[i+1]
pty.ExpectMatch(match)

if value != "" {
pty.WriteLine(value)
}
}
<-doneChan
})

t.Run("ParameterOptionChanged", func(t *testing.T) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a test case where the chosen template parameter disappears completely?

e.g. before: { 1st, 2nd, 3rd }, after: { 1st, 3rd, 4th }

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added!

t.Parallel()

Expand Down