mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-11 17:12:51 +00:00
Add more loader tests.
This commit is contained in:
@@ -133,7 +133,7 @@ func newFileLoaderAt(
|
|||||||
}
|
}
|
||||||
if !fSys.IsDir(absRoot) {
|
if !fSys.IsDir(absRoot) {
|
||||||
return nil, fmt.Errorf(
|
return nil, fmt.Errorf(
|
||||||
"absolute root dir '%s' does not exist", absRoot)
|
"'%s' does not exist or is not a directory", absRoot)
|
||||||
}
|
}
|
||||||
return &fileLoader{
|
return &fileLoader{
|
||||||
roots: append(roots, absRoot),
|
roots: append(roots, absRoot),
|
||||||
|
|||||||
@@ -61,6 +61,25 @@ func MakeFakeFs(td []testData) fs.FileSystem {
|
|||||||
return fSys
|
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) {
|
func TestLoaderLoad(t *testing.T) {
|
||||||
l1 := NewFileLoaderAtRoot(MakeFakeFs(testCases))
|
l1 := NewFileLoaderAtRoot(MakeFakeFs(testCases))
|
||||||
if "/" != l1.Root() {
|
if "/" != l1.Root() {
|
||||||
|
|||||||
Reference in New Issue
Block a user