@@ -30,6 +30,7 @@ import (
30
30
apierrors "k8s.io/apimachinery/pkg/api/errors"
31
31
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
32
32
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
33
+ "k8s.io/apimachinery/pkg/runtime"
33
34
"k8s.io/apimachinery/pkg/types"
34
35
"k8s.io/apimachinery/pkg/util/sets"
35
36
"k8s.io/apimachinery/pkg/util/wait"
@@ -1202,7 +1203,7 @@ func Test_objectMover_move_dryRun(t *testing.T) {
1202
1203
dryRun : true ,
1203
1204
}
1204
1205
1205
- err := mover .move (ctx , graph , toProxy , nil )
1206
+ err := mover .move (ctx , graph , toProxy )
1206
1207
if tt .wantErr {
1207
1208
g .Expect (err ).To (HaveOccurred ())
1208
1209
return
@@ -1876,7 +1877,6 @@ func Test_objectMoverService_ensureNamespaces(t *testing.T) {
1876
1877
expectedNamespaces : []string {"namespace-1" , "namespace-2" },
1877
1878
},
1878
1879
{
1879
-
1880
1880
name : "ensureNamespaces moves namespace-2 to target which already has namespace-1" ,
1881
1881
fields : fields {
1882
1882
objs : cluster2 .Objs (),
@@ -2408,3 +2408,48 @@ func TestWaitReadyForMove(t *testing.T) {
2408
2408
})
2409
2409
}
2410
2410
}
2411
+
2412
+ func Test_applyMutators (t * testing.T ) {
2413
+ tests := []struct {
2414
+ name string
2415
+ object client.Object
2416
+ mutators []ResourceMutatorFunc
2417
+ want * unstructured.Unstructured
2418
+ wantErr bool
2419
+ }{
2420
+ {
2421
+ name : "do nothing if object is nil" ,
2422
+ },
2423
+ {
2424
+ name : "do nothing if mutators is a nil slice" ,
2425
+ object : test .NewFakeCluster ("example" , "example" ).Objs ()[0 ],
2426
+ want : func () * unstructured.Unstructured {
2427
+ g := NewWithT (t )
2428
+ obj := test .NewFakeCluster ("example" , "example" ).Objs ()[0 ]
2429
+ u := & unstructured.Unstructured {}
2430
+ to , err := runtime .DefaultUnstructuredConverter .ToUnstructured (obj )
2431
+ g .Expect (err ).NotTo (HaveOccurred ())
2432
+ u .SetUnstructuredContent (to )
2433
+ return u
2434
+ }(),
2435
+ },
2436
+ {
2437
+ name : "return error if any element in mutators slice is nil" ,
2438
+ mutators : []ResourceMutatorFunc {nil },
2439
+ object : test .NewFakeCluster ("example" , "example" ).Objs ()[0 ],
2440
+ wantErr : true ,
2441
+ },
2442
+ }
2443
+ for _ , tt := range tests {
2444
+ t .Run (tt .name , func (t * testing.T ) {
2445
+ g := NewWithT (t )
2446
+ got , err := applyMutators (tt .object , tt .mutators ... )
2447
+ g .Expect (got ).To (Equal (tt .want ))
2448
+ if tt .wantErr {
2449
+ g .Expect (err ).To (HaveOccurred ())
2450
+ } else {
2451
+ g .Expect (err ).NotTo (HaveOccurred ())
2452
+ }
2453
+ })
2454
+ }
2455
+ }
0 commit comments