@@ -5134,57 +5134,74 @@ func Test_GetRepositoryLock(t *testing.T) {
51345134func Test_mergeKustomizeOverride (t * testing.T ) {
51355135 tests := []struct {
51365136 name string
5137- existing v1alpha1.KustomizeImages
5138- new v1alpha1.KustomizeImages
5139- expected v1alpha1.KustomizeImages
5137+ existing * v1alpha1.KustomizeImages
5138+ new * v1alpha1.KustomizeImages
5139+ expected * v1alpha1.KustomizeImages
51405140 }{
5141- {"with-tag" , [] v1alpha1.KustomizeImage {"nginx:foo" },
5142- [] v1alpha1.KustomizeImage {"nginx:foo" },
5143- [] v1alpha1.KustomizeImage {"nginx:foo" }},
5144- {"no-tag" , [] v1alpha1.KustomizeImage {"nginx:foo" },
5145- [] v1alpha1.KustomizeImage {"nginx" },
5146- [] v1alpha1.KustomizeImage {"nginx:foo" }},
5147- {"with-tag-1" , [] v1alpha1.KustomizeImage {"nginx" },
5148- [] v1alpha1.KustomizeImage {"nginx:latest" },
5149- [] v1alpha1.KustomizeImage {"nginx:latest" }},
5150- {"with-tag-sha" , [] v1alpha1.KustomizeImage {"nginx:latest" },
5151- [] v1alpha1.KustomizeImage {"nginx:latest@sha256:91734281c0ebfc6f1aea979cffeed5079cfe786228a71cc6f1f46a228cde6e34" },
5152- [] v1alpha1.KustomizeImage {"nginx:latest@sha256:91734281c0ebfc6f1aea979cffeed5079cfe786228a71cc6f1f46a228cde6e34" }},
5153-
5154- {"2-images" , [] v1alpha1.KustomizeImage {"nginx:latest" ,
5141+ {"with-tag" , & v1alpha1.KustomizeImages {"nginx:foo" },
5142+ & v1alpha1.KustomizeImages {"nginx:foo" },
5143+ & v1alpha1.KustomizeImages {"nginx:foo" }},
5144+ {"no-tag" , & v1alpha1.KustomizeImages {"nginx:foo" },
5145+ & v1alpha1.KustomizeImages {"nginx" },
5146+ & v1alpha1.KustomizeImages {"nginx:foo" }},
5147+ {"with-tag-1" , & v1alpha1.KustomizeImages {"nginx" },
5148+ & v1alpha1.KustomizeImages {"nginx:latest" },
5149+ & v1alpha1.KustomizeImages {"nginx:latest" }},
5150+ {"with-tag-sha" , & v1alpha1.KustomizeImages {"nginx:latest" },
5151+ & v1alpha1.KustomizeImages {"nginx:latest@sha256:91734281c0ebfc6f1aea979cffeed5079cfe786228a71cc6f1f46a228cde6e34" },
5152+ & v1alpha1.KustomizeImages {"nginx:latest@sha256:91734281c0ebfc6f1aea979cffeed5079cfe786228a71cc6f1f46a228cde6e34" }},
5153+
5154+ {"2-images" , & v1alpha1.KustomizeImages {"nginx:latest" ,
51555155 "bitnami/nginx:latest@sha256:1a2fe3f9f6d1d38d5a7ee35af732fdb7d15266ec3dbc79bbc0355742cd24d3ec" },
5156- [] v1alpha1.KustomizeImage {"nginx:latest@sha256:91734281c0ebfc6f1aea979cffeed5079cfe786228a71cc6f1f46a228cde6e34" ,
5156+ & v1alpha1.KustomizeImages {"nginx:latest@sha256:91734281c0ebfc6f1aea979cffeed5079cfe786228a71cc6f1f46a228cde6e34" ,
51575157 "bitnami/nginx@sha256:1a2fe3f9f6d1d38d5a7ee35af732fdb7d15266ec3dbc79bbc0355742cd24d3ec" },
5158- [] v1alpha1.KustomizeImage {"nginx:latest@sha256:91734281c0ebfc6f1aea979cffeed5079cfe786228a71cc6f1f46a228cde6e34" ,
5158+ & v1alpha1.KustomizeImages {"nginx:latest@sha256:91734281c0ebfc6f1aea979cffeed5079cfe786228a71cc6f1f46a228cde6e34" ,
51595159 "bitnami/nginx:latest@sha256:1a2fe3f9f6d1d38d5a7ee35af732fdb7d15266ec3dbc79bbc0355742cd24d3ec" }},
51605160
5161- {"with-registry" , []v1alpha1.KustomizeImage {"quay.io/nginx:latest" },
5162- []v1alpha1.KustomizeImage {"quay.io/nginx:latest" },
5163- []v1alpha1.KustomizeImage {"quay.io/nginx:latest" }},
5164- {"with-registry-1" , []v1alpha1.KustomizeImage {"quay.io/nginx:latest" },
5165- []v1alpha1.KustomizeImage {"docker.io/nginx:latest" },
5166- []v1alpha1.KustomizeImage {"docker.io/nginx:latest" , "quay.io/nginx:latest" }},
5161+ {"with-registry" , & v1alpha1.KustomizeImages {"quay.io/nginx:latest" },
5162+ & v1alpha1.KustomizeImages {"quay.io/nginx:latest" },
5163+ & v1alpha1.KustomizeImages {"quay.io/nginx:latest" }},
5164+ {"with-registry-1" , & v1alpha1.KustomizeImages {"quay.io/nginx:latest" },
5165+ & v1alpha1.KustomizeImages {"docker.io/nginx:latest" },
5166+ & v1alpha1.KustomizeImages {"docker.io/nginx:latest" , "quay.io/nginx:latest" }},
5167+ {"o_is_nil" , & v1alpha1.KustomizeImages {"nginx:foo" },
5168+ nil ,
5169+ & v1alpha1.KustomizeImages {"nginx:foo" }},
5170+ {"t_is_nil" , nil ,
5171+ & v1alpha1.KustomizeImages {"nginx:foo" },
5172+ & v1alpha1.KustomizeImages {"nginx:foo" }},
5173+ {"both_are_nil" , nil ,
5174+ nil ,
5175+ nil },
5176+ {"add_to_empty" , & v1alpha1.KustomizeImages {},
5177+ & v1alpha1.KustomizeImages {"nginx:foo" },
5178+ & v1alpha1.KustomizeImages {"nginx:foo" }},
51675179 }
51685180 for _ , tt := range tests {
51695181 t .Run (tt .name , func (t * testing.T ) {
51705182 existingImages := kustomizeOverride {
51715183 Kustomize : kustomizeImages {
5172- Images : & tt .existing ,
5184+ Images : tt .existing ,
51735185 },
51745186 }
51755187 newImages := kustomizeOverride {
51765188 Kustomize : kustomizeImages {
5177- Images : & tt .new ,
5189+ Images : tt .new ,
51785190 },
51795191 }
51805192 expectedImages := kustomizeOverride {
51815193 Kustomize : kustomizeImages {
5182- Images : & tt .expected ,
5194+ Images : tt .expected ,
51835195 },
51845196 }
51855197
51865198 mergeKustomizeOverride (& existingImages , & newImages )
5187- assert .ElementsMatch (t , * expectedImages .Kustomize .Images , * existingImages .Kustomize .Images )
5199+ if expectedImages .Kustomize .Images == nil {
5200+ assert .Nil (t , existingImages .Kustomize .Images )
5201+ } else {
5202+ require .NotNil (t , existingImages .Kustomize .Images )
5203+ assert .ElementsMatch (t , * expectedImages .Kustomize .Images , * existingImages .Kustomize .Images )
5204+ }
51885205 })
51895206 }
51905207}
0 commit comments