@@ -352,6 +352,125 @@ func TestApplyMonitoringConsoleEnvConfigMap(t *testing.T) {
352352
353353}
354354
355+ func TestAddURLsConfigMapMultipleEnvVars (t * testing.T ) {
356+ // Scenario: Multiple URL types need to be added/updated
357+ // The first URL already exists and matches, but subsequent URLs need processing
358+
359+ t .Run ("All URLs processed when first matches" , func (t * testing.T ) {
360+ configMap := & corev1.ConfigMap {
361+ Data : map [string ]string {
362+ "SPLUNK_CLUSTER_MANAGER_URL" : "splunk-cm-cluster-manager-service" ,
363+ "SPLUNK_INDEXER_URL" : "splunk-idx-indexer-0,splunk-idx-indexer-1" ,
364+ },
365+ }
366+
367+ newURLs := []corev1.EnvVar {
368+ {Name : "SPLUNK_CLUSTER_MANAGER_URL" , Value : "splunk-cm-cluster-manager-service" }, // matches
369+ {Name : "SPLUNK_INDEXER_URL" , Value : "splunk-idx-indexer-0,splunk-idx-indexer-1,splunk-idx-indexer-2" }, // scale up
370+ {Name : "SPLUNK_SEARCH_HEAD_URL" , Value : "splunk-sh-search-head-0,splunk-sh-search-head-1" }, // new
371+ }
372+
373+ AddURLsConfigMap (configMap , "test-cr" , newURLs )
374+
375+ if configMap .Data ["SPLUNK_CLUSTER_MANAGER_URL" ] != "splunk-cm-cluster-manager-service" {
376+ t .Errorf ("SPLUNK_CLUSTER_MANAGER_URL was modified, expected unchanged" )
377+ }
378+
379+ expectedIndexerURL := "splunk-idx-indexer-0,splunk-idx-indexer-1,splunk-idx-indexer-2"
380+ if configMap .Data ["SPLUNK_INDEXER_URL" ] != expectedIndexerURL {
381+ t .Errorf ("SPLUNK_INDEXER_URL not updated correctly. Got: %s, Want: %s" ,
382+ configMap .Data ["SPLUNK_INDEXER_URL" ], expectedIndexerURL )
383+ }
384+
385+ expectedSearchHeadURL := "splunk-sh-search-head-0,splunk-sh-search-head-1"
386+ if configMap .Data ["SPLUNK_SEARCH_HEAD_URL" ] != expectedSearchHeadURL {
387+ t .Errorf ("SPLUNK_SEARCH_HEAD_URL not added. Got: %s, Want: %s" ,
388+ configMap .Data ["SPLUNK_SEARCH_HEAD_URL" ], expectedSearchHeadURL )
389+ }
390+ })
391+
392+ t .Run ("Multiple matching URLs all preserved" , func (t * testing.T ) {
393+ configMap := & corev1.ConfigMap {
394+ Data : map [string ]string {
395+ "SPLUNK_CLUSTER_MANAGER_URL" : "splunk-cm-cluster-manager-service" ,
396+ "SPLUNK_INDEXER_URL" : "splunk-idx-indexer-0,splunk-idx-indexer-1" ,
397+ "SPLUNK_SEARCH_HEAD_URL" : "splunk-sh-search-head-0" ,
398+ "SPLUNK_LICENSE_MANAGER_URL" : "splunk-lm-license-manager-service" ,
399+ },
400+ }
401+
402+ newURLs := []corev1.EnvVar {
403+ {Name : "SPLUNK_CLUSTER_MANAGER_URL" , Value : "splunk-cm-cluster-manager-service" },
404+ {Name : "SPLUNK_INDEXER_URL" , Value : "splunk-idx-indexer-0,splunk-idx-indexer-1" },
405+ {Name : "SPLUNK_SEARCH_HEAD_URL" , Value : "splunk-sh-search-head-0" },
406+ {Name : "SPLUNK_LICENSE_MANAGER_URL" , Value : "splunk-lm-license-manager-service" },
407+ }
408+
409+ AddURLsConfigMap (configMap , "test-cr" , newURLs )
410+
411+ for _ , url := range newURLs {
412+ if val , ok := configMap .Data [url .Name ]; ! ok {
413+ t .Errorf ("URL %s was removed from ConfigMap (bug manifestation)" , url .Name )
414+ } else if val != url .Value {
415+ t .Errorf ("URL %s was modified. Got: %s, Want: %s" , url .Name , val , url .Value )
416+ }
417+ }
418+ })
419+
420+ t .Run ("First URL matches, second is new, third scales up" , func (t * testing.T ) {
421+ configMap := & corev1.ConfigMap {
422+ Data : map [string ]string {
423+ "SPLUNK_CLUSTER_MANAGER_URL" : "splunk-cm-cluster-manager-service" ,
424+ "SPLUNK_INDEXER_URL" : "splunk-idx-indexer-0" ,
425+ },
426+ }
427+
428+ newURLs := []corev1.EnvVar {
429+ {Name : "SPLUNK_CLUSTER_MANAGER_URL" , Value : "splunk-cm-cluster-manager-service" }, // matches
430+ {Name : "SPLUNK_LICENSE_MANAGER_URL" , Value : "splunk-lm-license-manager-service" }, // new
431+ {Name : "SPLUNK_INDEXER_URL" , Value : "splunk-idx-indexer-0,splunk-idx-indexer-1" }, // scale up
432+ }
433+
434+ AddURLsConfigMap (configMap , "test-cr" , newURLs )
435+
436+ if _ , ok := configMap .Data ["SPLUNK_CLUSTER_MANAGER_URL" ]; ! ok {
437+ t .Errorf ("SPLUNK_CLUSTER_MANAGER_URL was removed" )
438+ }
439+
440+ if _ , ok := configMap .Data ["SPLUNK_LICENSE_MANAGER_URL" ]; ! ok {
441+ t .Errorf ("SPLUNK_LICENSE_MANAGER_URL was not added (bug: loop exited early)" )
442+ }
443+
444+ expectedIndexerURL := "splunk-idx-indexer-0,splunk-idx-indexer-1"
445+ if configMap .Data ["SPLUNK_INDEXER_URL" ] != expectedIndexerURL {
446+ t .Errorf ("SPLUNK_INDEXER_URL not scaled up. Got: %s, Want: %s" ,
447+ configMap .Data ["SPLUNK_INDEXER_URL" ], expectedIndexerURL )
448+ }
449+ })
450+
451+ t .Run ("Empty ConfigMap with multiple URLs" , func (t * testing.T ) {
452+ configMap := & corev1.ConfigMap {
453+ Data : map [string ]string {},
454+ }
455+
456+ newURLs := []corev1.EnvVar {
457+ {Name : "SPLUNK_CLUSTER_MANAGER_URL" , Value : "splunk-cm-cluster-manager-service" },
458+ {Name : "SPLUNK_INDEXER_URL" , Value : "splunk-idx-indexer-0,splunk-idx-indexer-1" },
459+ {Name : "SPLUNK_SEARCH_HEAD_URL" , Value : "splunk-sh-search-head-0" },
460+ }
461+
462+ AddURLsConfigMap (configMap , "test-cr" , newURLs )
463+
464+ for _ , url := range newURLs {
465+ if val , ok := configMap .Data [url .Name ]; ! ok {
466+ t .Errorf ("URL %s was not added to empty ConfigMap" , url .Name )
467+ } else if val != url .Value {
468+ t .Errorf ("URL %s has wrong value. Got: %s, Want: %s" , url .Name , val , url .Value )
469+ }
470+ }
471+ })
472+ }
473+
355474func TestGetMonitoringConsoleStatefulSet (t * testing.T ) {
356475 os .Setenv ("SPLUNK_GENERAL_TERMS" , "--accept-sgt-current-at-splunk-com" )
357476
0 commit comments