Merge pull request #1866 from monopole/anotherTestMove

Move another test up.
This commit is contained in:
Jeff Regan
2019-11-29 08:02:03 -08:00
committed by GitHub
2 changed files with 17 additions and 25 deletions

View File

@@ -56,6 +56,11 @@ func (th testingHarness) MakeOptionsPluginsDisabled() Options {
func (th testingHarness) MakeOptionsPluginsEnabled() Options { func (th testingHarness) MakeOptionsPluginsEnabled() Options {
c, err := konfig.EnabledPluginConfig() c, err := konfig.EnabledPluginConfig()
if err != nil { if err != nil {
if strings.Contains(err.Error(), "unable to find plugin root") {
th.t.Log(
"Tests that want to run with plugins enabled must be " +
"bookended by calls to NewPluginTestEnv.Set(), Reset().")
}
th.t.Fatal(err) th.t.Fatal(err)
} }
return Options{ return Options{

View File

@@ -1,7 +1,7 @@
// Copyright 2019 The Kubernetes Authors. // Copyright 2019 The Kubernetes Authors.
// SPDX-License-Identifier: Apache-2.0 // SPDX-License-Identifier: Apache-2.0
package target_test package krusty_test
import ( import (
"testing" "testing"
@@ -10,7 +10,7 @@ import (
"sigs.k8s.io/kustomize/api/types" "sigs.k8s.io/kustomize/api/types"
) )
func writeDeployment(th *kusttest_test.KustTestHarness, path string) { func writeDeployment(th testingHarness, path string) {
th.WriteF(path, ` th.WriteF(path, `
apiVersion: apps/v1 apiVersion: apps/v1
kind: Deployment kind: Deployment
@@ -28,8 +28,7 @@ spec:
`) `)
} }
func writeStringPrefixer( func writeStringPrefixer(th testingHarness, path, name string) {
th *kusttest_test.KustTestHarness, path, name string) {
th.WriteF(path, ` th.WriteF(path, `
apiVersion: someteam.example.com/v1 apiVersion: someteam.example.com/v1
kind: StringPrefixer kind: StringPrefixer
@@ -38,8 +37,7 @@ metadata:
`) `)
} }
func writeDatePrefixer( func writeDatePrefixer(th testingHarness, path, name string) {
th *kusttest_test.KustTestHarness, path, name string) {
th.WriteF(path, ` th.WriteF(path, `
apiVersion: someteam.example.com/v1 apiVersion: someteam.example.com/v1
kind: DatePrefixer kind: DatePrefixer
@@ -57,8 +55,7 @@ func TestOrderedTransformers(t *testing.T) {
tc.BuildGoPlugin( tc.BuildGoPlugin(
"someteam.example.com", "v1", "DatePrefixer") "someteam.example.com", "v1", "DatePrefixer")
th := makeTestHarness(t)
th := kusttest_test.NewKustTestHarnessAllowPlugins(t, "/app")
th.WriteK("/app", ` th.WriteK("/app", `
resources: resources:
- deployment.yaml - deployment.yaml
@@ -73,10 +70,7 @@ transformers:
writeStringPrefixer(th, "/app/peachPrefixer.yaml", "peach") writeStringPrefixer(th, "/app/peachPrefixer.yaml", "peach")
writeDatePrefixer(th, "/app/date1Prefixer.yaml", "date1") writeDatePrefixer(th, "/app/date1Prefixer.yaml", "date1")
writeDatePrefixer(th, "/app/date2Prefixer.yaml", "date2") writeDatePrefixer(th, "/app/date2Prefixer.yaml", "date2")
m, err := th.MakeKustTarget().MakeCustomizedResMap() m := th.Run("/app", th.MakeOptionsPluginsEnabled())
if err != nil {
t.Fatalf("Err: %v", err)
}
th.AssertActualEqualsExpected(m, ` th.AssertActualEqualsExpected(m, `
apiVersion: apps/v1 apiVersion: apps/v1
kind: Deployment kind: Deployment
@@ -101,14 +95,13 @@ func TestPluginsNotEnabled(t *testing.T) {
tc.BuildGoPlugin( tc.BuildGoPlugin(
"someteam.example.com", "v1", "StringPrefixer") "someteam.example.com", "v1", "StringPrefixer")
th := kusttest_test.NewKustTestHarness(t, "/app") th := makeTestHarness(t)
th.WriteK("/app", ` th.WriteK("/app", `
transformers: transformers:
- stringPrefixer.yaml - stringPrefixer.yaml
`) `)
writeStringPrefixer(th, "/app/stringPrefixer.yaml", "apple") writeStringPrefixer(th, "/app/stringPrefixer.yaml", "apple")
err := th.RunWithErr("/app", th.MakeOptionsPluginsDisabled())
_, err := th.MakeKustTarget().MakeCustomizedResMap()
if err == nil { if err == nil {
t.Fatalf("expected error") t.Fatalf("expected error")
} }
@@ -124,7 +117,7 @@ func TestSedTransformer(t *testing.T) {
tc.PrepExecPlugin( tc.PrepExecPlugin(
"someteam.example.com", "v1", "SedTransformer") "someteam.example.com", "v1", "SedTransformer")
th := kusttest_test.NewKustTestHarnessAllowPlugins(t, "/app") th := makeTestHarness(t)
th.WriteK("/app", ` th.WriteK("/app", `
resources: resources:
- configmap.yaml - configmap.yaml
@@ -161,10 +154,7 @@ data:
foo: $FOO foo: $FOO
`) `)
m, err := th.MakeKustTarget().MakeCustomizedResMap() m := th.Run("/app", th.MakeOptionsPluginsEnabled())
if err != nil {
t.Fatalf("Err: %v", err)
}
th.AssertActualEqualsExpected(m, ` th.AssertActualEqualsExpected(m, `
apiVersion: v1 apiVersion: v1
data: data:
@@ -195,7 +185,7 @@ func TestTransformedTransformers(t *testing.T) {
tc.BuildGoPlugin( tc.BuildGoPlugin(
"someteam.example.com", "v1", "DatePrefixer") "someteam.example.com", "v1", "DatePrefixer")
th := kusttest_test.NewKustTestHarnessAllowPlugins(t, "/app/overlay") th := makeTestHarness(t)
th.WriteK("/app/base", ` th.WriteK("/app/base", `
resources: resources:
@@ -214,10 +204,7 @@ transformers:
`) `)
writeDeployment(th, "/app/overlay/deployment.yaml") writeDeployment(th, "/app/overlay/deployment.yaml")
m, err := th.MakeKustTarget().MakeCustomizedResMap() m := th.Run("/app/overlay", th.MakeOptionsPluginsEnabled())
if err != nil {
t.Fatalf("Err: %v", err)
}
th.AssertActualEqualsExpected(m, ` th.AssertActualEqualsExpected(m, `
apiVersion: apps/v1 apiVersion: apps/v1
kind: Deployment kind: Deployment