Allow fake loader be initialized with directory

This commit is contained in:
Sean Sullivan
2018-02-27 15:30:32 -08:00
parent 2a5e1b5acb
commit 62655260a6

View File

@@ -18,6 +18,7 @@ package loadertest
import (
"os"
"strings"
"k8s.io/kubectl/pkg/kinflate/util/fs"
"k8s.io/kubectl/pkg/loader"
@@ -30,11 +31,15 @@ type FakeLoader struct {
}
// NewFakeLoader returns a Loader that delegates calls, and encapsulates
// a fake file system that the Loader reads from . "initialFilePath" parameter
// must be an absolute path.
// a fake file system that the Loader reads from. "initialFilePath" parameter
// must be an absolute path, and it can be a directory if it has a
// trailing slash: "/home/seans/project/" (dir) -- "/home/seans/project" (file)
func NewFakeLoader(initialFilePath string) FakeLoader {
// Create fake filesystem and inject it into initial Loader.
fakefs := fs.MakeFakeFS()
if strings.HasSuffix(initialFilePath, "/") {
fakefs.Mkdir(initialFilePath, 0x777)
}
var schemes []loader.SchemeLoader
schemes = append(schemes, loader.NewFileLoader(fakefs))
rootLoader := loader.Init(schemes)