Skip to content

Commit

Permalink
Allow fake loader be initialized with directory
Browse files Browse the repository at this point in the history
  • Loading branch information
seans3 committed Feb 27, 2018
1 parent 2a5e1b5 commit 6265526
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions loadertest/fake_loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package loadertest

import (
"os"
"strings"

"k8s.io/kubectl/pkg/kinflate/util/fs"
"k8s.io/kubectl/pkg/loader"
Expand All @@ -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)
Expand Down

0 comments on commit 6265526

Please sign in to comment.