Skip to content

Commit 3eefea4

Browse files
committed
Test createTargetObject for object whose namespace is mutated
1 parent eba0375 commit 3eefea4

File tree

1 file changed

+48
-2
lines changed

1 file changed

+48
-2
lines changed

cmd/clusterctl/client/cluster/mover_test.go

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1876,7 +1876,6 @@ func Test_objectMoverService_ensureNamespaces(t *testing.T) {
18761876
expectedNamespaces: []string{"namespace-1", "namespace-2"},
18771877
},
18781878
{
1879-
18801879
name: "ensureNamespaces moves namespace-2 to target which already has namespace-1",
18811880
fields: fields{
18821881
objs: cluster2.Objs(),
@@ -1956,6 +1955,7 @@ func Test_createTargetObject(t *testing.T) {
19561955
fromProxy Proxy
19571956
toProxy Proxy
19581957
node *node
1958+
mutators []ResourceMutatorFunc
19591959
}
19601960

19611961
tests := []struct {
@@ -2075,6 +2075,52 @@ func Test_createTargetObject(t *testing.T) {
20752075
g.Expect(c.Annotations).To(BeEmpty())
20762076
},
20772077
},
2078+
{
2079+
name: "updates object whose namespace is mutated, if it already exists and the object is not Global/GlobalHierarchy",
2080+
args: args{
2081+
fromProxy: test.NewFakeProxy().WithObjs(
2082+
&clusterv1.Cluster{
2083+
ObjectMeta: metav1.ObjectMeta{
2084+
Name: "foo",
2085+
Namespace: "ns1",
2086+
},
2087+
},
2088+
),
2089+
toProxy: test.NewFakeProxy().WithObjs(
2090+
&clusterv1.Cluster{
2091+
ObjectMeta: metav1.ObjectMeta{
2092+
Name: "foo",
2093+
Namespace: "mutatedns1",
2094+
Annotations: map[string]string{"foo": "bar"},
2095+
},
2096+
},
2097+
),
2098+
node: &node{
2099+
identity: corev1.ObjectReference{
2100+
Kind: "Cluster",
2101+
Namespace: "ns1",
2102+
Name: "foo",
2103+
APIVersion: "cluster.x-k8s.io/v1beta1",
2104+
},
2105+
},
2106+
mutators: []ResourceMutatorFunc{
2107+
func(u *unstructured.Unstructured) error {
2108+
return unstructured.SetNestedField(u.Object,
2109+
"mutatedns1",
2110+
"metadata", "namespace")
2111+
},
2112+
},
2113+
},
2114+
want: func(g *WithT, toClient client.Client) {
2115+
c := &clusterv1.Cluster{}
2116+
key := client.ObjectKey{
2117+
Namespace: "mutatedns1",
2118+
Name: "foo",
2119+
}
2120+
g.Expect(toClient.Get(context.Background(), key, c)).ToNot(HaveOccurred())
2121+
g.Expect(c.Annotations).To(BeEmpty())
2122+
},
2123+
},
20782124
{
20792125
name: "should not update Global objects",
20802126
args: args{
@@ -2163,7 +2209,7 @@ func Test_createTargetObject(t *testing.T) {
21632209
fromProxy: tt.args.fromProxy,
21642210
}
21652211

2166-
err := mover.createTargetObject(ctx, tt.args.node, tt.args.toProxy, nil, sets.New[string]())
2212+
err := mover.createTargetObject(ctx, tt.args.node, tt.args.toProxy, tt.args.mutators, sets.New[string]())
21672213
if tt.wantErr {
21682214
g.Expect(err).To(HaveOccurred())
21692215
return

0 commit comments

Comments
 (0)