mirror of
https://github.com/skoelle/kctl-tui.git
synced 2026-09-18 04:20:25 +00:00
Add internal/kctl and internal/config packages with unit tests
This commit is contained in:
@@ -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)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user