Skip to content

Commit

Permalink
Merge pull request #713 from monopole/moreTestOnLoader
Browse files Browse the repository at this point in the history
Add more loader tests.
  • Loading branch information
k8s-ci-robot authored Jan 22, 2019
2 parents 077d554 + 2e6bdd4 commit 244b3a2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/loader/fileloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
19 changes: 19 additions & 0 deletions pkg/loader/fileloader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit 244b3a2

Please sign in to comment.