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 ( import (
"os" "os"
"strings"
"k8s.io/kubectl/pkg/kinflate/util/fs" "k8s.io/kubectl/pkg/kinflate/util/fs"
"k8s.io/kubectl/pkg/loader" "k8s.io/kubectl/pkg/loader"
@@ -31,10 +32,14 @@ type FakeLoader struct {
// NewFakeLoader returns a Loader that delegates calls, and encapsulates // NewFakeLoader returns a Loader that delegates calls, and encapsulates
// a fake file system that the Loader reads from. "initialFilePath" parameter // a fake file system that the Loader reads from. "initialFilePath" parameter
// must be an absolute path. // 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 { func NewFakeLoader(initialFilePath string) FakeLoader {
// Create fake filesystem and inject it into initial Loader. // Create fake filesystem and inject it into initial Loader.
fakefs := fs.MakeFakeFS() fakefs := fs.MakeFakeFS()
if strings.HasSuffix(initialFilePath, "/") {
fakefs.Mkdir(initialFilePath, 0x777)
}
var schemes []loader.SchemeLoader var schemes []loader.SchemeLoader
schemes = append(schemes, loader.NewFileLoader(fakefs)) schemes = append(schemes, loader.NewFileLoader(fakefs))
rootLoader := loader.Init(schemes) rootLoader := loader.Init(schemes)