Skip to content

Commit e6a529d

Browse files
committed
add more validation tests
1 parent c640b02 commit e6a529d

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed

provider/parameter_test.go

+58
Original file line numberDiff line numberDiff line change
@@ -733,6 +733,15 @@ func TestParameterValidation(t *testing.T) {
733733
Value: "delta", // not in option set
734734
ExpectError: regexp.MustCompile("Value must be a valid option"),
735735
},
736+
{
737+
Name: "NumberNotInOptions",
738+
Parameter: provider.Parameter{
739+
Type: "number",
740+
Option: opts("1", "2", "3"),
741+
},
742+
Value: "0", // not in option set
743+
ExpectError: regexp.MustCompile("Value must be a valid option"),
744+
},
736745
{
737746
Name: "NonUniqueOptionNames",
738747
Parameter: provider.Parameter{
@@ -771,6 +780,55 @@ func TestParameterValidation(t *testing.T) {
771780
Value: "not-a-number",
772781
ExpectError: regexp.MustCompile("Parameter value is not of type \"number\""),
773782
},
783+
{
784+
Name: "NotListStringDefault",
785+
Parameter: provider.Parameter{
786+
Type: "list(string)",
787+
Default: "not-a-list",
788+
},
789+
ExpectError: regexp.MustCompile("not a valid list of strings"),
790+
},
791+
{
792+
Name: "NotListStringDefault",
793+
Parameter: provider.Parameter{
794+
Type: "list(string)",
795+
},
796+
Value: "not-a-list",
797+
ExpectError: regexp.MustCompile("not a valid list of strings"),
798+
},
799+
{
800+
Name: "DefaultListStringNotInOptions",
801+
Parameter: provider.Parameter{
802+
Type: "list(string)",
803+
Default: `["red", "yellow", "black"]`,
804+
Option: opts("red", "blue", "green"),
805+
FormType: provider.ParameterFormTypeMultiSelect,
806+
},
807+
ExpectError: regexp.MustCompile("is not a valid option, values \"yellow, black\" are missing from the options"),
808+
},
809+
{
810+
Name: "ListStringNotInOptions",
811+
Parameter: provider.Parameter{
812+
Type: "list(string)",
813+
Default: `["red"]`,
814+
Option: opts("red", "blue", "green"),
815+
FormType: provider.ParameterFormTypeMultiSelect,
816+
},
817+
Value: `["red", "yellow", "black"]`,
818+
ExpectError: regexp.MustCompile("is not a valid option, values \"yellow, black\" are missing from the options"),
819+
},
820+
{
821+
Name: "InvalidMiniumum",
822+
Parameter: provider.Parameter{
823+
Type: "number",
824+
Default: "5",
825+
Validation: []provider.Validation{{
826+
Min: 10,
827+
Error: "must be greater than 10",
828+
}},
829+
},
830+
ExpectError: regexp.MustCompile("must be greater than 10"),
831+
},
774832
} {
775833
tc := tc
776834
t.Run(tc.Name, func(t *testing.T) {

0 commit comments

Comments
 (0)