Move the default schema cache to the home directory

This commit is contained in:
Brendan Burns
2015-09-16 16:31:45 -07:00
parent 6a04145362
commit afea127a3e
11 changed files with 106 additions and 28 deletions

View File

@@ -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)
}
}
}