mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-10 16:42:51 +00:00
Allow fake loader be initialized with directory
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user