@@ -475,6 +475,78 @@ func TestGetMonitoringConsoleStatefulSet(t *testing.T) {
475475 cr .ObjectMeta .Labels ["app.kubernetes.io/test-extra-label" ] = "test-extra-label-value"
476476 test (loadFixture (t , "statefulset_stack1_monitoring_console_with_service_account_1.json" ))
477477}
478+
479+ func TestGetMonitoringConsoleConfigDataHash (t * testing.T ) {
480+ if got := getMonitoringConsoleConfigDataHash (nil ); got != "" {
481+ t .Errorf ("Expected empty hash for nil data, got=%s" , got )
482+ }
483+
484+ dataA := map [string ]string {"SPLUNK_SEARCH_HEAD_URL" : "sh1,sh2" , "SPLUNK_CLUSTER_MANAGER_URL" : "cm1" }
485+ dataB := map [string ]string {"SPLUNK_CLUSTER_MANAGER_URL" : "cm1" , "SPLUNK_SEARCH_HEAD_URL" : "sh1,sh2" }
486+ dataC := map [string ]string {"SPLUNK_CLUSTER_MANAGER_URL" : "cm1" , "SPLUNK_SEARCH_HEAD_URL" : "sh1,sh3" }
487+
488+ hashA := getMonitoringConsoleConfigDataHash (dataA )
489+ hashB := getMonitoringConsoleConfigDataHash (dataB )
490+ hashC := getMonitoringConsoleConfigDataHash (dataC )
491+
492+ if hashA == "" {
493+ t .Errorf ("Expected non-empty hash for non-empty data" )
494+ }
495+ if hashA != hashB {
496+ t .Errorf ("Expected stable hash for same data regardless of map iteration order" )
497+ }
498+ if hashA == hashC {
499+ t .Errorf ("Expected different hash when data changes" )
500+ }
501+ }
502+
503+ func TestGetMonitoringConsoleStatefulSetUsesConfigDataHash (t * testing.T ) {
504+ os .Setenv ("SPLUNK_GENERAL_TERMS" , "--accept-sgt-current-at-splunk-com" )
505+ ctx := context .TODO ()
506+
507+ cr := enterpriseApi.MonitoringConsole {
508+ ObjectMeta : metav1.ObjectMeta {
509+ Name : "stack1" ,
510+ Namespace : "test" ,
511+ },
512+ }
513+
514+ c := spltest .NewMockClient ()
515+ _ , err := splutil .ApplyNamespaceScopedSecretObject (ctx , c , "test" )
516+ if err != nil {
517+ t .Fatalf ("Failed to create namespace scoped secret: %v" , err )
518+ }
519+
520+ monitoringConsoleConfigMapName := GetSplunkMonitoringconsoleConfigMapName (cr .GetName (), SplunkMonitoringConsole )
521+ monitoringConsoleConfigMap := corev1.ConfigMap {
522+ ObjectMeta : metav1.ObjectMeta {
523+ Name : monitoringConsoleConfigMapName ,
524+ Namespace : "test" ,
525+ ResourceVersion : "12345" ,
526+ },
527+ Data : map [string ]string {
528+ "SPLUNK_CLUSTER_MANAGER_URL" : "cm1" ,
529+ "SPLUNK_SEARCH_HEAD_URL" : "sh1,sh2" ,
530+ },
531+ }
532+ c .AddObject (& monitoringConsoleConfigMap )
533+
534+ ss , err := getMonitoringConsoleStatefulSet (ctx , c , & cr )
535+ if err != nil {
536+ t .Fatalf ("getMonitoringConsoleStatefulSet() returned error: %v" , err )
537+ }
538+
539+ got := ss .Spec .Template .ObjectMeta .Annotations [monitoringConsoleConfigRev ]
540+ want := getMonitoringConsoleConfigDataHash (monitoringConsoleConfigMap .Data )
541+
542+ if got != want {
543+ t .Errorf ("Expected monitoringConsoleConfigRev to be data hash. got=%s want=%s" , got , want )
544+ }
545+ if got == monitoringConsoleConfigMap .ResourceVersion {
546+ t .Errorf ("monitoringConsoleConfigRev must not use configMap resourceVersion" )
547+ }
548+ }
549+
478550func TestMonitoringConsoleSpecNotCreatedWithoutGeneralTerms (t * testing.T ) {
479551 // Unset the SPLUNK_GENERAL_TERMS environment variable
480552 os .Unsetenv ("SPLUNK_GENERAL_TERMS" )
0 commit comments