Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions provider/parameter.go
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,12 @@ func (v *Validation) Valid(typ, value string) error {
if v.Monotonic != "" && v.Monotonic != ValidationMonotonicIncreasing && v.Monotonic != ValidationMonotonicDecreasing {
return fmt.Errorf("number monotonicity can be either %q or %q", ValidationMonotonicIncreasing, ValidationMonotonicDecreasing)
}
case "list(string)":
var listOfStrings []string
err := json.Unmarshal([]byte(value), &listOfStrings)
if err != nil {
return fmt.Errorf("value %q is not valid list of strings", value)
}
}
return nil
}
Expand Down
15 changes: 15 additions & 0 deletions provider/parameter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,19 @@ func TestValueValidatesType(t *testing.T) {
Min: 0,
Max: 2,
Monotonic: "decreasing",
}, {
Name: "ValidListOfStrings",
Type: "list(string)",
Value: `["first","second","third"]`,
}, {
Name: "InvalidListOfStrings",
Type: "list(string)",
Value: `["first","second","third"`,
Error: regexp.MustCompile("is not valid list of strings"),
}, {
Name: "EmptyListOfStrings",
Type: "list(string)",
Value: `[]`,
}} {
tc := tc
t.Run(tc.Name, func(t *testing.T) {
Expand All @@ -529,6 +542,8 @@ func TestValueValidatesType(t *testing.T) {
if tc.Error != nil {
require.Error(t, err)
require.True(t, tc.Error.MatchString(err.Error()), "got: %s", err.Error())
} else {
require.NoError(t, err)
}
})
}
Expand Down