Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit2d51bff

Browse files
committed
add cases
1 parent9af5f68 commit2d51bff

File tree

1 file changed

+61
-29
lines changed

1 file changed

+61
-29
lines changed

‎provider/parameter_test.go‎

Lines changed: 61 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -696,35 +696,61 @@ data "coder_parameter" "region" {
696696
//
697697
//nolint:paralleltest,tparallel // Parameters load values from env vars
698698
funcTestParameterValidationEnforcement(t*testing.T) {
699+
// Some interesting observations:
700+
// - Validation logic does not apply to the value of 'options'
701+
//- [NumDefInvOpt] So an invalid option can be present and selected, but would fail
702+
// - Validation logic does not apply to the default if a value is given
703+
//- [NumIns/DefInv] So the default can be invalid if an input value is valid.
704+
// The value is therefore not really optional, but it is marked as such.
705+
// - [NumInsNotOptsVal | NumsInsNotOpts] values do not need to be in the option set?
706+
699707
table:=strings.TrimSpace(`
700-
| Name | Type | Input Value | Default | Options | Validation | -> | Output Value | Optional | Error |
701-
|---------------|---------------|-------------|---------|-------------------|------------|----|--------------|----------|--------------|
702-
| | Empty Vals | | | | | | | | |
703-
| Emty | string,number | | | | | | "" | false | |
704-
| EmtyOpts | string,number | | | 1,2,3 | | | "" | false | |
705-
| EmtyRegex | string | | | | world | | | | regex error |
706-
| EmtyMin | number | | | | 1-10 | | | | 1 < < 10 |
707-
| EmtyMinOpt | number | | | 1,2,3 | 2-5 | | | | 2 < < 5 |
708-
| EmtyRegexOpt | string | | | "hello","goodbye" | goodbye | | | | regex error |
709-
| EmtyRegexOk | string | | | | .* | | "" | false | |
710-
| | | | | | | | | | |
711-
| | Default Set | No inputs | | | | | | | |
712-
| NumDef | number | | 5 | | | | 5 | true | |
713-
| NumDefVal | number | | 5 | | 3-7 | | 5 | true | |
714-
| NumDefInv | number | | 5 | | 10- | | 5 | | 10 < 5 < 0 |
715-
| NumDefOpts | number | | 5 | 1,3,5,7 | 2-6 | | 5 | true | |
716-
| NumDefNotOpts | number | | 5 | 1,3,7,9 | 2-6 | | | | valid option |
717-
| | | | | | | | | | |
718-
| StrDef | string | | hello | | | | hello | true | |
719-
| StrDefInv | string | | hello | | world | | | | regex error |
720-
| StrDefOpts | string | | a | a,b,c | | | a | true | |
721-
| StrDefNotOpts | string | | a | b,c,d | | | | | valid option |
722-
| StrDefOpts | string | | a | a,b,c,d,e,f | [a-c] | | a | true | |
723-
| | | | | | | | | | |
724-
| | Input Vals | | | | | | | | |
725-
| NumIns | number | 3 | 5 | | | | 3 | true | |
726-
| | | | | | | | | | |
727-
| | | | | | | | | | |
708+
| Name | Type | Input Value | Default | Options | Validation | -> | Output Value | Optional | Error |
709+
|---------------------|---------------|-------------|---------|-------------------|------------|----|--------------|----------|--------------|
710+
| | Empty Vals | | | | | | | | |
711+
| Emty | string,number | | | | | | "" | false | |
712+
| EmtyOpts | string,number | | | 1,2,3 | | | "" | false | |
713+
| EmtyRegex | string | | | | world | | | | regex error |
714+
| EmtyMin | number | | | | 1-10 | | | | 1 < < 10 |
715+
| EmtyMinOpt | number | | | 1,2,3 | 2-5 | | | | 2 < < 5 |
716+
| EmtyRegexOpt | string | | | "hello","goodbye" | goodbye | | | | regex error |
717+
| EmtyRegexOk | string | | | | .* | | "" | false | |
718+
| | | | | | | | | | |
719+
| | Default Set | No inputs | | | | | | | |
720+
| NumDef | number | | 5 | | | | 5 | true | |
721+
| NumDefVal | number | | 5 | | 3-7 | | 5 | true | |
722+
| NumDefInv | number | | 5 | | 10- | | | | 10 < 5 < 0 |
723+
| NumDefOpts | number | | 5 | 1,3,5,7 | 2-6 | | 5 | true | |
724+
| NumDefNotOpts | number | | 5 | 1,3,7,9 | 2-6 | | | | valid option |
725+
| NumDefInvOpt | number | | 5 | 1,3,5,7 | 6-10 | | | | 6 < 5 < 10 |
726+
| | | | | | | | | | |
727+
| StrDef | string | | hello | | | | hello | true | |
728+
| StrDefInv | string | | hello | | world | | | | regex error |
729+
| StrDefOpts | string | | a | a,b,c | | | a | true | |
730+
| StrDefNotOpts | string | | a | b,c,d | | | | | valid option |
731+
| StrDefOpts | string | | a | a,b,c,d,e,f | [a-c] | | a | true | |
732+
| StrDefInvOpt | string | | d | a,b,c,d,e,f | [a-c] | | | | regex error |
733+
| | | | | | | | | | |
734+
| | Input Vals | | | | | | | | |
735+
| NumIns | number | 3 | | | | | 3 | false | |
736+
| NumInsDef | number | 3 | 5 | | | | 3 | true | |
737+
| NumIns/DefInv | number | 3 | 5 | | 1-3 | | 3 | true | |
738+
| NumIns=DefInv | number | 5 | 5 | | 1-3 | | | | 1 < 5 < 3 |
739+
| NumInsOpts | number | 3 | 5 | 1,2,3,4,5 | 1-3 | | 3 | true | |
740+
| NumInsNotOptsVal | number | 3 | 5 | 1,2,4,5 | 1-3 | | 3 | true | |
741+
| NumInsNotOptsInv | number | 3 | 5 | 1,2,4,5 | 1-2 | | | true | 1 < 3 < 2 |
742+
| NumInsNotOpts | number | 3 | 5 | 1,2,4,5 | | | 3 | true | |
743+
| NumInsNotOpts/NoDef | number | 3 | | 1,2,4,5 | | | 3 | false | |
744+
| | | | | | | | | | |
745+
| StrIns | string | c | | | | | c | false | |
746+
| StrInsDef | string | c | e | | | | c | true | |
747+
| StrIns/DefInv | string | c | e | | [a-c] | | c | true | |
748+
| NumIns=DefInv | string | e | e | | [a-c] | | | | regex error |
749+
| StrInsOpts | string | c | e | a,b,c,d,e | [a-c] | | c | true | |
750+
| StrInsNotOptsVal | string | c | e | a,b,d,e | [a-c] | | c | true | |
751+
| StrInsNotOptsInv | string | c | e | a,b,d,e | [a-b] | | | | regex error |
752+
| StrInsNotOpts | string | c | e | a,b,d,e | | | c | true | |
753+
| StrInsNotOpts/NoDef | string | c | | a,b,d,e | | | c | false | |
728754
`)
729755

730756
typerowstruct {
@@ -832,6 +858,12 @@ func TestParameterValidationEnforcement(t *testing.T) {
832858
t.Setenv(provider.ParameterEnvironmentVariable("parameter"),row.InputValue)
833859
}
834860

861+
ifrow.Error!=nil {
862+
ifrow.OutputValue!="" {
863+
t.Errorf("output value %q should not be set if error is set",row.OutputValue)
864+
}
865+
}
866+
835867
varcfg strings.Builder
836868
cfg.WriteString("data\"coder_parameter\"\"parameter\" {\n")
837869
cfg.WriteString("\tname =\"parameter\"\n")
@@ -896,7 +928,7 @@ func TestParameterValidationEnforcement(t *testing.T) {
896928
forkey,expected:=rangemap[string]string{
897929
"optional":strconv.FormatBool(row.Optional),
898930
} {
899-
require.Equal(t,expected,param.Primary.Attributes[key])
931+
require.Equal(t,expected,param.Primary.Attributes[key],"optional")
900932
}
901933

902934
returnnil

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp