Add more loader tests.

This commit is contained in:
Jeffrey Regan
2019-01-22 14:08:17 -08:00
parent 077d554b76
commit 2e6bdd4041
2 changed files with 20 additions and 1 deletions

View File

@@ -133,7 +133,7 @@ func newFileLoaderAt(
}
if !fSys.IsDir(absRoot) {
return nil, fmt.Errorf(
"absolute root dir '%s' does not exist", absRoot)
"'%s' does not exist or is not a directory", absRoot)
}
return &fileLoader{
roots: append(roots, absRoot),

View File

@@ -61,6 +61,25 @@ func MakeFakeFs(td []testData) fs.FileSystem {
return fSys
}
func TestNewFileLoaderAt_DemandsDirectory(t *testing.T) {
fSys := MakeFakeFs(testCases)
_, err := newFileLoaderAt("/foo", fSys, []string{}, nil)
if err != nil {
t.Fatalf("Unexpected error - a directory should work.")
}
_, err = newFileLoaderAt("/foo/project", fSys, []string{}, nil)
if err != nil {
t.Fatalf("Unexpected error - a directory should work.")
}
_, err = newFileLoaderAt("/foo/project/fileA.yaml", fSys, []string{}, nil)
if err == nil {
t.Fatalf("Expected error - a file should not work.")
}
if !strings.Contains(err.Error(), "does not exist or is not a directory") {
t.Fatalf("unexpected err: %v", err)
}
}
func TestLoaderLoad(t *testing.T) {
l1 := NewFileLoaderAtRoot(MakeFakeFs(testCases))
if "/" != l1.Root() {