@@ -24,7 +24,7 @@ const (
24
24
provider = "ACoolProvider"
25
25
)
26
26
27
- func TestTagger_Initialize (t * testing.T ) {
27
+ func TestTaggerInitialize (t * testing.T ) {
28
28
errBoom := errors .New ("boom" )
29
29
30
30
type args struct {
@@ -112,3 +112,187 @@ func TestSetExternalTagsWithPaved(t *testing.T) {
112
112
})
113
113
}
114
114
}
115
+
116
+ func TestAddSingletonListConversion (t * testing.T ) {
117
+ type args struct {
118
+ r func () * Resource
119
+ tfPath string
120
+ crdPath string
121
+ }
122
+ type want struct {
123
+ r func () * Resource
124
+ }
125
+ cases := map [string ]struct {
126
+ reason string
127
+ args
128
+ want
129
+ }{
130
+ "AddNonWildcardTFPath" : {
131
+ reason : "A non-wildcard TF path of a singleton list should successfully be configured to be converted into an embedded object." ,
132
+ args : args {
133
+ tfPath : "singleton_list" ,
134
+ crdPath : "singletonList" ,
135
+ r : func () * Resource {
136
+ r := DefaultResource ("test_resource" , nil , nil , nil )
137
+ r .AddSingletonListConversion ("singleton_list" , "singletonList" )
138
+ return r
139
+ },
140
+ },
141
+ want : want {
142
+ r : func () * Resource {
143
+ r := DefaultResource ("test_resource" , nil , nil , nil )
144
+ r .SchemaElementOptions = SchemaElementOptions {}
145
+ r .SchemaElementOptions ["singleton_list" ] = & SchemaElementOption {
146
+ EmbeddedObject : true ,
147
+ }
148
+ r .listConversionPaths ["singleton_list" ] = "singletonList"
149
+ return r
150
+ },
151
+ },
152
+ },
153
+ "AddWildcardTFPath" : {
154
+ reason : "A wildcard TF path of a singleton list should successfully be configured to be converted into an embedded object." ,
155
+ args : args {
156
+ tfPath : "parent[*].singleton_list" ,
157
+ crdPath : "parent[*].singletonList" ,
158
+ r : func () * Resource {
159
+ r := DefaultResource ("test_resource" , nil , nil , nil )
160
+ r .AddSingletonListConversion ("parent[*].singleton_list" , "parent[*].singletonList" )
161
+ return r
162
+ },
163
+ },
164
+ want : want {
165
+ r : func () * Resource {
166
+ r := DefaultResource ("test_resource" , nil , nil , nil )
167
+ r .SchemaElementOptions = SchemaElementOptions {}
168
+ r .SchemaElementOptions ["parent.singleton_list" ] = & SchemaElementOption {
169
+ EmbeddedObject : true ,
170
+ }
171
+ r .listConversionPaths ["parent[*].singleton_list" ] = "parent[*].singletonList"
172
+ return r
173
+ },
174
+ },
175
+ },
176
+ "AddIndexedTFPath" : {
177
+ reason : "An indexed TF path of a singleton list should successfully be configured to be converted into an embedded object." ,
178
+ args : args {
179
+ tfPath : "parent[0].singleton_list" ,
180
+ crdPath : "parent[0].singletonList" ,
181
+ r : func () * Resource {
182
+ r := DefaultResource ("test_resource" , nil , nil , nil )
183
+ r .AddSingletonListConversion ("parent[0].singleton_list" , "parent[0].singletonList" )
184
+ return r
185
+ },
186
+ },
187
+ want : want {
188
+ r : func () * Resource {
189
+ r := DefaultResource ("test_resource" , nil , nil , nil )
190
+ r .SchemaElementOptions = SchemaElementOptions {}
191
+ r .SchemaElementOptions ["parent.singleton_list" ] = & SchemaElementOption {
192
+ EmbeddedObject : true ,
193
+ }
194
+ r .listConversionPaths ["parent[0].singleton_list" ] = "parent[0].singletonList"
195
+ return r
196
+ },
197
+ },
198
+ },
199
+ }
200
+ for n , tc := range cases {
201
+ t .Run (n , func (t * testing.T ) {
202
+ r := tc .args .r ()
203
+ r .AddSingletonListConversion (tc .args .tfPath , tc .args .crdPath )
204
+ wantR := tc .want .r ()
205
+ if diff := cmp .Diff (wantR .listConversionPaths , r .listConversionPaths ); diff != "" {
206
+ t .Errorf ("%s\n AddSingletonListConversion(tfPath): -wantConversionPaths, +gotConversionPaths: \n %s" , tc .reason , diff )
207
+ }
208
+ if diff := cmp .Diff (wantR .SchemaElementOptions , r .SchemaElementOptions ); diff != "" {
209
+ t .Errorf ("%s\n AddSingletonListConversion(tfPath): -wantSchemaElementOptions, +gotSchemaElementOptions: \n %s" , tc .reason , diff )
210
+ }
211
+ })
212
+ }
213
+ }
214
+
215
+ func TestRemoveSingletonListConversion (t * testing.T ) {
216
+ type args struct {
217
+ r func () * Resource
218
+ tfPath string
219
+ }
220
+ type want struct {
221
+ removed bool
222
+ r func () * Resource
223
+ }
224
+ cases := map [string ]struct {
225
+ reason string
226
+ args
227
+ want
228
+ }{
229
+ "RemoveWildcardListConversion" : {
230
+ reason : "An existing wildcard list conversion can successfully be removed." ,
231
+ args : args {
232
+ tfPath : "parent[*].singleton_list" ,
233
+ r : func () * Resource {
234
+ r := DefaultResource ("test_resource" , nil , nil , nil )
235
+ r .AddSingletonListConversion ("parent[*].singleton_list" , "parent[*].singletonList" )
236
+ return r
237
+ },
238
+ },
239
+ want : want {
240
+ removed : true ,
241
+ r : func () * Resource {
242
+ r := DefaultResource ("test_resource" , nil , nil , nil )
243
+ return r
244
+ },
245
+ },
246
+ },
247
+ "RemoveIndexedListConversion" : {
248
+ reason : "An existing indexed list conversion can successfully be removed." ,
249
+ args : args {
250
+ tfPath : "parent[0].singleton_list" ,
251
+ r : func () * Resource {
252
+ r := DefaultResource ("test_resource" , nil , nil , nil )
253
+ r .AddSingletonListConversion ("parent[0].singleton_list" , "parent[0].singletonList" )
254
+ return r
255
+ },
256
+ },
257
+ want : want {
258
+ removed : true ,
259
+ r : func () * Resource {
260
+ r := DefaultResource ("test_resource" , nil , nil , nil )
261
+ return r
262
+ },
263
+ },
264
+ },
265
+ "NonExistingListConversion" : {
266
+ reason : "A list conversion path that does not exist cannot be removed." ,
267
+ args : args {
268
+ tfPath : "non-existent" ,
269
+ r : func () * Resource {
270
+ r := DefaultResource ("test_resource" , nil , nil , nil )
271
+ r .AddSingletonListConversion ("parent[*].singleton_list" , "parent[*].singletonList" )
272
+ return r
273
+ },
274
+ },
275
+ want : want {
276
+ removed : false ,
277
+ r : func () * Resource {
278
+ r := DefaultResource ("test_resource" , nil , nil , nil )
279
+ r .AddSingletonListConversion ("parent[*].singleton_list" , "parent[*].singletonList" )
280
+ return r
281
+ },
282
+ },
283
+ },
284
+ }
285
+ for n , tc := range cases {
286
+ t .Run (n , func (t * testing.T ) {
287
+ r := tc .args .r ()
288
+ got := r .RemoveSingletonListConversion (tc .args .tfPath )
289
+ if diff := cmp .Diff (tc .want .removed , got ); diff != "" {
290
+ t .Errorf ("%s\n RemoveSingletonListConversion(tfPath): -wantRemoved, +gotRemoved: \n %s" , tc .reason , diff )
291
+ }
292
+
293
+ if diff := cmp .Diff (tc .want .r ().listConversionPaths , r .listConversionPaths ); diff != "" {
294
+ t .Errorf ("%s\n RemoveSingletonListConversion(tfPath): -wantConversionPaths, +gotConversionPaths: \n %s" , tc .reason , diff )
295
+ }
296
+ })
297
+ }
298
+ }
0 commit comments