Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit f0bca91

Browse files
committedApr 7, 2025··
also assert styling
1 parent fec030d commit f0bca91

File tree

1 file changed

+28
-11
lines changed

1 file changed

+28
-11
lines changed
 

‎provider/formtype_test.go

+28-11
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
package provider_test
22

33
import (
4+
"encoding/json"
45
"fmt"
56
"regexp"
7+
"strconv"
68
"strings"
79
"testing"
810

@@ -26,16 +28,19 @@ type formTypeTestCase struct {
2628
type paramAssert struct {
2729
FormType provider.ParameterFormType
2830
Type provider.OptionType
29-
Styling string
31+
Styling json.RawMessage
3032
}
3133

3234
// formTypeCheck is a struct that helps build the terraform config
3335
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
3841
customOptions []string
42+
defValue string
43+
styling json.RawMessage
3944
}
4045

4146
func (c formTypeCheck) String() string {
@@ -55,6 +60,18 @@ func TestValidateFormType(t *testing.T) {
5560
if ftname == "" {
5661
ftname = "default"
5762
}
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+
5875
return formTypeTestCase{
5976
name: fmt.Sprintf("%s_%s_%t",
6077
ftname,
@@ -65,7 +82,7 @@ func TestValidateFormType(t *testing.T) {
6582
assert: paramAssert{
6683
FormType: expected,
6784
Type: opts.optionType,
68-
Styling: "",
85+
Styling: opts.styling,
6986
},
7087
expectError: nil,
7188
}
@@ -85,7 +102,7 @@ func TestValidateFormType(t *testing.T) {
85102
assert: paramAssert{
86103
FormType: provider.ParameterFormTypeInput,
87104
Type: provider.OptionTypeString,
88-
Styling: "",
105+
Styling: []byte("{}"),
89106
},
90107
},
91108
// All default behaviors. Essentially legacy behavior.
@@ -210,9 +227,6 @@ func TestValidateFormType(t *testing.T) {
210227
for _, c := range cases {
211228
t.Run(c.name, func(t *testing.T) {
212229
t.Parallel()
213-
if c.assert.Styling == "" {
214-
c.assert.Styling = "{}"
215-
}
216230

217231
formTypeTest(t, c)
218232
if _, ok := formTypesChecked[c.config.String()]; ok {
@@ -322,6 +336,9 @@ func ezconfig(paramName string, cfg formTypeCheck) (defaultValue string, tf stri
322336
if cfg.optionType != "" {
323337
body.WriteString(fmt.Sprintf("type = %q\n", cfg.optionType))
324338
}
339+
if cfg.styling != nil {
340+
body.WriteString(fmt.Sprintf("styling = %s\n", strconv.Quote(string(cfg.styling))))
341+
}
325342

326343
for i, opt := range options {
327344
body.WriteString("option {\n")
@@ -356,7 +373,7 @@ func formTypeTest(t *testing.T, c formTypeTestCase) {
356373
assert.Equal(t, def, param.Primary.Attributes["default"], "default value")
357374
assert.Equal(t, string(c.assert.FormType), param.Primary.Attributes["form_type"], "form_type")
358375
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")
360377

361378
return nil
362379
}

0 commit comments

Comments
 (0)
Please sign in to comment.