Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit e011f73

Browse files
committedMay 6, 2025··
add unit test cases for previous values
1 parent 9274e81 commit e011f73

File tree

2 files changed

+126
-98
lines changed

2 files changed

+126
-98
lines changed
 

‎provider/parameter_test.go

Lines changed: 33 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -881,6 +881,7 @@ func TestParameterValidationEnforcement(t *testing.T) {
881881
OutputValue string
882882
Optional bool
883883
CreateError *regexp.Regexp
884+
Previous *string
884885
}
885886

886887
rows := make([]row, 0)
@@ -898,41 +899,44 @@ func TestParameterValidationEnforcement(t *testing.T) {
898899
continue // Skip rows with empty names
899900
}
900901

901-
optional, err := strconv.ParseBool(columns[8])
902-
if columns[8] != "" {
902+
cname, ctype, cprev, cinput, cdefault, coptions, cvalidation, _, coutput, coptional, cerr :=
903+
columns[0], columns[1], columns[2], columns[3], columns[4], columns[5], columns[6], columns[7], columns[8], columns[9], columns[10]
904+
905+
optional, err := strconv.ParseBool(coptional)
906+
if coptional != "" {
903907
// Value does not matter if not specified
904908
require.NoError(t, err)
905909
}
906910

907911
var rerr *regexp.Regexp
908-
if columns[9] != "" {
909-
rerr, err = regexp.Compile(columns[9])
912+
if cerr != "" {
913+
rerr, err = regexp.Compile(cerr)
910914
if err != nil {
911-
t.Fatalf("failed to parse error column %q: %v", columns[9], err)
915+
t.Fatalf("failed to parse error column %q: %v", cerr, err)
912916
}
913917
}
914918

915919
var options []string
916-
if columns[4] != "" {
917-
options = strings.Split(columns[4], ",")
920+
if coptions != "" {
921+
options = strings.Split(coptions, ",")
918922
}
919923

920924
var validation *provider.Validation
921-
if columns[5] != "" {
925+
if cvalidation != "" {
922926
switch {
923-
case columns[5] == provider.ValidationMonotonicIncreasing || columns[5] == provider.ValidationMonotonicDecreasing:
927+
case cvalidation == provider.ValidationMonotonicIncreasing || cvalidation == provider.ValidationMonotonicDecreasing:
924928
validation = &provider.Validation{
925929
MinDisabled: true,
926930
MaxDisabled: true,
927-
Monotonic: columns[5],
931+
Monotonic: cvalidation,
928932
Error: "monotonicity",
929933
}
930-
case validMinMax.MatchString(columns[5]):
934+
case validMinMax.MatchString(cvalidation):
931935
// Min-Max validation should look like:
932936
// 1-10 :: min=1, max=10
933937
// -10 :: max=10
934938
// 1- :: min=1
935-
parts := strings.Split(columns[5], "-")
939+
parts := strings.Split(cvalidation, "-")
936940
min, _ := strconv.ParseInt(parts[0], 10, 64)
937941
max, _ := strconv.ParseInt(parts[1], 10, 64)
938942
validation = &provider.Validation{
@@ -951,22 +955,30 @@ func TestParameterValidationEnforcement(t *testing.T) {
951955
Max: 0,
952956
MaxDisabled: true,
953957
Monotonic: "",
954-
Regex: columns[5],
958+
Regex: cvalidation,
955959
Error: "regex error",
956960
}
957961
}
958962
}
959963

964+
var prev *string
965+
if cprev != "" {
966+
prev = ptr(cprev)
967+
if cprev == `""` {
968+
prev = ptr("")
969+
}
970+
}
960971
rows = append(rows, row{
961-
Name: columns[0],
962-
Types: strings.Split(columns[1], ","),
963-
InputValue: columns[2],
964-
Default: columns[3],
972+
Name: cname,
973+
Types: strings.Split(ctype, ","),
974+
InputValue: cinput,
975+
Default: cdefault,
965976
Options: options,
966977
Validation: validation,
967-
OutputValue: columns[7],
978+
OutputValue: coutput,
968979
Optional: optional,
969980
CreateError: rerr,
981+
Previous: prev,
970982
})
971983
}
972984

@@ -984,6 +996,9 @@ func TestParameterValidationEnforcement(t *testing.T) {
984996
if row.InputValue != "" {
985997
t.Setenv(provider.ParameterEnvironmentVariable("parameter"), row.InputValue)
986998
}
999+
if row.Previous != nil {
1000+
t.Setenv(provider.ParameterEnvironmentVariablePrevious("parameter"), *row.Previous)
1001+
}
9871002

9881003
if row.CreateError != nil && row.OutputValue != "" {
9891004
t.Errorf("output value %q should not be set if both errors are set", row.OutputValue)

‎provider/testdata/parameter_table.md

Lines changed: 93 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -1,80 +1,93 @@
1-
| Name | Type | Input | Default | Options | Validation | -> | Output | Optional | ErrorCreate |
2-
|----------------------|---------------|-----------|---------|-------------------|------------|----|--------|----------|-----------------|
3-
| | Empty Vals | | | | | | | | |
4-
| Empty | string,number | | | | | | "" | false | |
5-
| EmptyDupeOps | string,number | | | 1,1,1 | | | | | unique |
6-
| EmptyList | list(string) | | | | | | "" | false | |
7-
| EmptyListDupeOpts | list(string) | | | ["a"],["a"] | | | | | unique |
8-
| EmptyMulti | tag-select | | | | | | "" | false | |
9-
| EmptyOpts | string,number | | | 1,2,3 | | | "" | false | |
10-
| EmptyRegex | string | | | | world | | | | regex error |
11-
| EmptyMin | number | | | | 1-10 | | | | 1 < < 10 |
12-
| EmptyMinOpt | number | | | 1,2,3 | 2-5 | | | | valid option |
13-
| EmptyRegexOpt | string | | | "hello","goodbye" | goodbye | | | | valid option |
14-
| EmptyRegexOk | string | | | | .* | | "" | false | |
15-
| | | | | | | | | | |
16-
| | Default Set | No inputs | | | | | | | |
17-
| NumDef | number | | 5 | | | | 5 | true | |
18-
| NumDefVal | number | | 5 | | 3-7 | | 5 | true | |
19-
| NumDefInv | number | | 5 | | 10- | | | | 10 < 5 < 0 |
20-
| NumDefOpts | number | | 5 | 1,3,5,7 | 2-6 | | 5 | true | |
21-
| NumDefNotOpts | number | | 5 | 1,3,7,9 | 2-6 | | | | valid option |
22-
| NumDefInvOpt | number | | 5 | 1,3,5,7 | 6-10 | | | | 6 < 5 < 10 |
23-
| NumDefNotNum | number | | a | | | | | | type "number" |
24-
| NumDefOptsNotNum | number | | 1 | 1,a,2 | | | | | type "number" |
25-
| | | | | | | | | | |
26-
| StrDef | string | | hello | | | | hello | true | |
27-
| StrDefInv | string | | hello | | world | | | | regex error |
28-
| StrDefOpts | string | | a | a,b,c | | | a | true | |
29-
| StrDefNotOpts | string | | a | b,c,d | | | | | valid option |
30-
| StrDefValOpts | string | | a | a,b,c,d,e,f | [a-c] | | a | true | |
31-
| StrDefInvOpt | string | | d | a,b,c,d,e,f | [a-c] | | | | regex error |
32-
| | | | | | | | | | |
33-
| LStrDef | list(string) | | ["a"] | | | | ["a"] | true | |
34-
| LStrDefOpts | list(string) | | ["a"] | ["a"], ["b"] | | | ["a"] | true | |
35-
| LStrDefNotOpts | list(string) | | ["a"] | ["b"], ["c"] | | | | | valid option |
36-
| | | | | | | | | | |
37-
| MulDef | tag-select | | ["a"] | | | | ["a"] | true | |
38-
| MulDefOpts | multi-select | | ["a"] | a,b | | | ["a"] | true | |
39-
| MulDefNotOpts | multi-select | | ["a"] | b,c | | | | | valid option |
40-
| | | | | | | | | | |
41-
| | Input Vals | | | | | | | | |
42-
| NumIns | number | 3 | | | | | 3 | false | |
43-
| NumInsOptsNaN | number | 3 | 5 | a,1,2,3,4,5 | 1-3 | | | | type "number" |
44-
| NumInsNotNum | number | a | | | | | | | type "number" |
45-
| NumInsNotNumInv | number | a | | | 1-3 | | | | 1 < a < 3 |
46-
| NumInsDef | number | 3 | 5 | | | | 3 | true | |
47-
| NumIns/DefInv | number | 3 | 5 | | 1-3 | | 3 | true | |
48-
| NumIns=DefInv | number | 5 | 5 | | 1-3 | | | | 1 < 5 < 3 |
49-
| NumInsOpts | number | 3 | 5 | 1,2,3,4,5 | 1-3 | | 3 | true | |
50-
| NumInsNotOptsVal | number | 3 | 5 | 1,2,4,5 | 1-3 | | | | valid option |
51-
| NumInsNotOptsInv | number | 3 | 5 | 1,2,4,5 | 1-2 | | | true | valid option |
52-
| NumInsNotOpts | number | 3 | 5 | 1,2,4,5 | | | | | valid option |
53-
| NumInsNotOpts/NoDef | number | 3 | | 1,2,4,5 | | | | | valid option |
54-
| | | | | | | | | | |
55-
| StrIns | string | c | | | | | c | false | |
56-
| StrInsDupeOpts | string | c | | a,b,c,c | | | | | unique |
57-
| StrInsDef | string | c | e | | | | c | true | |
58-
| StrIns/DefInv | string | c | e | | [a-c] | | c | true | |
59-
| StrIns=DefInv | string | e | e | | [a-c] | | | | regex error |
60-
| StrInsOpts | string | c | e | a,b,c,d,e | [a-c] | | c | true | |
61-
| StrInsNotOptsVal | string | c | e | a,b,d,e | [a-c] | | | | valid option |
62-
| StrInsNotOptsInv | string | c | e | a,b,d,e | [a-b] | | | | valid option |
63-
| StrInsNotOpts | string | c | e | a,b,d,e | | | | | valid option |
64-
| StrInsNotOpts/NoDef | string | c | | a,b,d,e | | | | | valid option |
65-
| StrInsBadVal | string | c | | a,b,c,d,e | 1-10 | | | | min cannot |
66-
| | | | | | | | | | |
67-
| | list(string) | | | | | | | | |
68-
| LStrIns | list(string) | ["c"] | | | | | ["c"] | false | |
69-
| LStrInsNotList | list(string) | c | | | | | | | list of strings |
70-
| LStrInsDef | list(string) | ["c"] | ["e"] | | | | ["c"] | true | |
71-
| LStrIns/DefInv | list(string) | ["c"] | ["e"] | | [a-c] | | | | regex cannot |
72-
| LStrInsOpts | list(string) | ["c"] | ["e"] | ["c"],["d"],["e"] | | | ["c"] | true | |
73-
| LStrInsNotOpts | list(string) | ["c"] | ["e"] | ["d"],["e"] | | | | | valid option |
74-
| LStrInsNotOpts/NoDef | list(string) | ["c"] | | ["d"],["e"] | | | | | valid option |
75-
| | | | | | | | | | |
76-
| MulInsOpts | multi-select | ["c"] | ["e"] | c,d,e | | | ["c"] | true | |
77-
| MulInsNotListOpts | multi-select | c | ["e"] | c,d,e | | | | | json encoded |
78-
| MulInsNotOpts | multi-select | ["c"] | ["e"] | d,e | | | | | valid option |
79-
| MulInsNotOpts/NoDef | multi-select | ["c"] | | d,e | | | | | valid option |
80-
| MulInsInvOpts | multi-select | ["c"] | ["e"] | c,d,e | [a-c] | | | | regex cannot |
1+
| Name | Type | Previous | Input | Default | Options | Validation | -> | Output | Optional | ErrorCreate |
2+
|----------------------|---------------|----------|-----------|---------|-------------------|------------|----|--------|----------|-----------------|
3+
| | Empty Vals | | | | | | | | | |
4+
| Empty | string,number | | | | | | | "" | false | |
5+
| EmptyDupeOps | string,number | | | | 1,1,1 | | | | | unique |
6+
| EmptyList | list(string) | | | | | | | "" | false | |
7+
| EmptyListDupeOpts | list(string) | | | | ["a"],["a"] | | | | | unique |
8+
| EmptyMulti | tag-select | | | | | | | "" | false | |
9+
| EmptyOpts | string,number | | | | 1,2,3 | | | "" | false | |
10+
| EmptyRegex | string | | | | | world | | | | regex error |
11+
| EmptyMin | number | | | | | 1-10 | | | | 1 < < 10 |
12+
| EmptyMinOpt | number | | | | 1,2,3 | 2-5 | | | | valid option |
13+
| EmptyRegexOpt | string | | | | "hello","goodbye" | goodbye | | | | valid option |
14+
| EmptyRegexOk | string | | | | | .* | | "" | false | |
15+
| | | | | | | | | | | |
16+
| | Default Set | | No inputs | | | | | | | |
17+
| NumDef | number | | | 5 | | | | 5 | true | |
18+
| NumDefVal | number | | | 5 | | 3-7 | | 5 | true | |
19+
| NumDefInv | number | | | 5 | | 10- | | | | 10 < 5 < 0 |
20+
| NumDefOpts | number | | | 5 | 1,3,5,7 | 2-6 | | 5 | true | |
21+
| NumDefNotOpts | number | | | 5 | 1,3,7,9 | 2-6 | | | | valid option |
22+
| NumDefInvOpt | number | | | 5 | 1,3,5,7 | 6-10 | | | | 6 < 5 < 10 |
23+
| NumDefNotNum | number | | | a | | | | | | type "number" |
24+
| NumDefOptsNotNum | number | | | 1 | 1,a,2 | | | | | type "number" |
25+
| NumDefInc | number | 4 | | 5 | | increasing | | 5 | true | |
26+
| NumDefIncBad | number | 6 | | 5 | | increasing | | | | greater |
27+
| NumDefDec | number | 6 | | 5 | | decreasing | | 5 | true | |
28+
| NumDefDecBad | number | 4 | | 5 | | decreasing | | | | lower |
29+
| NumDefDecEq | number | 5 | | 5 | | decreasing | | 5 | true | |
30+
| NumDefIncEq | number | 5 | | 5 | | increasing | | 5 | true | |
31+
| | | | | | | | | | | |
32+
| StrDef | string | | | hello | | | | hello | true | |
33+
| StrMonotonicity | string | | | hello | | increasing | | | | monotonic |
34+
| StrDefInv | string | | | hello | | world | | | | regex error |
35+
| StrDefOpts | string | | | a | a,b,c | | | a | true | |
36+
| StrDefNotOpts | string | | | a | b,c,d | | | | | valid option |
37+
| StrDefValOpts | string | | | a | a,b,c,d,e,f | [a-c] | | a | true | |
38+
| StrDefInvOpt | string | | | d | a,b,c,d,e,f | [a-c] | | | | regex error |
39+
| | | | | | | | | | | |
40+
| LStrDef | list(string) | | | ["a"] | | | | ["a"] | true | |
41+
| LStrDefOpts | list(string) | | | ["a"] | ["a"], ["b"] | | | ["a"] | true | |
42+
| LStrDefNotOpts | list(string) | | | ["a"] | ["b"], ["c"] | | | | | valid option |
43+
| | | | | | | | | | | |
44+
| MulDef | tag-select | | | ["a"] | | | | ["a"] | true | |
45+
| MulDefOpts | multi-select | | | ["a"] | a,b | | | ["a"] | true | |
46+
| MulDefNotOpts | multi-select | | | ["a"] | b,c | | | | | valid option |
47+
| | | | | | | | | | | |
48+
| | Input Vals | | | | | | | | | |
49+
| NumIns | number | | 3 | | | | | 3 | false | |
50+
| NumInsOptsNaN | number | | 3 | 5 | a,1,2,3,4,5 | 1-3 | | | | type "number" |
51+
| NumInsNotNum | number | | a | | | | | | | type "number" |
52+
| NumInsNotNumInv | number | | a | | | 1-3 | | | | 1 < a < 3 |
53+
| NumInsDef | number | | 3 | 5 | | | | 3 | true | |
54+
| NumIns/DefInv | number | | 3 | 5 | | 1-3 | | 3 | true | |
55+
| NumIns=DefInv | number | | 5 | 5 | | 1-3 | | | | 1 < 5 < 3 |
56+
| NumInsOpts | number | | 3 | 5 | 1,2,3,4,5 | 1-3 | | 3 | true | |
57+
| NumInsNotOptsVal | number | | 3 | 5 | 1,2,4,5 | 1-3 | | | | valid option |
58+
| NumInsNotOptsInv | number | | 3 | 5 | 1,2,4,5 | 1-2 | | | true | valid option |
59+
| NumInsNotOpts | number | | 3 | 5 | 1,2,4,5 | | | | | valid option |
60+
| NumInsNotOpts/NoDef | number | | 3 | | 1,2,4,5 | | | | | valid option |
61+
| NumInsInc | number | 4 | 5 | 3 | | increasing | | 5 | true | |
62+
| NumInsIncBad | number | 6 | 5 | 7 | | increasing | | | | greater |
63+
| NumInsDec | number | 6 | 5 | 7 | | decreasing | | 5 | true | |
64+
| NumInsDecBad | number | 4 | 5 | 3 | | decreasing | | | | lower |
65+
| NumInsDecEq | number | 5 | 5 | 5 | | decreasing | | 5 | true | |
66+
| NumInsIncEq | number | 5 | 5 | 5 | | increasing | | 5 | true | |
67+
| | | | | | | | | | | |
68+
| StrIns | string | | c | | | | | c | false | |
69+
| StrInsDupeOpts | string | | c | | a,b,c,c | | | | | unique |
70+
| StrInsDef | string | | c | e | | | | c | true | |
71+
| StrIns/DefInv | string | | c | e | | [a-c] | | c | true | |
72+
| StrIns=DefInv | string | | e | e | | [a-c] | | | | regex error |
73+
| StrInsOpts | string | | c | e | a,b,c,d,e | [a-c] | | c | true | |
74+
| StrInsNotOptsVal | string | | c | e | a,b,d,e | [a-c] | | | | valid option |
75+
| StrInsNotOptsInv | string | | c | e | a,b,d,e | [a-b] | | | | valid option |
76+
| StrInsNotOpts | string | | c | e | a,b,d,e | | | | | valid option |
77+
| StrInsNotOpts/NoDef | string | | c | | a,b,d,e | | | | | valid option |
78+
| StrInsBadVal | string | | c | | a,b,c,d,e | 1-10 | | | | min cannot |
79+
| | | | | | | | | | | |
80+
| | list(string) | | | | | | | | | |
81+
| LStrIns | list(string) | | ["c"] | | | | | ["c"] | false | |
82+
| LStrInsNotList | list(string) | | c | | | | | | | list of strings |
83+
| LStrInsDef | list(string) | | ["c"] | ["e"] | | | | ["c"] | true | |
84+
| LStrIns/DefInv | list(string) | | ["c"] | ["e"] | | [a-c] | | | | regex cannot |
85+
| LStrInsOpts | list(string) | | ["c"] | ["e"] | ["c"],["d"],["e"] | | | ["c"] | true | |
86+
| LStrInsNotOpts | list(string) | | ["c"] | ["e"] | ["d"],["e"] | | | | | valid option |
87+
| LStrInsNotOpts/NoDef | list(string) | | ["c"] | | ["d"],["e"] | | | | | valid option |
88+
| | | | | | | | | | | |
89+
| MulInsOpts | multi-select | | ["c"] | ["e"] | c,d,e | | | ["c"] | true | |
90+
| MulInsNotListOpts | multi-select | | c | ["e"] | c,d,e | | | | | json encoded |
91+
| MulInsNotOpts | multi-select | | ["c"] | ["e"] | d,e | | | | | valid option |
92+
| MulInsNotOpts/NoDef | multi-select | | ["c"] | | d,e | | | | | valid option |
93+
| MulInsInvOpts | multi-select | | ["c"] | ["e"] | c,d,e | [a-c] | | | | regex cannot |

0 commit comments

Comments
 (0)
Please sign in to comment.