@@ -94,10 +94,8 @@ func TestUnstructuredList(t *testing.T) {
9494 DesiredObject : desired [1 ],
9595 ClusterObject : cluster [1 ],
9696 Patch : jsondiff.Patch {
97- {Type : jsondiff .OperationAdd , Path : "/metadata" , Value : map [string ]interface {}{
98- "annotations" : map [string ]interface {}{
99- "annotated" : "yes" ,
100- },
97+ {Type : jsondiff .OperationAdd , Path : "/metadata/annotations" , Value : map [string ]interface {}{
98+ "annotated" : "yes" ,
10199 }},
102100 },
103101 },
@@ -250,10 +248,8 @@ func TestUnstructuredList(t *testing.T) {
250248 DesiredObject : desired [1 ],
251249 ClusterObject : cluster [1 ],
252250 Patch : jsondiff.Patch {
253- {Type : jsondiff .OperationAdd , Path : "/metadata" , Value : map [string ]interface {}{
254- "labels" : map [string ]interface {}{
255- "labeled" : "change" ,
256- },
251+ {Type : jsondiff .OperationAdd , Path : "/metadata/labels" , Value : map [string ]interface {}{
252+ "labeled" : "change" ,
257253 }},
258254 },
259255 },
@@ -294,10 +290,8 @@ func TestUnstructuredList(t *testing.T) {
294290 DesiredObject : desired [1 ],
295291 ClusterObject : cluster [1 ],
296292 Patch : jsondiff.Patch {
297- {Type : jsondiff .OperationAdd , Path : "/metadata" , Value : map [string ]interface {}{
298- "labels" : map [string ]interface {}{
299- "labeled" : "change" ,
300- },
293+ {Type : jsondiff .OperationAdd , Path : "/metadata/labels" , Value : map [string ]interface {}{
294+ "labeled" : "change" ,
301295 }},
302296 },
303297 },
@@ -507,6 +501,44 @@ func TestUnstructured(t *testing.T) {
507501 }
508502 },
509503 },
504+ {
505+ name : "ConfigMap with added label and annotation" ,
506+ path : "testdata/empty-configmap.yaml" ,
507+ mutateDesired : func (obj * unstructured.Unstructured ) {
508+ _ = unstructured .SetNestedField (obj .Object , "yes" , "metadata" , "annotations" , "annotated" )
509+ _ = unstructured .SetNestedField (obj .Object , "yes" , "metadata" , "labels" , "labeled" )
510+ },
511+ want : func (desired , cluster client.Object ) * Diff {
512+ return & Diff {
513+ Type : DiffTypeUpdate ,
514+ DesiredObject : desired ,
515+ ClusterObject : cluster ,
516+ Patch : jsondiff.Patch {
517+ {Type : jsondiff .OperationAdd , Path : "/metadata/annotations" , Value : map [string ]interface {}{"annotated" : "yes" }},
518+ {Type : jsondiff .OperationAdd , Path : "/metadata/labels" , Value : map [string ]interface {}{"labeled" : "yes" }},
519+ },
520+ }
521+ },
522+ },
523+ {
524+ name : "Annotated ConfigMap with added label and annotation" ,
525+ path : "testdata/annotated-configmap.yaml" ,
526+ mutateDesired : func (obj * unstructured.Unstructured ) {
527+ _ = unstructured .SetNestedField (obj .Object , "yes" , "metadata" , "annotations" , "annotated" )
528+ _ = unstructured .SetNestedField (obj .Object , "yes" , "metadata" , "labels" , "labeled" )
529+ },
530+ want : func (desired , cluster client.Object ) * Diff {
531+ return & Diff {
532+ Type : DiffTypeUpdate ,
533+ DesiredObject : desired ,
534+ ClusterObject : cluster ,
535+ Patch : jsondiff.Patch {
536+ {Type : jsondiff .OperationAdd , Path : "/metadata/annotations/annotated" , Value : "yes" },
537+ {Type : jsondiff .OperationAdd , Path : "/metadata/labels" , Value : map [string ]interface {}{"labeled" : "yes" }},
538+ },
539+ }
540+ },
541+ },
510542 {
511543 name : "Deployment with missing label and annotation" ,
512544 path : "testdata/deployment.yaml" ,
0 commit comments