-
Notifications
You must be signed in to change notification settings - Fork 894
feat(coderd): support ephemeral parameters #8367
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
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
ef50c35
WIP
mtojek de38911
WIP2
mtojek 3239d07
Merge branch 'main' into 6828-support-ephemeral-parameters
mtojek 469fcc2
fix
mtojek 712519f
fix
mtojek ec04dc5
cleanup
mtojek f1f3a0a
Refs to ephemeral
mtojek 533dde3
fix: frontend
mtojek 97df39f
fmt
mtojek 4ff2705
make gen
mtojek f826d99
resolver: if not ephemeral
mtojek cc20564
Merge branch 'main' into 6828-support-ephemeral-parameters
mtojek 35321fc
ParameterResolver tests
mtojek feceec3
WIP
mtojek e8cd16d
Tests: resources
mtojek ffb7b94
fmt
mtojek 85044d3
Long ephemeral test
mtojek 3636b70
Merge branch 'main' into 6828-support-ephemeral-parameters
mtojek 343c87e
remove debug
mtojek 38eacbf
fix: go.mod
mtojek 8e73da8
go mod tidy
mtojek dffefb6
Merge branch 'main' into 6828-support-ephemeral-parameters
mtojek 69e46ee
rename to ephemeralParameter
mtojek File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
ParameterResolver tests
- Loading branch information
commit 35321fc3aa3262d7bc75a166ab4be8d9563a0fd8
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -304,3 +304,89 @@ func TestRichParameterValidation(t *testing.T) { | |
} | ||
}) | ||
} | ||
|
||
func TestParameterResolver_ValidateResolve_Ephemeral_OverridePrevious(t *testing.T) { | ||
t.Parallel() | ||
uut := codersdk.ParameterResolver{ | ||
Rich: []codersdk.WorkspaceBuildParameter{{Name: "n", Value: "5"}}, | ||
} | ||
p := codersdk.TemplateVersionParameter{ | ||
Name: "n", | ||
Type: "number", | ||
Mutable: true, | ||
Required: true, | ||
Ephemeral: true, | ||
} | ||
v, err := uut.ValidateResolve(p, &codersdk.WorkspaceBuildParameter{ | ||
Name: "n", | ||
Value: "6", | ||
}) | ||
require.NoError(t, err) | ||
require.Equal(t, "6", v) | ||
} | ||
|
||
func TestParameterResolver_ValidateResolve_Ephemeral_FirstTime(t *testing.T) { | ||
t.Parallel() | ||
uut := codersdk.ParameterResolver{} | ||
p := codersdk.TemplateVersionParameter{ | ||
Name: "n", | ||
Type: "number", | ||
Mutable: true, | ||
Required: true, | ||
Ephemeral: true, | ||
} | ||
v, err := uut.ValidateResolve(p, &codersdk.WorkspaceBuildParameter{ | ||
Name: "n", | ||
Value: "6", | ||
}) | ||
require.NoError(t, err) | ||
require.Equal(t, "6", v) | ||
} | ||
|
||
func TestParameterResolver_ValidateResolve_Ephemeral_UseDefault(t *testing.T) { | ||
t.Parallel() | ||
uut := codersdk.ParameterResolver{} | ||
p := codersdk.TemplateVersionParameter{ | ||
Name: "n", | ||
Type: "number", | ||
Mutable: true, | ||
DefaultValue: "5", | ||
Ephemeral: true, | ||
} | ||
v, err := uut.ValidateResolve(p, nil) | ||
require.NoError(t, err) | ||
require.Equal(t, "5", v) | ||
} | ||
|
||
func TestParameterResolver_ValidateResolve_Ephemeral_UseEmptyDefault(t *testing.T) { | ||
t.Parallel() | ||
uut := codersdk.ParameterResolver{} | ||
p := codersdk.TemplateVersionParameter{ | ||
Name: "n", | ||
Type: "number", | ||
Mutable: true, | ||
DefaultValue: "", | ||
Ephemeral: true, | ||
} | ||
v, err := uut.ValidateResolve(p, nil) | ||
require.NoError(t, err) | ||
require.Equal(t, "", v) | ||
} | ||
|
||
func TestParameterResolver_ValidateResolve_Ephemeral_RequiredButMissing(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. What about a case where required = true, but there's also a default value set? Is this possible and should we test it? 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. |
||
t.Parallel() | ||
uut := codersdk.ParameterResolver{} | ||
p := codersdk.TemplateVersionParameter{ | ||
Name: "n", | ||
Type: "number", | ||
Mutable: true, | ||
Required: true, | ||
Ephemeral: true, | ||
} | ||
// It is more theoretical than practical case. Schema allows to configure a parameter, | ||
// which always requires from initiator to provide the value, but it is not persisted between | ||
// consecutive workspace builds. | ||
v, err := uut.ValidateResolve(p, nil) | ||
require.Error(t, err) // Parameter is required, but not provided. | ||
require.Equal(t, "", v) | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This is an interesting use-case - a required ephemeral value could be the equivalent of a TOS checkbox when building a workspace e.g. "I solemnly swear to not use this workspace for evil. [x]"