Add internal/kctl and internal/config packages with unit tests

This commit is contained in:
Stefan Koelle
2026-08-09 11:21:47 +02:00
parent 2dae206ec4
commit dc8bcc555f
6 changed files with 253 additions and 0 deletions
+45
View File
@@ -0,0 +1,45 @@
package kctl
import (
"reflect"
"testing"
)
func testNamespaces() map[string]map[string]string {
return map[string]map[string]string{
"ns-one": {"team-label": "team-a"},
"ns-two": {"team-label": "team-b"},
"ns-three": {"team-label": "team-a"},
"ns-four": {}, // no label at all
}
}
func TestDistinctLabelValues(t *testing.T) {
got := DistinctLabelValues(testNamespaces(), "team-label")
want := []string{"team-a", "team-b"}
if !reflect.DeepEqual(got, want) {
t.Fatalf("got %v, want %v", got, want)
}
}
func TestDistinctLabelValues_UnknownKey(t *testing.T) {
got := DistinctLabelValues(testNamespaces(), "does-not-exist")
if len(got) != 0 {
t.Fatalf("expected empty result, got %v", got)
}
}
func TestNamespacesForLabelValue(t *testing.T) {
got := NamespacesForLabelValue(testNamespaces(), "team-label", "team-a")
want := []string{"ns-one", "ns-three"}
if !reflect.DeepEqual(got, want) {
t.Fatalf("got %v, want %v", got, want)
}
}
func TestNamespacesForLabelValue_NoMatch(t *testing.T) {
got := NamespacesForLabelValue(testNamespaces(), "team-label", "team-z")
if len(got) != 0 {
t.Fatalf("expected empty result, got %v", got)
}
}