@@ -268,85 +268,85 @@ func TestCreateInventory(t *testing.T) {
268
268
269
269
func TestReplace (t * testing.T ) {
270
270
tests := map [string ]struct {
271
- localInv InventoryInfo
272
271
localObjs []object.ObjMetadata
273
272
clusterObjs []object.ObjMetadata
274
- isError bool
275
273
}{
276
- "Local inventory nil is error" : {
277
- localInv : nil ,
274
+ "Cluster and local inventories empty" : {
278
275
localObjs : []object.ObjMetadata {},
279
276
clusterObjs : []object.ObjMetadata {},
280
- isError : true ,
281
277
},
282
- "Cluster and local inventories empty: no error" : {
283
- localInv : copyInventory (),
284
- localObjs : []object.ObjMetadata {},
285
- clusterObjs : []object.ObjMetadata {},
286
- isError : false ,
287
- },
288
- "Cluster and local inventories same: no error" : {
289
- localInv : copyInventory (),
278
+ "Cluster and local inventories same" : {
290
279
localObjs : []object.ObjMetadata {
291
280
ignoreErrInfoToObjMeta (pod1Info ),
292
281
},
293
282
clusterObjs : []object.ObjMetadata {
294
283
ignoreErrInfoToObjMeta (pod1Info ),
295
284
},
296
- isError : false ,
297
285
},
298
- "Cluster two obj, local one: no error" : {
299
- localInv : copyInventory (),
286
+ "Cluster two obj, local one" : {
300
287
localObjs : []object.ObjMetadata {
301
288
ignoreErrInfoToObjMeta (pod1Info ),
302
289
},
303
290
clusterObjs : []object.ObjMetadata {
304
291
ignoreErrInfoToObjMeta (pod1Info ),
305
292
ignoreErrInfoToObjMeta (pod3Info ),
306
293
},
307
- isError : false ,
308
294
},
309
- "Cluster multiple objs, local multiple different objs: no error" : {
310
- localInv : copyInventory (),
295
+ "Cluster multiple objs, local multiple different objs" : {
311
296
localObjs : []object.ObjMetadata {
312
297
ignoreErrInfoToObjMeta (pod2Info ),
313
298
},
314
299
clusterObjs : []object.ObjMetadata {
315
300
ignoreErrInfoToObjMeta (pod1Info ),
316
301
ignoreErrInfoToObjMeta (pod2Info ),
317
302
ignoreErrInfoToObjMeta (pod3Info )},
318
- isError : false ,
319
303
},
320
304
}
321
305
322
306
tf := cmdtesting .NewTestFactory ().WithNamespace (testNamespace )
323
307
defer tf .Cleanup ()
324
308
309
+ // Client and server dry-run do not throw errors.
310
+ invClient , _ := NewInventoryClient (tf , WrapInventoryObj , InvInfoToConfigMap )
311
+ invClient .SetDryRunStrategy (common .DryRunClient )
312
+ err := invClient .Replace (copyInventory (), []object.ObjMetadata {})
313
+ if err != nil {
314
+ t .Fatalf ("unexpected error received: %s" , err )
315
+ }
316
+ invClient .SetDryRunStrategy (common .DryRunServer )
317
+ err = invClient .Replace (copyInventory (), []object.ObjMetadata {})
318
+ if err != nil {
319
+ t .Fatalf ("unexpected error received: %s" , err )
320
+ }
321
+
325
322
for name , tc := range tests {
326
- for i := range common .Strategies {
327
- drs := common .Strategies [i ]
328
- t .Run (name , func (t * testing.T ) {
329
- invClient , _ := NewInventoryClient (tf ,
330
- WrapInventoryObj , InvInfoToConfigMap )
331
- invClient .SetDryRunStrategy (drs )
332
- // Create fake builder returning the cluster inventory object
333
- // storing the "tc.clusterObjs" objects.
334
- fakeBuilder := FakeBuilder {}
335
- fakeBuilder .SetInventoryObjs (tc .clusterObjs )
336
- invClient .builderFunc = fakeBuilder .GetBuilder ()
337
- // Call "Replace", passing in the new local inventory objects
338
- err := invClient .Replace (tc .localInv , tc .localObjs )
339
- if tc .isError {
340
- if err == nil {
341
- t .Fatalf ("expected error but received none" )
342
- }
343
- return
344
- }
345
- if ! tc .isError && err != nil {
346
- t .Fatalf ("unexpected error received: %s" , err )
347
- }
348
- })
349
- }
323
+ t .Run (name , func (t * testing.T ) {
324
+ // Create inventory client, and store the cluster objs in the inventory object.
325
+ invClient , _ := NewInventoryClient (tf ,
326
+ WrapInventoryObj , InvInfoToConfigMap )
327
+ wrappedInv := invClient .InventoryFactoryFunc (inventoryObj )
328
+ if err := wrappedInv .Store (tc .clusterObjs ); err != nil {
329
+ t .Fatalf ("unexpected error storing inventory objects: %s" , err )
330
+ }
331
+ inv , err := wrappedInv .GetObject ()
332
+ if err != nil {
333
+ t .Fatalf ("unexpected error storing inventory objects: %s" , err )
334
+ }
335
+ // Call replaceInventory with the new set of "localObjs"
336
+ inv , err = invClient .replaceInventory (inv , tc .localObjs )
337
+ if err != nil {
338
+ t .Fatalf ("unexpected error received: %s" , err )
339
+ }
340
+ wrappedInv = invClient .InventoryFactoryFunc (inv )
341
+ // Validate that the stored objects are now the "localObjs".
342
+ actualObjs , err := wrappedInv .Load ()
343
+ if err != nil {
344
+ t .Fatalf ("unexpected error received: %s" , err )
345
+ }
346
+ if ! object .SetEquals (tc .localObjs , actualObjs ) {
347
+ t .Errorf ("expected objects (%s), got (%s)" , tc .localObjs , actualObjs )
348
+ }
349
+ })
350
350
}
351
351
}
352
352
0 commit comments