mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-01-05 07:27:21 +00:00
Move the default schema cache to the home directory
This commit is contained in:
@@ -22,6 +22,7 @@ import (
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"os"
|
||||
"os/user"
|
||||
"path"
|
||||
"sort"
|
||||
"strings"
|
||||
@@ -302,3 +303,32 @@ func TestValidateCachesSchema(t *testing.T) {
|
||||
t.Errorf("unexpected cache file error: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSubstitueUser(t *testing.T) {
|
||||
usr, _ := user.Current()
|
||||
tests := []struct {
|
||||
input string
|
||||
expected string
|
||||
expectErr bool
|
||||
}{
|
||||
{input: "~/foo", expected: path.Join(os.Getenv("HOME"), "foo")},
|
||||
{input: "~" + usr.Username + "/bar", expected: usr.HomeDir + "/bar"},
|
||||
{input: "/foo/bar", expected: "/foo/bar"},
|
||||
{input: "~doesntexit/bar", expectErr: true},
|
||||
}
|
||||
for _, test := range tests {
|
||||
output, err := substituteUserHome(test.input)
|
||||
if test.expectErr {
|
||||
if err == nil {
|
||||
t.Error("unexpected non-error")
|
||||
}
|
||||
continue
|
||||
}
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
if output != test.expected {
|
||||
t.Errorf("expected: %s, saw: %s", test.expected, output)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user