@@ -158,3 +158,241 @@ func Test_customPreCompare(t *testing.T) {
158158 }
159159 })
160160}
161+
162+ func Test_newResourceDelta_customDeltaFunction_AttributeDefinitions (t * testing.T ) {
163+ type args struct {
164+ a * resource
165+ b * resource
166+ }
167+ tests := []struct {
168+ name string
169+ args args
170+ want bool
171+ }{
172+ {
173+ name : "both desired and latest are nil" ,
174+ args : args {
175+ a : & resource {
176+ ko : & v1alpha1.Table {
177+ Spec : v1alpha1.TableSpec {
178+ AttributeDefinitions : nil ,
179+ },
180+ },
181+ },
182+ b : & resource {
183+ ko : & v1alpha1.Table {
184+ Spec : v1alpha1.TableSpec {
185+ AttributeDefinitions : nil ,
186+ },
187+ },
188+ },
189+ },
190+ want : true ,
191+ },
192+ {
193+ name : "desired is not nil" ,
194+ args : args {
195+ a : & resource {
196+ ko : & v1alpha1.Table {
197+ Spec : v1alpha1.TableSpec {
198+ AttributeDefinitions : []* v1alpha1.AttributeDefinition {
199+ {
200+ AttributeName : aws .String ("externalId" ),
201+ AttributeType : aws .String ("S" ),
202+ },
203+ },
204+ },
205+ },
206+ },
207+ b : & resource {
208+ ko : & v1alpha1.Table {
209+ Spec : v1alpha1.TableSpec {
210+ AttributeDefinitions : nil ,
211+ },
212+ },
213+ },
214+ },
215+ want : false ,
216+ },
217+ {
218+ name : "latest is not nil" ,
219+ args : args {
220+ a : & resource {
221+ ko : & v1alpha1.Table {
222+ Spec : v1alpha1.TableSpec {
223+ AttributeDefinitions : nil ,
224+ },
225+ },
226+ },
227+ b : & resource {
228+ ko : & v1alpha1.Table {
229+ Spec : v1alpha1.TableSpec {
230+ AttributeDefinitions : []* v1alpha1.AttributeDefinition {
231+ {
232+ AttributeName : aws .String ("externalId" ),
233+ AttributeType : aws .String ("S" ),
234+ },
235+ },
236+ },
237+ },
238+ },
239+ },
240+ want : false ,
241+ },
242+ {
243+ name : "desired and latest are equal" ,
244+ args : args {
245+ a : & resource {
246+ ko : & v1alpha1.Table {
247+ Spec : v1alpha1.TableSpec {
248+ AttributeDefinitions : []* v1alpha1.AttributeDefinition {
249+ {
250+ AttributeName : aws .String ("externalId" ),
251+ AttributeType : aws .String ("S" ),
252+ },
253+ {
254+ AttributeName : aws .String ("id" ),
255+ AttributeType : aws .String ("S" ),
256+ },
257+ },
258+ },
259+ },
260+ },
261+ b : & resource {
262+ ko : & v1alpha1.Table {
263+ Spec : v1alpha1.TableSpec {
264+ AttributeDefinitions : []* v1alpha1.AttributeDefinition {
265+ {
266+ AttributeName : aws .String ("id" ),
267+ AttributeType : aws .String ("S" ),
268+ },
269+ {
270+ AttributeName : aws .String ("externalId" ),
271+ AttributeType : aws .String ("S" ),
272+ },
273+ },
274+ },
275+ },
276+ },
277+ },
278+ want : true ,
279+ },
280+ {
281+ name : "desired is updated" ,
282+ args : args {
283+ a : & resource {
284+ ko : & v1alpha1.Table {
285+ Spec : v1alpha1.TableSpec {
286+ AttributeDefinitions : []* v1alpha1.AttributeDefinition {
287+ {
288+ AttributeName : aws .String ("externalId" ),
289+ AttributeType : aws .String ("N" ),
290+ },
291+ {
292+ AttributeName : aws .String ("id" ),
293+ AttributeType : aws .String ("S" ),
294+ },
295+ },
296+ },
297+ },
298+ },
299+ b : & resource {
300+ ko : & v1alpha1.Table {
301+ Spec : v1alpha1.TableSpec {
302+ AttributeDefinitions : []* v1alpha1.AttributeDefinition {
303+ {
304+ AttributeName : aws .String ("id" ),
305+ AttributeType : aws .String ("S" ),
306+ },
307+ {
308+ AttributeName : aws .String ("externalId" ),
309+ AttributeType : aws .String ("S" ),
310+ },
311+ },
312+ },
313+ },
314+ },
315+ },
316+ want : false ,
317+ },
318+ {
319+ name : "removed in desired" ,
320+ args : args {
321+ a : & resource {
322+ ko : & v1alpha1.Table {
323+ Spec : v1alpha1.TableSpec {
324+ AttributeDefinitions : []* v1alpha1.AttributeDefinition {
325+ {
326+ AttributeName : aws .String ("id" ),
327+ AttributeType : aws .String ("S" ),
328+ },
329+ },
330+ },
331+ },
332+ },
333+ b : & resource {
334+ ko : & v1alpha1.Table {
335+ Spec : v1alpha1.TableSpec {
336+ AttributeDefinitions : []* v1alpha1.AttributeDefinition {
337+ {
338+ AttributeName : aws .String ("id" ),
339+ AttributeType : aws .String ("S" ),
340+ },
341+ {
342+ AttributeName : aws .String ("externalId" ),
343+ AttributeType : aws .String ("S" ),
344+ },
345+ },
346+ },
347+ },
348+ },
349+ },
350+ want : false ,
351+ },
352+ {
353+ name : "added in desired" ,
354+ args : args {
355+ a : & resource {
356+ ko : & v1alpha1.Table {
357+ Spec : v1alpha1.TableSpec {
358+ AttributeDefinitions : []* v1alpha1.AttributeDefinition {
359+ {
360+ AttributeName : aws .String ("id" ),
361+ AttributeType : aws .String ("S" ),
362+ },
363+ {
364+ AttributeName : aws .String ("externalId" ),
365+ AttributeType : aws .String ("S" ),
366+ },
367+ },
368+ },
369+ },
370+ },
371+ b : & resource {
372+ ko : & v1alpha1.Table {
373+ Spec : v1alpha1.TableSpec {
374+ AttributeDefinitions : []* v1alpha1.AttributeDefinition {
375+ {
376+ AttributeName : aws .String ("id" ),
377+ AttributeType : aws .String ("S" ),
378+ },
379+ },
380+ },
381+ },
382+ },
383+ },
384+ want : false ,
385+ },
386+ }
387+
388+ isEqual := func (delta * compare.Delta ) bool {
389+ return len (delta .Differences ) == 0
390+ }
391+ for _ , tt := range tests {
392+ t .Run (tt .name , func (t * testing.T ) {
393+ if delta := newResourceDelta (tt .args .a , tt .args .b ); isEqual (delta ) != tt .want {
394+ t .Errorf ("Compare attribution defintions should be %v" , tt .want )
395+ }
396+ })
397+ }
398+ }
0 commit comments