mirror of
https://github.com/ahmetb/kubectx.git
synced 2025-09-11 13:28:59 +00:00
Move kubeconfig utility to a shared pkg
Signed-off-by: Ahmet Alp Balkan <ahmetb@google.com>
This commit is contained in:
55
internal/kubeconfig/currentcontext_test.go
Normal file
55
internal/kubeconfig/currentcontext_test.go
Normal file
@@ -0,0 +1,55 @@
|
||||
package kubeconfig
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestKubeconfig_GetCurrentContext(t *testing.T) {
|
||||
tl := &testLoader{in: strings.NewReader(`current-context: foo`)}
|
||||
kc := new(Kubeconfig).WithLoader(tl)
|
||||
if err := kc.Parse(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
v := kc.GetCurrentContext()
|
||||
|
||||
expected := "foo"
|
||||
if v != expected {
|
||||
t.Fatalf("expected=%q; got=%q", expected, v)
|
||||
}
|
||||
}
|
||||
|
||||
func TestKubeconfig_GetCurrentContext_missingField(t *testing.T) {
|
||||
tl := &testLoader{in: strings.NewReader(`abc: def`)}
|
||||
kc := new(Kubeconfig).WithLoader(tl)
|
||||
if err := kc.Parse(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
v := kc.GetCurrentContext()
|
||||
|
||||
expected := ""
|
||||
if v != expected {
|
||||
t.Fatalf("expected=%q; got=%q", expected, v)
|
||||
}
|
||||
}
|
||||
|
||||
func TestKubeconfig_UnsetCurrentContext(t *testing.T) {
|
||||
tl := &testLoader{in: strings.NewReader(`current-context: foo`)}
|
||||
kc := new(Kubeconfig).WithLoader(tl)
|
||||
if err := kc.Parse(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := kc.UnsetCurrentContext(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := kc.Save(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
out := tl.out.String()
|
||||
expected := `current-context: ""
|
||||
`
|
||||
if out != expected {
|
||||
t.Fatalf("expected=%q; got=%q", expected, out)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user