Add SedTransformerTest

This commit is contained in:
jregan
2019-05-12 11:22:16 -07:00
parent 61d46c26b8
commit 4df576869f
13 changed files with 142 additions and 22 deletions

View File

@@ -128,6 +128,27 @@ func (th *KustTestHarness) LoadAndRunGenerator(
return rm
}
func (th *KustTestHarness) LoadAndRunTransformer(
config, input string) resmap.ResMap {
transConfig, err := th.rf.RF().FromBytes([]byte(config))
if err != nil {
th.t.Fatalf("Err: %v", err)
}
resMap, err := th.rf.NewResMapFromBytes([]byte(input))
if err != nil {
th.t.Fatalf("Err: %v", err)
}
g, err := th.pl.LoadTransformer(th.ldr, transConfig)
if err != nil {
th.t.Fatalf("Err: %v", err)
}
err = g.Transform(resMap)
if err != nil {
th.t.Fatalf("Err: %v", err)
}
return resMap
}
func tabToSpace(input string) string {
var result []string
for _, i := range input {

View File

@@ -27,6 +27,7 @@ import (
const (
XDG_CONFIG_HOME = "XDG_CONFIG_HOME"
defaultConfigSubdir = ".config"
PluginRoot = "plugin"
)
// Use https://github.com/kirsle/configdir instead?

View File

@@ -50,7 +50,7 @@ func DefaultSrcRoot() (string, error) {
root = filepath.Join(
os.Getenv("GOPATH"), "src",
pgmconfig.DomainName,
pgmconfig.ProgramName, plugin.PluginRoot)
pgmconfig.ProgramName, pgmconfig.PluginRoot)
if FileExists(root) {
return root, nil
}
@@ -59,7 +59,7 @@ func DefaultSrcRoot() (string, error) {
// get the root kustomize source directory when
// GOPATH is not set
_, filename, _, _ := runtime.Caller(1)
root = path.Join(path.Dir(filename), "../..", plugin.PluginRoot)
root = path.Join(path.Dir(filename), "../..", pgmconfig.PluginRoot)
if FileExists(root) {
return root, nil
}
@@ -73,7 +73,7 @@ func DefaultSrcRoot() (string, error) {
root = filepath.Join(
pgmconfig.HomeDir(),
pgmconfig.ProgramName, plugin.PluginRoot)
pgmconfig.ProgramName, pgmconfig.PluginRoot)
if FileExists(root) {
return root, nil
}

View File

@@ -16,4 +16,4 @@ limitations under the License.
package plugins
const pluginSymbol = "KustomizePlugin"
const PluginSymbol = "KustomizePlugin"

View File

@@ -141,11 +141,11 @@ func (l *Loader) loadGoPlugin(id resid.ResId) (c Configurable, err error) {
if err != nil {
return nil, errors.Wrapf(err, "plugin %s fails to load", name)
}
symbol, err := p.Lookup(pluginSymbol)
symbol, err := p.Lookup(PluginSymbol)
if err != nil {
return nil, errors.Wrapf(
err, "plugin %s doesn't have symbol %s",
name, pluginSymbol)
name, PluginSymbol)
}
c, ok = symbol.(Configurable)
if !ok {

View File

@@ -25,6 +25,42 @@ import (
"sigs.k8s.io/kustomize/pkg/loader"
)
func TestBaseInResourceList(t *testing.T) {
th := kusttest_test.NewKustTestHarness(t, "/app/prod")
th.WriteK("/app/prod", `
namePrefix: b-
resources:
- ../base
`)
th.WriteK("/app/base", `
namePrefix: a-
resources:
- service.yaml
`)
th.WriteF("/app/base/service.yaml", `
apiVersion: v1
kind: Service
metadata:
name: myService
spec:
selector:
backend: bungie
`)
m, err := th.MakeKustTarget().MakeCustomizedResMap()
if err != nil {
t.Fatalf("Err: %v", err)
}
th.AssertActualEqualsExpected(m, `
apiVersion: v1
kind: Service
metadata:
name: b-a-myService
spec:
selector:
backend: bungie
`)
}
func writeSmallBase(th *kusttest_test.KustTestHarness) {
th.WriteK("/app/base", `
namePrefix: a-