@@ -10,41 +10,47 @@ import (
10
10
)
11
11
12
12
func TestProviderSchemasValidate (t * testing.T ) {
13
- f , err := os .Open ("testdata/basic/schemas.json" )
14
- if err != nil {
15
- t .Fatal (err )
13
+ cases := map [string ]struct {
14
+ testDataPath string
15
+ }{
16
+ "a basic provider schema is validated" : {
17
+ testDataPath : "testdata/basic/schemas.json" ,
18
+ },
19
+ "a provider schema including functions is validated" : {
20
+ testDataPath : "testdata/functions/schemas.json" ,
21
+ },
22
+ "a provider schema including ephemeral resources is validated" : {
23
+ testDataPath : "testdata/ephemeral_resources/schemas.json" ,
24
+ },
25
+ "a provider schema including a resource with write-only attribute(s) is validated" : {
26
+ testDataPath : "testdata/write_only_attribute_on_resource/schemas.json" ,
27
+ },
16
28
}
17
- defer f .Close ()
18
29
19
- var schemas * ProviderSchemas
20
- if err := json .NewDecoder (f ).Decode (& schemas ); err != nil {
21
- t .Fatal (err )
22
- }
23
-
24
- if err := schemas .Validate (); err != nil {
25
- t .Fatal (err )
26
- }
27
- }
30
+ for tn , tc := range cases {
31
+ t .Run (tn , func (t * testing.T ) {
32
+ f , err := os .Open (tc .testDataPath )
33
+ if err != nil {
34
+ t .Fatal (err )
35
+ }
36
+ defer f .Close ()
28
37
29
- func TestProviderSchemasValidate_functions (t * testing.T ) {
30
- f , err := os .Open ("testdata/functions/schemas.json" )
31
- if err != nil {
32
- t .Fatal (err )
33
- }
34
- defer f .Close ()
38
+ var schemas * ProviderSchemas
39
+ if err := json .NewDecoder (f ).Decode (& schemas ); err != nil {
40
+ t .Fatal (err )
41
+ }
35
42
36
- var schemas * ProviderSchemas
37
- if err := json .NewDecoder (f ).Decode (& schemas ); err != nil {
38
- t .Fatal (err )
39
- }
40
-
41
- if err := schemas .Validate (); err != nil {
42
- t .Fatal (err )
43
+ if err := schemas .Validate (); err != nil {
44
+ t .Fatal (err )
45
+ }
46
+ })
43
47
}
44
48
}
45
49
46
- func TestProviderSchemasValidate_ephemeralResources (t * testing.T ) {
47
- f , err := os .Open ("testdata/ephemeral_resources/schemas.json" )
50
+ // TestProviderSchemas_writeOnlyAttribute asserts that write-only attributes in a resource in a
51
+ // provider schema JSON file are marked as WriteOnly once decoded into a ProviderSchemas struct
52
+ func TestProviderSchemas_writeOnlyAttribute (t * testing.T ) {
53
+ f , err := os .Open ("testdata/write_only_attribute_on_resource/schemas.json" )
48
54
if err != nil {
49
55
t .Fatal (err )
50
56
}
@@ -55,24 +61,11 @@ func TestProviderSchemasValidate_ephemeralResources(t *testing.T) {
55
61
t .Fatal (err )
56
62
}
57
63
58
- if err := schemas .Validate (); err != nil {
59
- t .Fatal (err )
60
- }
61
- }
62
-
63
- func TestProviderSchemasValidate_nestedAttributes (t * testing.T ) {
64
- f , err := os .Open ("testdata/nested_attributes/schemas.json" )
65
- if err != nil {
66
- t .Fatal (err )
64
+ resourceSchema := schemas .Schemas ["terraform.io/builtin/terraform" ].ResourceSchemas ["terraform_example" ]
65
+ if resourceSchema .Block .Attributes ["wo_attr" ].WriteOnly != true {
66
+ t .Fatal ("expected terraform_example.wo_attr to be marked as write-only" )
67
67
}
68
- defer f .Close ()
69
-
70
- var schemas * ProviderSchemas
71
- if err := json .NewDecoder (f ).Decode (& schemas ); err != nil {
72
- t .Fatal (err )
73
- }
74
-
75
- if err := schemas .Validate (); err != nil {
76
- t .Fatal (err )
68
+ if resourceSchema .Block .Attributes ["foo" ].WriteOnly != false {
69
+ t .Fatal ("expected terraform_example.foo to not be marked as write-only" )
77
70
}
78
71
}
0 commit comments