-
Notifications
You must be signed in to change notification settings - Fork 886
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
Changes from all commits
33214f5
e831d24
e5421c4
349c6ca
0da0b47
1c64cfe
1e41500
8cf4b15
0635b5c
80249a5
e617d16
75d0f41
c03a581
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -593,12 +593,138 @@ func TestUpdateValidateRichParameters(t *testing.T) { | |
assert.NoError(t, err) | ||
}() | ||
|
||
pty.ExpectMatch("Planning workspace...") | ||
<-doneChan | ||
}) | ||
|
||
t.Run("ParameterOptionChanged", func(t *testing.T) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 } There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added! |
||
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 | ||
updatedTemplateParameters := []*proto.RichParameter{ | ||
{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"}, | ||
{Name: "third_option", Description: "This is third option", Value: "3"}, | ||
}}, | ||
} | ||
|
||
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{ | ||
stringParameterName, "second_option", | ||
"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("ParameterOptionDisappeared", 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 - 2nd option disappeared, 4th option added | ||
updatedTemplateParameters := []*proto.RichParameter{ | ||
{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: "Fourth option", Description: "This is fourth option", Value: "4th"}, | ||
}}, | ||
} | ||
|
||
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{ | ||
stringParameterName, "Third option", | ||
"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 | ||
}) | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -69,7 +69,6 @@ const ( | |
type JobErrorCode string | ||
|
||
const ( | ||
MissingTemplateParameter JobErrorCode = "MISSING_TEMPLATE_PARAMETER" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. for reviewers: used by old legacy parameters (do not exist anymore) |
||
RequiredTemplateVariables JobErrorCode = "REQUIRED_TEMPLATE_VARIABLES" | ||
) | ||
|
||
|
@@ -81,7 +80,7 @@ type ProvisionerJob struct { | |
CompletedAt *time.Time `json:"completed_at,omitempty" format:"date-time"` | ||
CanceledAt *time.Time `json:"canceled_at,omitempty" format:"date-time"` | ||
Error string `json:"error,omitempty"` | ||
ErrorCode JobErrorCode `json:"error_code,omitempty" enums:"MISSING_TEMPLATE_PARAMETER,REQUIRED_TEMPLATE_VARIABLES"` | ||
ErrorCode JobErrorCode `json:"error_code,omitempty" enums:"REQUIRED_TEMPLATE_VARIABLES"` | ||
Status ProvisionerJobStatus `json:"status" enums:"pending,running,succeeded,canceling,canceled,failed"` | ||
WorkerID *uuid.UUID `json:"worker_id,omitempty" format:"uuid"` | ||
FileID uuid.UUID `json:"file_id" format:"uuid"` | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for reviewers:
Message: "Unable to validate parameter X"
Detail: "parameter value must match one of options"
^ this should be consistent with site UI error