mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-12 01:14:22 +00:00
Allow fake loader be initialized with directory
This commit is contained in:
@@ -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"
|
||||||
@@ -30,11 +31,15 @@ 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)
|
||||||
|
|||||||
Reference in New Issue
Block a user