@@ -2,6 +2,7 @@ package provider_test
2
2
3
3
import (
4
4
"fmt"
5
+ "os"
5
6
"regexp"
6
7
"strconv"
7
8
"strings"
@@ -703,55 +704,8 @@ func TestParameterValidationEnforcement(t *testing.T) {
703
704
// - [NumIns/DefInv] So the default can be invalid if an input value is valid.
704
705
// The value is therefore not really optional, but it is marked as such.
705
706
// - [NumInsNotOptsVal | NumsInsNotOpts] values do not need to be in the option set?
706
-
707
- table := strings .TrimSpace (`
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 | |
754
- ` )
707
+ table , err := os .ReadFile ("testdata/parameter_table.md" )
708
+ require .NoError (t , err )
755
709
756
710
type row struct {
757
711
Name string
@@ -766,7 +720,7 @@ func TestParameterValidationEnforcement(t *testing.T) {
766
720
}
767
721
768
722
rows := make ([]row , 0 )
769
- lines := strings .Split (table , "\n " )
723
+ lines := strings .Split (string ( table ) , "\n " )
770
724
validMinMax := regexp .MustCompile ("^[0-9]*-[0-9]*$" )
771
725
for _ , line := range lines [2 :] {
772
726
columns := strings .Split (line , "|" )
@@ -867,7 +821,12 @@ func TestParameterValidationEnforcement(t *testing.T) {
867
821
var cfg strings.Builder
868
822
cfg .WriteString ("data \" coder_parameter\" \" parameter\" {\n " )
869
823
cfg .WriteString ("\t name = \" parameter\" \n " )
870
- cfg .WriteString (fmt .Sprintf ("\t type = \" %s\" \n " , rt ))
824
+ if rt == "multi-select" || rt == "tag-select" {
825
+ cfg .WriteString (fmt .Sprintf ("\t type = \" %s\" \n " , "list(string)" ))
826
+ cfg .WriteString (fmt .Sprintf ("\t form_type = \" %s\" \n " , rt ))
827
+ } else {
828
+ cfg .WriteString (fmt .Sprintf ("\t type = \" %s\" \n " , rt ))
829
+ }
871
830
if row .Default != "" {
872
831
cfg .WriteString (fmt .Sprintf ("\t default = %s\n " , stringLiteral (row .Default )))
873
832
}
0 commit comments