mirror of
https://github.com/ahmetb/kubectx.git
synced 2025-09-11 05:19:11 +00:00
kubens: Add facility to store state file
Signed-off-by: Ahmet Alp Balkan <ahmetb@google.com>
This commit is contained in:
38
cmd/kubens/statefile_test.go
Normal file
38
cmd/kubens/statefile_test.go
Normal file
@@ -0,0 +1,38 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestNSFile(t *testing.T) {
|
||||
td, err := ioutil.TempDir(os.TempDir(), "")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer os.RemoveAll(td)
|
||||
|
||||
f := NewNSFile("foo")
|
||||
f.dir = td
|
||||
v, err := f.Load()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if v != "" {
|
||||
t.Fatalf("Load() expected empty; got=%v", err)
|
||||
}
|
||||
|
||||
err = f.Save("bar")
|
||||
if err != nil {
|
||||
t.Fatalf("Save() err=%v", err)
|
||||
}
|
||||
|
||||
v, err = f.Load()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if expected := "bar"; v != expected {
|
||||
t.Fatalf("Load()=%q; expected=%q", v, expected)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user