mirror of
https://github.com/ahmetb/kubectx.git
synced 2025-09-12 14:01:07 +00:00
Move kubeconfig loader utils to cmdutil pkg
Signed-off-by: Ahmet Alp Balkan <ahmetb@google.com>
This commit is contained in:
26
internal/testutil/tempfile.go
Normal file
26
internal/testutil/tempfile.go
Normal file
@@ -0,0 +1,26 @@
|
||||
package testutil
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TempFile(t *testing.T, contents string) (path string, cleanup func()) {
|
||||
// TODO consider removing, used only in one place.
|
||||
t.Helper()
|
||||
|
||||
f, err := ioutil.TempFile(os.TempDir(), "test-file")
|
||||
if err != nil {
|
||||
t.Fatalf("failed to create test file: %v", err)
|
||||
}
|
||||
path = f.Name()
|
||||
if _, err := f.Write([]byte(contents)); err != nil {
|
||||
t.Fatalf("failed to write to test file: %v", err)
|
||||
}
|
||||
|
||||
return path, func() {
|
||||
f.Close()
|
||||
os.Remove(path)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user