1
1
package provider_test
2
2
3
3
import (
4
+ "encoding/json"
4
5
"fmt"
5
6
"regexp"
7
+ "strconv"
6
8
"strings"
7
9
"testing"
8
10
@@ -26,16 +28,19 @@ type formTypeTestCase struct {
26
28
type paramAssert struct {
27
29
FormType provider.ParameterFormType
28
30
Type provider.OptionType
29
- Styling string
31
+ Styling json. RawMessage
30
32
}
31
33
32
34
// formTypeCheck is a struct that helps build the terraform config
33
35
type formTypeCheck struct {
34
- formType provider.ParameterFormType
35
- optionType provider.OptionType
36
- options bool
37
- defValue string
36
+ formType provider.ParameterFormType
37
+ optionType provider.OptionType
38
+ options bool
39
+
40
+ // optional to inform the assert
38
41
customOptions []string
42
+ defValue string
43
+ styling json.RawMessage
39
44
}
40
45
41
46
func (c formTypeCheck ) String () string {
@@ -55,6 +60,18 @@ func TestValidateFormType(t *testing.T) {
55
60
if ftname == "" {
56
61
ftname = "default"
57
62
}
63
+
64
+ if opts .styling == nil {
65
+ // Try passing arbitrary data in, as anything should be accepted
66
+ opts .styling , _ = json .Marshal (map [string ]any {
67
+ "foo" : "bar" ,
68
+ "disabled" : true ,
69
+ "nested" : map [string ]any {
70
+ "foo" : "bar" ,
71
+ },
72
+ })
73
+ }
74
+
58
75
return formTypeTestCase {
59
76
name : fmt .Sprintf ("%s_%s_%t" ,
60
77
ftname ,
@@ -65,7 +82,7 @@ func TestValidateFormType(t *testing.T) {
65
82
assert : paramAssert {
66
83
FormType : expected ,
67
84
Type : opts .optionType ,
68
- Styling : "" ,
85
+ Styling : opts . styling ,
69
86
},
70
87
expectError : nil ,
71
88
}
@@ -85,7 +102,7 @@ func TestValidateFormType(t *testing.T) {
85
102
assert : paramAssert {
86
103
FormType : provider .ParameterFormTypeInput ,
87
104
Type : provider .OptionTypeString ,
88
- Styling : "" ,
105
+ Styling : [] byte ( "{}" ) ,
89
106
},
90
107
},
91
108
// All default behaviors. Essentially legacy behavior.
@@ -210,9 +227,6 @@ func TestValidateFormType(t *testing.T) {
210
227
for _ , c := range cases {
211
228
t .Run (c .name , func (t * testing.T ) {
212
229
t .Parallel ()
213
- if c .assert .Styling == "" {
214
- c .assert .Styling = "{}"
215
- }
216
230
217
231
formTypeTest (t , c )
218
232
if _ , ok := formTypesChecked [c .config .String ()]; ok {
@@ -322,6 +336,9 @@ func ezconfig(paramName string, cfg formTypeCheck) (defaultValue string, tf stri
322
336
if cfg .optionType != "" {
323
337
body .WriteString (fmt .Sprintf ("type = %q\n " , cfg .optionType ))
324
338
}
339
+ if cfg .styling != nil {
340
+ body .WriteString (fmt .Sprintf ("styling = %s\n " , strconv .Quote (string (cfg .styling ))))
341
+ }
325
342
326
343
for i , opt := range options {
327
344
body .WriteString ("option {\n " )
@@ -356,7 +373,7 @@ func formTypeTest(t *testing.T, c formTypeTestCase) {
356
373
assert .Equal (t , def , param .Primary .Attributes ["default" ], "default value" )
357
374
assert .Equal (t , string (c .assert .FormType ), param .Primary .Attributes ["form_type" ], "form_type" )
358
375
assert .Equal (t , string (c .assert .Type ), param .Primary .Attributes ["type" ], "type" )
359
- assert .JSONEq (t , c .assert .Styling , param .Primary .Attributes ["styling" ], "styling" )
376
+ assert .JSONEq (t , string ( c .assert .Styling ) , param .Primary .Attributes ["styling" ], "styling" )
360
377
361
378
return nil
362
379
}
0 commit comments