From ed1b6320eb061d1a672b009dd8873e470e53a72c Mon Sep 17 00:00:00 2001 From: Rishi Jat Date: Wed, 5 Nov 2025 17:06:08 +0530 Subject: [PATCH] Add unit test Signed-off-by: Rishi Jat --- pkg/cluster/discovery_test.go | 50 +++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 pkg/cluster/discovery_test.go diff --git a/pkg/cluster/discovery_test.go b/pkg/cluster/discovery_test.go new file mode 100644 index 0000000..54d9064 --- /dev/null +++ b/pkg/cluster/discovery_test.go @@ -0,0 +1,50 @@ +package cluster + +import ( + "testing" +) + +func TestIsWDSCluster(t *testing.T) { + tests := []struct { + name string + input string + expected bool + }{ + {"prefix_wds", "wds1", true}, + {"contains_dash", "prod-wds-2", true}, + {"contains_underscore", "test_wds_env", true}, + {"no_wds", "prodcluster", false}, + {"mixed_case", "WdsCluster", false}, // function likely case-sensitive + {"empty", "", false}, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got := isWDSCluster(tt.input) + if got != tt.expected { + t.Errorf("isWDSCluster(%q) = %v, want %v", tt.input, got, tt.expected) + } + }) + } +} + +func TestGetTargetNamespace(t *testing.T) { + tests := []struct { + name string + input string + expected string + }{ + {"empty_returns_default", "", "default"}, + {"non_empty_returns_same", "kube-system", "kube-system"}, + {"spaces_not_trimmed", " myns ", " myns "}, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got := GetTargetNamespace(tt.input) + if got != tt.expected { + t.Errorf("GetTargetNamespace(%q) = %q, want %q", tt.input, got, tt.expected) + } + }) + } +}