mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-07-17 17:52:12 +00:00
Simplify plugin tests.
This commit is contained in:
@@ -28,13 +28,10 @@ import (
|
||||
// TODO: Download and inflate the chart, and check that
|
||||
// in for the test.
|
||||
func TestChartInflatorPlugin(t *testing.T) {
|
||||
tc := kusttest_test.NewPluginTestEnv(t).Set()
|
||||
defer tc.Reset()
|
||||
th := kusttest_test.MakeEnhancedHarness(t).
|
||||
PrepExecPlugin("someteam.example.com", "v1", "ChartInflator")
|
||||
defer th.Reset()
|
||||
|
||||
tc.PrepExecPlugin(
|
||||
"someteam.example.com", "v1", "ChartInflator")
|
||||
|
||||
th := kusttest_test.MakeHarness(t)
|
||||
th.WriteK("/app", `
|
||||
generators:
|
||||
- chartInflator.yaml
|
||||
|
||||
@@ -13,13 +13,10 @@ import (
|
||||
// This is a NamePrefixer that touches Deployments
|
||||
// and Services exclusively.
|
||||
func TestCustomNamePrefixer(t *testing.T) {
|
||||
tc := kusttest_test.NewPluginTestEnv(t).Set()
|
||||
defer tc.Reset()
|
||||
th := kusttest_test.MakeEnhancedHarness(t).
|
||||
PrepBuiltin("PrefixSuffixTransformer")
|
||||
defer th.Reset()
|
||||
|
||||
tc.BuildGoPlugin(
|
||||
"builtin", "", "PrefixSuffixTransformer")
|
||||
|
||||
th := kusttest_test.MakeHarness(t)
|
||||
th.WriteK("/app", `
|
||||
resources:
|
||||
- deployment.yaml
|
||||
|
||||
@@ -14,17 +14,11 @@ import (
|
||||
// in a base, allowing them to be reused in any number of
|
||||
// kustomizations.
|
||||
func TestReusableCustomTransformers(t *testing.T) {
|
||||
tc := kusttest_test.NewPluginTestEnv(t).Set()
|
||||
defer tc.Reset()
|
||||
|
||||
tc.BuildGoPlugin(
|
||||
"builtin", "", "PrefixSuffixTransformer")
|
||||
tc.BuildGoPlugin(
|
||||
"builtin", "", "AnnotationsTransformer")
|
||||
tc.BuildGoPlugin(
|
||||
"builtin", "", "LabelTransformer")
|
||||
|
||||
th := kusttest_test.MakeHarness(t)
|
||||
th := kusttest_test.MakeEnhancedHarness(t).
|
||||
PrepBuiltin("PrefixSuffixTransformer").
|
||||
PrepBuiltin("AnnotationsTransformer").
|
||||
PrepBuiltin("LabelTransformer")
|
||||
defer th.Reset()
|
||||
|
||||
// First write three custom configurations for builtin plugins.
|
||||
|
||||
|
||||
@@ -331,13 +331,10 @@ patchesStrategicMerge:
|
||||
}
|
||||
|
||||
func TestIssue1251_Plugins_ProdVsDev(t *testing.T) {
|
||||
tc := kusttest_test.NewPluginTestEnv(t).Set()
|
||||
defer tc.Reset()
|
||||
th := kusttest_test.MakeEnhancedHarness(t).
|
||||
PrepBuiltin("PatchJson6902Transformer")
|
||||
defer th.Reset()
|
||||
|
||||
tc.BuildGoPlugin(
|
||||
"builtin", "", "PatchJson6902Transformer")
|
||||
|
||||
th := kusttest_test.MakeHarness(t)
|
||||
defineTransformerDirStructure(th)
|
||||
th.WriteK("/app/prod", `
|
||||
resources:
|
||||
@@ -364,14 +361,11 @@ transformers:
|
||||
}
|
||||
|
||||
func TestIssue1251_Plugins_Local(t *testing.T) {
|
||||
tc := kusttest_test.NewPluginTestEnv(t).Set()
|
||||
defer tc.Reset()
|
||||
th := kusttest_test.MakeEnhancedHarness(t).
|
||||
PrepBuiltin("PatchJson6902Transformer")
|
||||
defer th.Reset()
|
||||
|
||||
tc.BuildGoPlugin(
|
||||
"builtin", "", "PatchJson6902Transformer")
|
||||
|
||||
th := kusttest_test.MakeHarness(t)
|
||||
writeDeploymentBase(th)
|
||||
writeDeploymentBase(th.Harness)
|
||||
|
||||
writeJsonTransformerPluginConfig(
|
||||
th, "/app/composite", "addDnsPolicy", patchJsonDnsPolicy)
|
||||
@@ -393,7 +387,7 @@ transformers:
|
||||
}
|
||||
|
||||
func writeJsonTransformerPluginConfig(
|
||||
th kusttest_test.Harness, path, name, patch string) {
|
||||
th *kusttest_test.HarnessEnhanced, path, name, patch string) {
|
||||
th.WriteF(filepath.Join(path, name+"Config.yaml"),
|
||||
fmt.Sprintf(`
|
||||
apiVersion: builtin
|
||||
@@ -411,14 +405,10 @@ jsonOp: '%s'
|
||||
|
||||
// Remote in the sense that they are bundled in a different kustomization.
|
||||
func TestIssue1251_Plugins_Bundled(t *testing.T) {
|
||||
tc := kusttest_test.NewPluginTestEnv(t).Set()
|
||||
defer tc.Reset()
|
||||
|
||||
tc.BuildGoPlugin(
|
||||
"builtin", "", "PatchJson6902Transformer")
|
||||
|
||||
th := kusttest_test.MakeHarness(t)
|
||||
writeDeploymentBase(th)
|
||||
th := kusttest_test.MakeEnhancedHarness(t).
|
||||
PrepBuiltin("PatchJson6902Transformer")
|
||||
defer th.Reset()
|
||||
writeDeploymentBase(th.Harness)
|
||||
|
||||
th.WriteK("/app/patches", `
|
||||
resources:
|
||||
@@ -443,8 +433,8 @@ transformers:
|
||||
th.AssertActualEqualsExpected(m, expectedPatchedDeployment)
|
||||
}
|
||||
|
||||
func defineTransformerDirStructure(th kusttest_test.Harness) {
|
||||
writeDeploymentBase(th)
|
||||
func defineTransformerDirStructure(th *kusttest_test.HarnessEnhanced) {
|
||||
writeDeploymentBase(th.Harness)
|
||||
|
||||
th.WriteK("/app/patches/addDnsPolicy", `
|
||||
resources:
|
||||
|
||||
@@ -18,11 +18,10 @@ import (
|
||||
// its working directory and some environment variables,
|
||||
// to add regression protection to plugin loading logic.
|
||||
func TestPluginEnvironment(t *testing.T) {
|
||||
tc := kusttest_test.NewPluginTestEnv(t).Set()
|
||||
defer tc.Reset()
|
||||
|
||||
tc.PrepExecPlugin(
|
||||
"someteam.example.com", "v1", "PrintPluginEnv")
|
||||
th := kusttest_test.MakeEnhancedHarness(t).
|
||||
PrepExecPlugin(
|
||||
"someteam.example.com", "v1", "PrintPluginEnv")
|
||||
defer th.Reset()
|
||||
|
||||
confirmBehavior(
|
||||
kusttest_test.MakeHarnessWithFs(t, filesys.MakeFsInMemory()),
|
||||
|
||||
@@ -90,7 +90,6 @@ resources:
|
||||
}
|
||||
|
||||
func TestBase(t *testing.T) {
|
||||
//th := kusttest_test.NewKustTestHarness(t, "/app/base")
|
||||
th := kusttest_test.MakeHarness(t)
|
||||
writeBase(th)
|
||||
m := th.Run("/app/base", th.MakeDefaultOptions())
|
||||
@@ -339,7 +338,6 @@ rules:
|
||||
|
||||
func TestMultibasesWithConflict(t *testing.T) {
|
||||
th := kusttest_test.MakeHarness(t)
|
||||
//th := kusttest_test.NewKustTestHarness(t, "/app/combined")
|
||||
writeBase(th)
|
||||
writeMidOverlays(th)
|
||||
writeTopOverlay(th)
|
||||
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
"sigs.k8s.io/kustomize/api/types"
|
||||
)
|
||||
|
||||
func writeDeployment(th kusttest_test.Harness, path string) {
|
||||
func writeDeployment(th *kusttest_test.HarnessEnhanced, path string) {
|
||||
th.WriteF(path, `
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
@@ -28,7 +28,7 @@ spec:
|
||||
`)
|
||||
}
|
||||
|
||||
func writeStringPrefixer(th kusttest_test.Harness, path, name string) {
|
||||
func writeStringPrefixer(th *kusttest_test.HarnessEnhanced, path, name string) {
|
||||
th.WriteF(path, `
|
||||
apiVersion: someteam.example.com/v1
|
||||
kind: StringPrefixer
|
||||
@@ -37,7 +37,7 @@ metadata:
|
||||
`)
|
||||
}
|
||||
|
||||
func writeDatePrefixer(th kusttest_test.Harness, path, name string) {
|
||||
func writeDatePrefixer(th *kusttest_test.HarnessEnhanced, path, name string) {
|
||||
th.WriteF(path, `
|
||||
apiVersion: someteam.example.com/v1
|
||||
kind: DatePrefixer
|
||||
@@ -47,15 +47,11 @@ metadata:
|
||||
}
|
||||
|
||||
func TestOrderedTransformers(t *testing.T) {
|
||||
tc := kusttest_test.NewPluginTestEnv(t).Set()
|
||||
defer tc.Reset()
|
||||
th := kusttest_test.MakeEnhancedHarness(t).
|
||||
BuildGoPlugin("someteam.example.com", "v1", "StringPrefixer").
|
||||
BuildGoPlugin("someteam.example.com", "v1", "DatePrefixer")
|
||||
defer th.Reset()
|
||||
|
||||
tc.BuildGoPlugin(
|
||||
"someteam.example.com", "v1", "StringPrefixer")
|
||||
|
||||
tc.BuildGoPlugin(
|
||||
"someteam.example.com", "v1", "DatePrefixer")
|
||||
th := kusttest_test.MakeHarness(t)
|
||||
th.WriteK("/app", `
|
||||
resources:
|
||||
- deployment.yaml
|
||||
@@ -89,13 +85,10 @@ spec:
|
||||
}
|
||||
|
||||
func TestPluginsNotEnabled(t *testing.T) {
|
||||
tc := kusttest_test.NewPluginTestEnv(t).Set()
|
||||
defer tc.Reset()
|
||||
th := kusttest_test.MakeEnhancedHarness(t).
|
||||
BuildGoPlugin("someteam.example.com", "v1", "StringPrefixer")
|
||||
defer th.Reset()
|
||||
|
||||
tc.BuildGoPlugin(
|
||||
"someteam.example.com", "v1", "StringPrefixer")
|
||||
|
||||
th := kusttest_test.MakeHarness(t)
|
||||
th.WriteK("/app", `
|
||||
transformers:
|
||||
- stringPrefixer.yaml
|
||||
@@ -111,13 +104,10 @@ transformers:
|
||||
}
|
||||
|
||||
func TestSedTransformer(t *testing.T) {
|
||||
tc := kusttest_test.NewPluginTestEnv(t).Set()
|
||||
defer tc.Reset()
|
||||
th := kusttest_test.MakeEnhancedHarness(t).
|
||||
PrepExecPlugin("someteam.example.com", "v1", "SedTransformer")
|
||||
defer th.Reset()
|
||||
|
||||
tc.PrepExecPlugin(
|
||||
"someteam.example.com", "v1", "SedTransformer")
|
||||
|
||||
th := kusttest_test.MakeHarness(t)
|
||||
th.WriteK("/app", `
|
||||
resources:
|
||||
- configmap.yaml
|
||||
@@ -176,16 +166,10 @@ metadata:
|
||||
}
|
||||
|
||||
func TestTransformedTransformers(t *testing.T) {
|
||||
tc := kusttest_test.NewPluginTestEnv(t).Set()
|
||||
defer tc.Reset()
|
||||
|
||||
tc.BuildGoPlugin(
|
||||
"someteam.example.com", "v1", "StringPrefixer")
|
||||
|
||||
tc.BuildGoPlugin(
|
||||
"someteam.example.com", "v1", "DatePrefixer")
|
||||
|
||||
th := kusttest_test.MakeHarness(t)
|
||||
th := kusttest_test.MakeEnhancedHarness(t).
|
||||
BuildGoPlugin("someteam.example.com", "v1", "StringPrefixer").
|
||||
BuildGoPlugin("someteam.example.com", "v1", "DatePrefixer")
|
||||
defer th.Reset()
|
||||
|
||||
th.WriteK("/app/base", `
|
||||
resources:
|
||||
|
||||
Reference in New Issue
Block a user