Skip to content

Commit cec2d97

Browse files
committed
extract tests to a file
1 parent 2d51bff commit cec2d97

File tree

2 files changed

+80
-51
lines changed

2 files changed

+80
-51
lines changed

provider/parameter_test.go

Lines changed: 10 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package provider_test
22

33
import (
44
"fmt"
5+
"os"
56
"regexp"
67
"strconv"
78
"strings"
@@ -703,55 +704,8 @@ func TestParameterValidationEnforcement(t *testing.T) {
703704
// - [NumIns/DefInv] So the default can be invalid if an input value is valid.
704705
// The value is therefore not really optional, but it is marked as such.
705706
// - [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)
755709

756710
type row struct {
757711
Name string
@@ -766,7 +720,7 @@ func TestParameterValidationEnforcement(t *testing.T) {
766720
}
767721

768722
rows := make([]row, 0)
769-
lines := strings.Split(table, "\n")
723+
lines := strings.Split(string(table), "\n")
770724
validMinMax := regexp.MustCompile("^[0-9]*-[0-9]*$")
771725
for _, line := range lines[2:] {
772726
columns := strings.Split(line, "|")
@@ -867,7 +821,12 @@ func TestParameterValidationEnforcement(t *testing.T) {
867821
var cfg strings.Builder
868822
cfg.WriteString("data \"coder_parameter\" \"parameter\" {\n")
869823
cfg.WriteString("\tname = \"parameter\"\n")
870-
cfg.WriteString(fmt.Sprintf("\ttype = \"%s\"\n", rt))
824+
if rt == "multi-select" || rt == "tag-select" {
825+
cfg.WriteString(fmt.Sprintf("\ttype = \"%s\"\n", "list(string)"))
826+
cfg.WriteString(fmt.Sprintf("\tform_type = \"%s\"\n", rt))
827+
} else {
828+
cfg.WriteString(fmt.Sprintf("\ttype = \"%s\"\n", rt))
829+
}
871830
if row.Default != "" {
872831
cfg.WriteString(fmt.Sprintf("\tdefault = %s\n", stringLiteral(row.Default)))
873832
}

provider/testdata/parameter_table.md

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
| Name | Type | Input | Default | Options | Validation | -> | Output | Optional | Error |
2+
|----------------------|---------------|-----------|---------|-------------------|------------|----|--------|----------|--------------|
3+
| | Empty Vals | | | | | | | | |
4+
| Empty | string,number | | | | | | "" | false | |
5+
| EmptyList | list(string) | | | | | | "" | false | |
6+
| EmptyMulti | tag-select | | | | | | "" | false | |
7+
| EmptyOpts | string,number | | | 1,2,3 | | | "" | false | |
8+
| EmptyRegex | string | | | | world | | | | regex error |
9+
| EmptyMin | number | | | | 1-10 | | | | 1 < < 10 |
10+
| EmptyMinOpt | number | | | 1,2,3 | 2-5 | | | | 2 < < 5 |
11+
| EmptyRegexOpt | string | | | "hello","goodbye" | goodbye | | | | regex error |
12+
| EmptyRegexOk | string | | | | .* | | "" | false | |
13+
| | | | | | | | | | |
14+
| | Default Set | No inputs | | | | | | | |
15+
| NumDef | number | | 5 | | | | 5 | true | |
16+
| NumDefVal | number | | 5 | | 3-7 | | 5 | true | |
17+
| NumDefInv | number | | 5 | | 10- | | | | 10 < 5 < 0 |
18+
| NumDefOpts | number | | 5 | 1,3,5,7 | 2-6 | | 5 | true | |
19+
| NumDefNotOpts | number | | 5 | 1,3,7,9 | 2-6 | | | | valid option |
20+
| NumDefInvOpt | number | | 5 | 1,3,5,7 | 6-10 | | | | 6 < 5 < 10 |
21+
| | | | | | | | | | |
22+
| StrDef | string | | hello | | | | hello | true | |
23+
| StrDefInv | string | | hello | | world | | | | regex error |
24+
| StrDefOpts | string | | a | a,b,c | | | a | true | |
25+
| StrDefNotOpts | string | | a | b,c,d | | | | | valid option |
26+
| StrDefValOpts | string | | a | a,b,c,d,e,f | [a-c] | | a | true | |
27+
| StrDefInvOpt | string | | d | a,b,c,d,e,f | [a-c] | | | | regex error |
28+
| | | | | | | | | | |
29+
| LStrDef | list(string) | | ["a"] | | | | ["a"] | true | |
30+
| LStrDefOpts | list(string) | | ["a"] | ["a"], ["b"] | | | ["a"] | true | |
31+
| LStrDefNotOpts | list(string) | | ["a"] | ["b"], ["c"] | | | | | valid option |
32+
| | | | | | | | | | |
33+
| MulDef | tag-select | | ["a"] | | | | ["a"] | true | |
34+
| MulDefOpts | multi-select | | ["a"] | a,b | | | ["a"] | true | |
35+
| MulDefNotOpts | multi-select | | ["a"] | b,c | | | | | valid option |
36+
| | | | | | | | | | |
37+
| | Input Vals | | | | | | | | |
38+
| NumIns | number | 3 | | | | | 3 | false | |
39+
| NumInsDef | number | 3 | 5 | | | | 3 | true | |
40+
| NumIns/DefInv | number | 3 | 5 | | 1-3 | | 3 | true | |
41+
| NumIns=DefInv | number | 5 | 5 | | 1-3 | | | | 1 < 5 < 3 |
42+
| NumInsOpts | number | 3 | 5 | 1,2,3,4,5 | 1-3 | | 3 | true | |
43+
| NumInsNotOptsVal | number | 3 | 5 | 1,2,4,5 | 1-3 | | 3 | true | |
44+
| NumInsNotOptsInv | number | 3 | 5 | 1,2,4,5 | 1-2 | | | true | 1 < 3 < 2 |
45+
| NumInsNotOpts | number | 3 | 5 | 1,2,4,5 | | | 3 | true | |
46+
| NumInsNotOpts/NoDef | number | 3 | | 1,2,4,5 | | | 3 | false | |
47+
| | | | | | | | | | |
48+
| StrIns | string | c | | | | | c | false | |
49+
| StrInsDef | string | c | e | | | | c | true | |
50+
| StrIns/DefInv | string | c | e | | [a-c] | | c | true | |
51+
| StrIns=DefInv | string | e | e | | [a-c] | | | | regex error |
52+
| StrInsOpts | string | c | e | a,b,c,d,e | [a-c] | | c | true | |
53+
| StrInsNotOptsVal | string | c | e | a,b,d,e | [a-c] | | c | true | |
54+
| StrInsNotOptsInv | string | c | e | a,b,d,e | [a-b] | | | | regex error |
55+
| StrInsNotOpts | string | c | e | a,b,d,e | | | c | true | |
56+
| StrInsNotOpts/NoDef | string | c | | a,b,d,e | | | c | false | |
57+
| StrInsBadVal | string | c | | a,b,c,d,e | 1-10 | | | | min cannot |
58+
| | | | | | | | | | |
59+
| | list(string) | | | | | | | | |
60+
| LStrIns | list(string) | ["c"] | | | | | ["c"] | false | |
61+
| LStrInsDef | list(string) | ["c"] | ["e"] | | | | ["c"] | true | |
62+
| LStrIns/DefInv | list(string) | ["c"] | ["e"] | | [a-c] | | | | regex cannot |
63+
| LStrInsOpts | list(string) | ["c"] | ["e"] | ["c"],["d"],["e"] | | | ["c"] | true | |
64+
| LStrInsNotOpts | list(string) | ["c"] | ["e"] | ["d"],["e"] | | | ["c"] | true | |
65+
| LStrInsNotOpts/NoDef | list(string) | ["c"] | | ["d"],["e"] | | | ["c"] | false | |
66+
| | | | | | | | | | |
67+
| MulInsOpts | multi-select | ["c"] | ["e"] | c,d,e | | | ["c"] | true | |
68+
| MulInsNotOpts | multi-select | ["c"] | ["e"] | d,e | | | ["c"] | true | |
69+
| MulInsNotOpts/NoDef | multi-select | ["c"] | | d,e | | | ["c"] | false | |
70+
| MulInsInvOpts | multi-select | ["c"] | ["e"] | c,d,e | [a-c] | | | | regex cannot |

0 commit comments

Comments
 (0)