@@ -2114,6 +2114,68 @@ func TestApplyJSONPatchOverride(t *testing.T) {
21142114 },
21152115 },
21162116 },
2117+ {
2118+ name : "reset the labels using add operation" ,
2119+ deployment : appsv1.Deployment {
2120+ TypeMeta : deploymentType ,
2121+ ObjectMeta : metav1.ObjectMeta {
2122+ Name : "deployment-name" ,
2123+ Namespace : "deployment-namespace" ,
2124+ Labels : map [string ]string {
2125+ "app" : "nginx-1" ,
2126+ "key" : "value" ,
2127+ },
2128+ },
2129+ },
2130+ overrides : []placementv1alpha1.JSONPatchOverride {
2131+ {
2132+ Operator : placementv1alpha1 .JSONPatchOverrideOpAdd ,
2133+ Path : "/metadata/labels" ,
2134+ Value : apiextensionsv1.JSON {Raw : []byte (`{"app": "nginx"}` )},
2135+ },
2136+ },
2137+ wantDeployment : appsv1.Deployment {
2138+ TypeMeta : deploymentType ,
2139+ ObjectMeta : metav1.ObjectMeta {
2140+ Name : "deployment-name" ,
2141+ Namespace : "deployment-namespace" ,
2142+ Labels : map [string ]string {
2143+ "app" : "nginx" ,
2144+ },
2145+ },
2146+ },
2147+ },
2148+ {
2149+ name : "reset the labels using replace operation" ,
2150+ deployment : appsv1.Deployment {
2151+ TypeMeta : deploymentType ,
2152+ ObjectMeta : metav1.ObjectMeta {
2153+ Name : "deployment-name" ,
2154+ Namespace : "deployment-namespace" ,
2155+ Labels : map [string ]string {
2156+ "app" : "nginx-1" ,
2157+ "key" : "value" ,
2158+ },
2159+ },
2160+ },
2161+ overrides : []placementv1alpha1.JSONPatchOverride {
2162+ {
2163+ Operator : placementv1alpha1 .JSONPatchOverrideOpReplace ,
2164+ Path : "/metadata/labels" ,
2165+ Value : apiextensionsv1.JSON {Raw : []byte (`{"app": "nginx"}` )},
2166+ },
2167+ },
2168+ wantDeployment : appsv1.Deployment {
2169+ TypeMeta : deploymentType ,
2170+ ObjectMeta : metav1.ObjectMeta {
2171+ Name : "deployment-name" ,
2172+ Namespace : "deployment-namespace" ,
2173+ Labels : map [string ]string {
2174+ "app" : "nginx" ,
2175+ },
2176+ },
2177+ },
2178+ },
21172179 {
21182180 name : "add the first label key value" ,
21192181 deployment : appsv1.Deployment {
@@ -2125,6 +2187,7 @@ func TestApplyJSONPatchOverride(t *testing.T) {
21252187 },
21262188 overrides : []placementv1alpha1.JSONPatchOverride {
21272189 {
2190+ // To add the first key, it cannot use "replace" as the path is missing.
21282191 Operator : placementv1alpha1 .JSONPatchOverrideOpAdd ,
21292192 Path : "/metadata/labels" ,
21302193 Value : apiextensionsv1.JSON {Raw : []byte (`{"app": "nginx"}` )},
0 commit comments