@@ -15,10 +15,13 @@ import (
1515 configv1 "github.com/openshift/api/config/v1"
1616 fakeconfigclientv1 "github.com/openshift/client-go/config/clientset/versioned/fake"
1717 "github.com/openshift/library-go/pkg/crypto"
18+
1819 corev1 "k8s.io/api/core/v1"
1920 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2021 "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
2122 "k8s.io/apimachinery/pkg/runtime"
23+
24+ "github.com/google/go-cmp/cmp"
2225)
2326
2427// makeGenericOperatorConfigYAML generates a GenericOperatorConfig YAML string
@@ -303,38 +306,38 @@ func TestModifyConfigMap(t *testing.T) {
303306 },
304307 },
305308 {
306- name : "ConfigMap with valid GenericOperatorConfig - annotation value not set to true - no modification" ,
307- configMap : func () * corev1.ConfigMap {
308- cm := makeConfigMap (true , map [string ]string {
309- genericOperatorConfigCMKey : makeGenericOperatorConfigYAML (testCipherSuites , tlsVersion12 ),
310- })
311- cm .Annotations [ConfigMapInjectTLSAnnotation ] = "false"
312- return cm
313- }(),
314- apiServer : makeAPIServerConfig (withCustomTLSProfile (testOpenSSLCipherSuites , configv1 .VersionTLS13 )),
315- expectError : false ,
316- validateConfigMap : func (t * testing.T , original , modified * corev1.ConfigMap ) {
317- if err := validateConfigMapsEqual (original , modified ); err != nil {
318- t .Fatalf ("validation failed: %v" , err )
319- }
320- },
309+ name : "ConfigMap with valid GenericOperatorConfig - annotation value not set to true - no modification" ,
310+ configMap : func () * corev1.ConfigMap {
311+ cm := makeConfigMap (true , map [string ]string {
312+ genericOperatorConfigCMKey : makeGenericOperatorConfigYAML (testCipherSuites , tlsVersion12 ),
313+ })
314+ cm .Annotations [ConfigMapInjectTLSAnnotation ] = "false"
315+ return cm
316+ }(),
317+ apiServer : makeAPIServerConfig (withCustomTLSProfile (testOpenSSLCipherSuites , configv1 .VersionTLS13 )),
318+ expectError : false ,
319+ validateConfigMap : func (t * testing.T , original , modified * corev1.ConfigMap ) {
320+ if err := validateConfigMapsEqual (original , modified ); err != nil {
321+ t .Fatalf ("validation failed: %v" , err )
322+ }
323+ },
321324 },
322325 {
323- name : "ConfigMap with valid GenericOperatorConfig - annotation value empty - no modification" ,
324- configMap : func () * corev1.ConfigMap {
325- cm := makeConfigMap (true , map [string ]string {
326- genericOperatorConfigCMKey : makeGenericOperatorConfigYAML (testCipherSuites , tlsVersion12 ),
327- })
328- cm .Annotations [ConfigMapInjectTLSAnnotation ] = ""
329- return cm
330- }(),
331- apiServer : makeAPIServerConfig (withCustomTLSProfile (testOpenSSLCipherSuites , configv1 .VersionTLS13 )),
332- expectError : false ,
333- validateConfigMap : func (t * testing.T , original , modified * corev1.ConfigMap ) {
334- if err := validateConfigMapsEqual (original , modified ); err != nil {
335- t .Fatalf ("validation failed: %v" , err )
336- }
337- },
326+ name : "ConfigMap with valid GenericOperatorConfig - annotation value empty - no modification" ,
327+ configMap : func () * corev1.ConfigMap {
328+ cm := makeConfigMap (true , map [string ]string {
329+ genericOperatorConfigCMKey : makeGenericOperatorConfigYAML (testCipherSuites , tlsVersion12 ),
330+ })
331+ cm .Annotations [ConfigMapInjectTLSAnnotation ] = ""
332+ return cm
333+ }(),
334+ apiServer : makeAPIServerConfig (withCustomTLSProfile (testOpenSSLCipherSuites , configv1 .VersionTLS13 )),
335+ expectError : false ,
336+ validateConfigMap : func (t * testing.T , original , modified * corev1.ConfigMap ) {
337+ if err := validateConfigMapsEqual (original , modified ); err != nil {
338+ t .Fatalf ("validation failed: %v" , err )
339+ }
340+ },
338341 },
339342 {
340343 name : "ConfigMap with annotation but nil Data - no modification" ,
@@ -523,11 +526,8 @@ servingInfo:
523526 apiServer : makeAPIServerConfig (withCustomTLSProfile (testOpenSSLCipherSuitesReversed , configv1 .VersionTLS13 )),
524527 expectError : false ,
525528 validateConfigMap : func (t * testing.T , original , modified * corev1.ConfigMap ) {
526- // Validate through pure string comparison
527- originalData := original .Data [genericOperatorConfigCMKey ]
528- modifiedData := modified .Data [genericOperatorConfigCMKey ]
529- if originalData != modifiedData {
530- t .Errorf ("ConfigMap data was modified when it should not have been.\n Original:\n %s\n Modified:\n %s" , originalData , modifiedData )
529+ if diff := cmp .Diff (original .Data [genericOperatorConfigCMKey ], modified .Data [genericOperatorConfigCMKey ]); diff != "" {
530+ t .Errorf ("ConfigMap YAML mismatch (-want +got):\n %s" , diff )
531531 }
532532 },
533533 },
0 commit comments