mirror of
https://github.com/ahmetb/kubectx.git
synced 2025-09-11 13:28:59 +00:00
kubens: implement namespace switching
Signed-off-by: Ahmet Alp Balkan <ahmetb@google.com>
This commit is contained in:
@@ -3,6 +3,8 @@ package kubeconfig
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/google/go-cmp/cmp"
|
||||
|
||||
"github.com/ahmetb/kubectx/internal/testutil"
|
||||
)
|
||||
|
||||
@@ -44,3 +46,35 @@ func TestKubeconfig_NamespaceOfContext(t *testing.T) {
|
||||
t.Fatalf("c2: expected=%q got=%q", expected, v2)
|
||||
}
|
||||
}
|
||||
|
||||
func TestKubeconfig_SetNamespace(t *testing.T) {
|
||||
l := WithMockKubeconfigLoader(testutil.KC().
|
||||
WithCtxs(
|
||||
testutil.Ctx("c1"),
|
||||
testutil.Ctx("c2").Ns("c2n1")).ToYAML(t))
|
||||
kc := new(Kubeconfig).WithLoader(l)
|
||||
if err := kc.Parse(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if err := kc.SetNamespace("c3", "foo"); err == nil {
|
||||
t.Fatalf("expected error for non-existing ctx")
|
||||
}
|
||||
|
||||
if err := kc.SetNamespace("c1", "c1n1"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := kc.SetNamespace("c2", "c2n2"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := kc.Save(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
expected := testutil.KC().WithCtxs(
|
||||
testutil.Ctx("c1").Ns("c1n1"),
|
||||
testutil.Ctx("c2").Ns("c2n2")).ToYAML(t)
|
||||
if diff := cmp.Diff(l.Output(), expected); diff != "" {
|
||||
t.Fatal(diff)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user