@@ -89,6 +89,154 @@ func TestTypeMinVersionObj(t *testing.T) {
8989 }
9090}
9191
92+ func TestTypeFieldType (t * testing.T ) {
93+ t .Parallel ()
94+
95+ cases := []struct {
96+ description string
97+ obj Type
98+ expected []string
99+ }{
100+ {
101+ description : "Required field" ,
102+ obj : Type {
103+ Required : true ,
104+ },
105+ expected : []string {"Required" },
106+ },
107+ {
108+ description : "Optional field" ,
109+ obj : Type {
110+ Required : false ,
111+ Output : false ,
112+ },
113+ expected : []string {"Optional" },
114+ },
115+ {
116+ description : "Output field with parent" ,
117+ obj : Type {
118+ Required : false ,
119+ Output : true ,
120+ ParentMetadata : & Type {},
121+ },
122+ expected : []string {"Output" },
123+ },
124+ {
125+ description : "Output field without parent" ,
126+ obj : Type {
127+ Required : false ,
128+ Output : true ,
129+ ParentMetadata : nil ,
130+ },
131+ expected : []string {},
132+ },
133+ {
134+ description : "WriteOnlyLegacy field" ,
135+ obj : Type {
136+ WriteOnlyLegacy : true ,
137+ },
138+ expected : []string {"Optional" , "Write-Only" },
139+ },
140+ {
141+ description : "WriteOnly field" ,
142+ obj : Type {
143+ WriteOnly : true ,
144+ },
145+ expected : []string {"Optional" , "Write-Only" },
146+ },
147+ {
148+ description : "Beta field in GA resource" ,
149+ obj : Type {
150+ MinVersion : "beta" ,
151+ ResourceMetadata : & Resource {
152+ MinVersion : "ga" ,
153+ },
154+ },
155+ expected : []string {"Optional" , "[Beta](https://terraform.io/docs/providers/google/guides/provider_versions.html)" },
156+ },
157+ {
158+ description : "Beta field in Beta resource" ,
159+ obj : Type {
160+ MinVersion : "beta" ,
161+ ResourceMetadata : & Resource {
162+ MinVersion : "beta" ,
163+ },
164+ },
165+ expected : []string {"Optional" },
166+ },
167+ {
168+ description : "GA field in GA resource" ,
169+ obj : Type {
170+ MinVersion : "ga" ,
171+ ResourceMetadata : & Resource {
172+ MinVersion : "ga" ,
173+ },
174+ },
175+ expected : []string {"Optional" },
176+ },
177+ {
178+ description : "Deprecated field" ,
179+ obj : Type {
180+ DeprecationMessage : "This field is deprecated." ,
181+ },
182+ expected : []string {"Optional" , "Deprecated" },
183+ },
184+ {
185+ description : "All fields set for a required property" ,
186+ obj : Type {
187+ Required : true ,
188+ WriteOnly : true ,
189+ MinVersion : "beta" ,
190+ ResourceMetadata : & Resource {MinVersion : "ga" },
191+ DeprecationMessage : "This field is deprecated." ,
192+ },
193+ expected : []string {"Required" , "Write-Only" , "[Beta](https://terraform.io/docs/providers/google/guides/provider_versions.html)" , "Deprecated" },
194+ },
195+ {
196+ description : "All fields set for an optional property" ,
197+ obj : Type {
198+ WriteOnly : true ,
199+ MinVersion : "beta" ,
200+ ResourceMetadata : & Resource {MinVersion : "ga" },
201+ DeprecationMessage : "This field is deprecated." ,
202+ },
203+ expected : []string {"Optional" , "Write-Only" , "[Beta](https://terraform.io/docs/providers/google/guides/provider_versions.html)" , "Deprecated" },
204+ },
205+ {
206+ description : "Output and deprecated" ,
207+ obj : Type {
208+ Output : true ,
209+ ParentMetadata : & Type {},
210+ DeprecationMessage : "This field is deprecated." ,
211+ },
212+ expected : []string {"Output" , "Deprecated" },
213+ },
214+ {
215+ description : "Required and deprecated" ,
216+ obj : Type {
217+ Required : true ,
218+ ParentMetadata : & Type {},
219+ DeprecationMessage : "This field is deprecated." ,
220+ },
221+ expected : []string {"Required" , "Deprecated" },
222+ },
223+ }
224+
225+ for _ , tc := range cases {
226+ tc := tc
227+
228+ t .Run (tc .description , func (t * testing.T ) {
229+ t .Parallel ()
230+
231+ fieldType := tc .obj .FieldType ()
232+
233+ if got , want := fieldType , tc .expected ; ! reflect .DeepEqual (got , want ) {
234+ t .Errorf ("expected %v to be %v" , got , want )
235+ }
236+ })
237+ }
238+ }
239+
92240func TestTypeExcludeIfNotInVersion (t * testing.T ) {
93241 t .Parallel ()
94242
0 commit comments