From 382c330f5b7e135ad73f00e19b8d7017ca0a63e3 Mon Sep 17 00:00:00 2001 From: Jeffrey Regan Date: Mon, 2 Dec 2019 09:28:50 -0800 Subject: [PATCH] Consolidate test harness to one package. --- api/internal/loadertest/fakeloader.go | 8 +- api/internal/target/kusttarget_test.go | 18 +- api/internal/target/maker_test.go | 48 ++++ api/internal/target/vars_test.go | 16 +- api/krusty/accumulation_test.go | 12 +- api/krusty/baseandoverlaymedium_test.go | 8 +- api/krusty/baseandoverlaysmall_test.go | 17 +- api/krusty/basereusenameprefix_test.go | 4 +- api/krusty/chartinflatorplugin_test.go | 4 +- api/krusty/complexcomposition_test.go | 45 +-- api/krusty/configmaps_test.go | 10 +- api/krusty/crd_test.go | 10 +- api/krusty/customconfig_test.go | 10 +- .../customconfigofbuiltinplugin_test.go | 2 +- api/krusty/customconfigreusable_test.go | 2 +- api/krusty/diamondcomposition_test.go | 32 +-- api/krusty/diamonds_test.go | 14 +- api/krusty/directoryarrangement_test.go | 4 +- api/krusty/disablenamesuffix_test.go | 3 +- api/krusty/extendedpatch_test.go | 26 +- api/krusty/generatormergeandreplace_test.go | 16 +- api/krusty/generatoroptions_test.go | 6 +- api/krusty/inlinepatch_test.go | 12 +- api/krusty/multiplepatch_test.go | 12 +- api/krusty/namespacedgenerators_test.go | 6 +- api/krusty/namespaces_test.go | 12 +- api/krusty/nullvalues_test.go | 4 +- api/krusty/pluginenv_test.go | 6 +- api/krusty/pruneconfigmap_test.go | 4 +- api/krusty/resourceconflict_test.go | 18 +- api/krusty/testingharness_test.go | 202 ------------- api/krusty/transformerplugin_test.go | 14 +- api/krusty/transformersarrays_test.go | 6 +- api/krusty/transformersimage_test.go | 16 +- api/krusty/variableref_test.go | 20 +- api/testutils/kusttest/harness.go | 126 +++++++++ api/testutils/kusttest/harnessenhanced.go | 104 +++++++ api/testutils/kusttest/hasgett.go | 104 +++++++ api/testutils/kusttest/kusttestharness.go | 267 ------------------ hack/imports.sh | 2 +- .../AnnotationsTransformer_test.go | 2 +- .../ConfigMapGenerator_test.go | 2 +- .../hashtransformer/HashTransformer_test.go | 2 +- .../ImageTagTransformer_test.go | 12 +- .../InventoryTransformer_test.go | 6 +- .../labeltransformer/LabelTransformer_test.go | 2 +- .../LegacyOrderTransformer_test.go | 2 +- .../NamespaceTransformer_test.go | 6 +- .../PatchJson6902Transformer_test.go | 16 +- .../PatchStrategicMergeTransformer_test.go | 34 +-- .../patchtransformer/PatchTransformer_test.go | 14 +- .../PrefixSuffixTransformer_test.go | 2 +- .../ReplicaCountTransformer_test.go | 6 +- .../secretgenerator/SecretGenerator_test.go | 2 +- .../bashedconfigmap/BashedConfigMap_test.go | 2 +- .../v1/chartinflator/ChartInflator_test.go | 2 +- .../v1/dateprefixer/DatePrefixer_test.go | 2 +- .../v1/gogetter/GoGetter_test.go | 8 +- .../v1/printpluginenv/PrintPluginEnv_test.go | 2 +- .../SecretsFromDatabase_test.go | 2 +- .../v1/sedtransformer/SedTransformer_test.go | 2 +- .../SomeServiceGenerator_test.go | 2 +- .../v1/stringprefixer/StringPrefixer_test.go | 2 +- .../v1/validator/validator_test.go | 4 +- 64 files changed, 676 insertions(+), 710 deletions(-) create mode 100644 api/internal/target/maker_test.go delete mode 100644 api/krusty/testingharness_test.go create mode 100644 api/testutils/kusttest/harness.go create mode 100644 api/testutils/kusttest/harnessenhanced.go create mode 100644 api/testutils/kusttest/hasgett.go delete mode 100644 api/testutils/kusttest/kusttestharness.go diff --git a/api/internal/loadertest/fakeloader.go b/api/internal/loadertest/fakeloader.go index d11d26a5d..0d3880b94 100644 --- a/api/internal/loadertest/fakeloader.go +++ b/api/internal/loadertest/fakeloader.go @@ -23,16 +23,16 @@ type FakeLoader struct { // The initialDir argument should be an absolute file path. func NewFakeLoader(initialDir string) FakeLoader { return NewFakeLoaderWithRestrictor( - loader.RestrictionRootOnly, initialDir) + loader.RestrictionRootOnly, filesys.MakeFsInMemory(), initialDir) } // NewFakeLoaderWithRestrictor returns a Loader that // uses a fake filesystem. // The initialDir argument should be an absolute file path. func NewFakeLoaderWithRestrictor( - lr loader.LoadRestrictorFunc, initialDir string) FakeLoader { - // Create fake filesystem and inject it into initial Loader. - fSys := filesys.MakeFsInMemory() + lr loader.LoadRestrictorFunc, + fSys filesys.FileSystem, + initialDir string) FakeLoader { fSys.Mkdir(initialDir) ldr, err := loader.NewLoader(lr, initialDir, fSys) if err != nil { diff --git a/api/internal/target/kusttarget_test.go b/api/internal/target/kusttarget_test.go index 659a3c926..8e7060248 100644 --- a/api/internal/target/kusttarget_test.go +++ b/api/internal/target/kusttarget_test.go @@ -7,7 +7,9 @@ import ( "encoding/base64" "testing" + "sigs.k8s.io/kustomize/api/filesys" "sigs.k8s.io/kustomize/api/ifc" + "sigs.k8s.io/kustomize/api/k8sdeps/kunstruct" "sigs.k8s.io/kustomize/api/resmap" "sigs.k8s.io/kustomize/api/resource" kusttest_test "sigs.k8s.io/kustomize/api/testutils/kusttest" @@ -17,7 +19,8 @@ import ( // high level tests. func TestMakeCustomizedResMap(t *testing.T) { - th := kusttest_test.NewKustTestHarness(t, "/whatever") + fSys := filesys.MakeFsInMemory() + th := kusttest_test.MakeHarnessWithFs(t, fSys) th.WriteK("/whatever", ` apiVersion: kustomize.config.k8s.io/v1beta1 kind: Kustomization @@ -68,8 +71,10 @@ metadata: {"op": "add", "path": "/spec/replica", "value": "3"} ]`) + resFactory := resource.NewFactory(kunstruct.NewKunstructuredFactoryImpl()) + resources := []*resource.Resource{ - th.RF().FromMapWithName("dply1", map[string]interface{}{ + resFactory.FromMapWithName("dply1", map[string]interface{}{ "apiVersion": "apps/v1", "kind": "Deployment", "metadata": map[string]interface{}{ @@ -101,7 +106,7 @@ metadata: }, }, }), - th.RF().FromMapWithName("ns1", map[string]interface{}{ + resFactory.FromMapWithName("ns1", map[string]interface{}{ "apiVersion": "v1", "kind": "Namespace", "metadata": map[string]interface{}{ @@ -114,7 +119,7 @@ metadata: }, }, }), - th.RF().FromMapWithName("literalConfigMap", + resFactory.FromMapWithName("literalConfigMap", map[string]interface{}{ "apiVersion": "v1", "kind": "ConfigMap", @@ -133,7 +138,7 @@ metadata: "DB_PASSWORD": "somepw", }, }), - th.RF().FromMapWithName("secret", + resFactory.FromMapWithName("secret", map[string]interface{}{ "apiVersion": "v1", "kind": "Secret", @@ -162,7 +167,8 @@ metadata: } } - actual, err := th.MakeKustTarget().MakeCustomizedResMap() + actual, err := makeKustTargetWithRf( + t, fSys, "/whatever", resFactory).MakeCustomizedResMap() if err != nil { t.Fatalf("unexpected Resources error %v", err) } diff --git a/api/internal/target/maker_test.go b/api/internal/target/maker_test.go new file mode 100644 index 000000000..1f53eed39 --- /dev/null +++ b/api/internal/target/maker_test.go @@ -0,0 +1,48 @@ +// Copyright 2019 The Kubernetes Authors. +// SPDX-License-Identifier: Apache-2.0 + +package target_test + +import ( + "testing" + + "sigs.k8s.io/kustomize/api/filesys" + "sigs.k8s.io/kustomize/api/internal/k8sdeps/transformer" + "sigs.k8s.io/kustomize/api/internal/loadertest" + pLdr "sigs.k8s.io/kustomize/api/internal/plugins/loader" + "sigs.k8s.io/kustomize/api/internal/target" + "sigs.k8s.io/kustomize/api/k8sdeps/kunstruct" + "sigs.k8s.io/kustomize/api/konfig" + "sigs.k8s.io/kustomize/api/loader" + "sigs.k8s.io/kustomize/api/resmap" + "sigs.k8s.io/kustomize/api/resource" + valtest_test "sigs.k8s.io/kustomize/api/testutils/valtest" +) + +func makeKustTarget( + t *testing.T, + fSys filesys.FileSystem, path string) *target.KustTarget { + return makeKustTargetWithRf( + t, fSys, path, + resource.NewFactory(kunstruct.NewKunstructuredFactoryImpl())) +} + +func makeKustTargetWithRf( + t *testing.T, + fSys filesys.FileSystem, path string, + resFact *resource.Factory) *target.KustTarget { + rf := resmap.NewFactory(resFact, transformer.NewFactoryImpl()) + pc := konfig.DisabledPluginConfig() + kt := target.NewKustTarget( + loadertest.NewFakeLoaderWithRestrictor( + loader.RestrictionRootOnly, fSys, path), + valtest_test.MakeFakeValidator(), + rf, + transformer.NewFactoryImpl(), + pLdr.NewLoader(pc, rf)) + err := kt.Load() + if err != nil { + t.Fatalf("Unexpected construction error %v", err) + } + return kt +} diff --git a/api/internal/target/vars_test.go b/api/internal/target/vars_test.go index 7330bed31..758a64e73 100644 --- a/api/internal/target/vars_test.go +++ b/api/internal/target/vars_test.go @@ -48,7 +48,7 @@ var someVars = []types.Var{ } func TestGetAllVarsSimple(t *testing.T) { - th := kusttest_test.NewKustTestHarness(t, "/app") + th := kusttest_test.MakeHarness(t) th.WriteK("/app", ` vars: - name: AWARD @@ -64,7 +64,8 @@ vars: name: heron apiVersion: v300 `) - ra, err := th.MakeKustTarget().AccumulateTarget() + ra, err := makeKustTarget( + t, th.GetFSys(), "/app").AccumulateTarget() if err != nil { t.Fatalf("Err: %v", err) } @@ -83,7 +84,7 @@ vars: } func TestGetAllVarsNested(t *testing.T) { - th := kusttest_test.NewKustTestHarness(t, "/app/overlays/o2") + th := kusttest_test.MakeHarness(t) th.WriteK("/app/base", ` vars: - name: AWARD @@ -117,7 +118,9 @@ vars: resources: - ../o1 `) - ra, err := th.MakeKustTarget().AccumulateTarget() + + ra, err := makeKustTarget( + t, th.GetFSys(), "/app/overlays/o2").AccumulateTarget() if err != nil { t.Fatalf("Err: %v", err) } @@ -139,7 +142,7 @@ resources: } func TestVarCollisionsForbidden(t *testing.T) { - th := kusttest_test.NewKustTestHarness(t, "/app/overlays/o2") + th := kusttest_test.MakeHarness(t) th.WriteK("/app/base", ` vars: - name: AWARD @@ -173,7 +176,8 @@ vars: resources: - ../o1 `) - _, err := th.MakeKustTarget().AccumulateTarget() + _, err := makeKustTarget( + t, th.GetFSys(), "/app/overlays/o2").AccumulateTarget() if err == nil { t.Fatalf("expected var collision") } diff --git a/api/krusty/accumulation_test.go b/api/krusty/accumulation_test.go index 3cc9116db..e0df84456 100644 --- a/api/krusty/accumulation_test.go +++ b/api/krusty/accumulation_test.go @@ -8,13 +8,13 @@ import ( "strings" "testing" - "sigs.k8s.io/kustomize/api/konfig" - . "sigs.k8s.io/kustomize/api/internal/target" + "sigs.k8s.io/kustomize/api/konfig" + kusttest_test "sigs.k8s.io/kustomize/api/testutils/kusttest" ) func TestTargetMustHaveKustomizationFile(t *testing.T) { - th := makeTestHarness(t) + th := kusttest_test.MakeHarness(t) th.WriteF("/app/service.yaml", ` apiVersion: v1 kind: Service @@ -37,7 +37,7 @@ metadata: } func TestTargetMustHaveOnlyOneKustomizationFile(t *testing.T) { - th := makeTestHarness(t) + th := kusttest_test.MakeHarness(t) for _, n := range konfig.RecognizedKustomizationFileNames() { th.WriteF(filepath.Join("/app", n), ` apiVersion: kustomize.config.k8s.io/v1beta1 @@ -54,7 +54,7 @@ kind: Kustomization } func TestBaseMustHaveKustomizationFile(t *testing.T) { - th := makeTestHarness(t) + th := kusttest_test.MakeHarness(t) th.WriteK("/app", ` resources: - base @@ -80,7 +80,7 @@ spec: } func TestResourceNotFound(t *testing.T) { - th := makeTestHarness(t) + th := kusttest_test.MakeHarness(t) th.WriteK("/app", ` resources: - deployment.yaml diff --git a/api/krusty/baseandoverlaymedium_test.go b/api/krusty/baseandoverlaymedium_test.go index 284f14634..19bd3d8da 100644 --- a/api/krusty/baseandoverlaymedium_test.go +++ b/api/krusty/baseandoverlaymedium_test.go @@ -5,9 +5,11 @@ package krusty_test import ( "testing" + + kusttest_test "sigs.k8s.io/kustomize/api/testutils/kusttest" ) -func writeMediumBase(th testingHarness) { +func writeMediumBase(th kusttest_test.Harness) { th.WriteK("/app/base", ` namePrefix: baseprefix- commonLabels: @@ -57,7 +59,7 @@ spec: } func TestMediumBase(t *testing.T) { - th := makeTestHarness(t) + th := kusttest_test.MakeHarness(t) writeMediumBase(th) m := th.Run("/app/base", th.MakeDefaultOptions()) th.AssertActualEqualsExpected(m, ` @@ -111,7 +113,7 @@ spec: } func TestMediumOverlay(t *testing.T) { - th := makeTestHarness(t) + th := kusttest_test.MakeHarness(t) writeMediumBase(th) th.WriteK("/app/overlay", ` namePrefix: test-infra- diff --git a/api/krusty/baseandoverlaysmall_test.go b/api/krusty/baseandoverlaysmall_test.go index 4e8c45456..6ddf93379 100644 --- a/api/krusty/baseandoverlaysmall_test.go +++ b/api/krusty/baseandoverlaysmall_test.go @@ -8,11 +8,12 @@ import ( "testing" . "sigs.k8s.io/kustomize/api/krusty" + kusttest_test "sigs.k8s.io/kustomize/api/testutils/kusttest" "sigs.k8s.io/kustomize/api/types" ) func TestOrderPreserved(t *testing.T) { - th := makeTestHarness(t) + th := kusttest_test.MakeHarness(t) th.WriteK("/app/base", ` namePrefix: b- resources: @@ -99,7 +100,7 @@ metadata: } func TestBaseInResourceList(t *testing.T) { - th := makeTestHarness(t) + th := kusttest_test.MakeHarness(t) th.WriteK("/app/prod", ` namePrefix: b- resources: @@ -131,7 +132,7 @@ spec: `) } -func writeSmallBase(th testingHarness) { +func writeSmallBase(th kusttest_test.Harness) { th.WriteK("/app/base", ` namePrefix: a- commonLabels: @@ -169,7 +170,7 @@ spec: } func TestSmallBase(t *testing.T) { - th := makeTestHarness(t) + th := kusttest_test.MakeHarness(t) writeSmallBase(th) m := th.Run("/app/base", th.MakeDefaultOptions()) th.AssertActualEqualsExpected(m, ` @@ -209,7 +210,7 @@ spec: } func TestSmallOverlay(t *testing.T) { - th := makeTestHarness(t) + th := kusttest_test.MakeHarness(t) writeSmallBase(th) th.WriteK("/app/overlay", ` namePrefix: b- @@ -284,7 +285,7 @@ spec: } func TestSharedPatchDisAllowed(t *testing.T) { - th := makeTestHarness(t) + th := kusttest_test.MakeHarness(t) writeSmallBase(th) th.WriteK("/app/overlay", ` commonLabels: @@ -315,7 +316,7 @@ spec: } func TestSharedPatchAllowed(t *testing.T) { - th := makeTestHarness(t) + th := kusttest_test.MakeHarness(t) writeSmallBase(th) th.WriteK("/app/overlay", ` commonLabels: @@ -381,7 +382,7 @@ spec: } func TestSmallOverlayJSONPatch(t *testing.T) { - th := makeTestHarness(t) + th := kusttest_test.MakeHarness(t) writeSmallBase(th) th.WriteK("/app/overlay", ` resources: diff --git a/api/krusty/basereusenameprefix_test.go b/api/krusty/basereusenameprefix_test.go index 6327e10e6..19f0bfcf4 100644 --- a/api/krusty/basereusenameprefix_test.go +++ b/api/krusty/basereusenameprefix_test.go @@ -5,6 +5,8 @@ package krusty_test import ( "testing" + + kusttest_test "sigs.k8s.io/kustomize/api/testutils/kusttest" ) // Here is a structure of a kustomization of two components, component1 @@ -38,7 +40,7 @@ import ( // ├── kustomization.yaml func TestBaseReuseNameConflict(t *testing.T) { - th := makeTestHarness(t) + th := kusttest_test.MakeHarness(t) th.WriteK("/app/component1/base", ` resources: - ../../shared diff --git a/api/krusty/chartinflatorplugin_test.go b/api/krusty/chartinflatorplugin_test.go index 558ddb618..3f1635395 100644 --- a/api/krusty/chartinflatorplugin_test.go +++ b/api/krusty/chartinflatorplugin_test.go @@ -11,7 +11,7 @@ import ( "regexp" "testing" - "sigs.k8s.io/kustomize/api/testutils/kusttest" + kusttest_test "sigs.k8s.io/kustomize/api/testutils/kusttest" ) // This is an example of using a helm chart as a base, @@ -34,7 +34,7 @@ func TestChartInflatorPlugin(t *testing.T) { tc.PrepExecPlugin( "someteam.example.com", "v1", "ChartInflator") - th := makeTestHarness(t) + th := kusttest_test.MakeHarness(t) th.WriteK("/app", ` generators: - chartInflator.yaml diff --git a/api/krusty/complexcomposition_test.go b/api/krusty/complexcomposition_test.go index e36c2686b..d680be96c 100644 --- a/api/krusty/complexcomposition_test.go +++ b/api/krusty/complexcomposition_test.go @@ -8,6 +8,7 @@ import ( "testing" . "sigs.k8s.io/kustomize/api/krusty" + kusttest_test "sigs.k8s.io/kustomize/api/testutils/kusttest" "sigs.k8s.io/kustomize/api/types" ) @@ -25,7 +26,7 @@ spec: app: my-app ` -func writeStatefulSetBase(th testingHarness) { +func writeStatefulSetBase(th kusttest_test.Harness) { th.WriteK("/app/base", ` resources: - statefulset.yaml @@ -54,7 +55,7 @@ spec: `) } -func writeHTTPSOverlay(th testingHarness) { +func writeHTTPSOverlay(th kusttest_test.Harness) { th.WriteK("/app/https", ` resources: - ../base @@ -73,7 +74,7 @@ spec: `) } -func writeHTTPSTransformerRaw(th testingHarness) { +func writeHTTPSTransformerRaw(th kusttest_test.Harness) { th.WriteF("/app/https/service/https-svc.yaml", httpsService) th.WriteF("/app/https/transformer/transformer.yaml", ` apiVersion: builtin @@ -95,7 +96,7 @@ patch: |- `) } -func writeHTTPSTransformerBase(th testingHarness) { +func writeHTTPSTransformerBase(th kusttest_test.Harness) { th.WriteK("/app/https/service", ` resources: - https-svc.yaml @@ -107,7 +108,7 @@ resources: writeHTTPSTransformerRaw(th) } -func writeConfigFromEnvOverlay(th testingHarness) { +func writeConfigFromEnvOverlay(th kusttest_test.Harness) { th.WriteK("/app/config", ` resources: - ../base @@ -136,7 +137,7 @@ spec: `) } -func writeConfigFromEnvTransformerRaw(th testingHarness) { +func writeConfigFromEnvTransformerRaw(th kusttest_test.Harness) { th.WriteF("/app/config/map/generator.yaml", ` apiVersion: builtin kind: ConfigMapGenerator @@ -171,7 +172,7 @@ patch: |- name: my-config `) } -func writeConfigFromEnvTransformerBase(th testingHarness) { +func writeConfigFromEnvTransformerBase(th kusttest_test.Harness) { th.WriteK("/app/config/map", ` resources: - generator.yaml @@ -183,7 +184,7 @@ resources: writeConfigFromEnvTransformerRaw(th) } -func writeTolerationsOverlay(th testingHarness) { +func writeTolerationsOverlay(th kusttest_test.Harness) { th.WriteK("/app/tolerations", ` resources: - ../base @@ -205,7 +206,7 @@ spec: `) } -func writeTolerationsTransformerRaw(th testingHarness) { +func writeTolerationsTransformerRaw(th kusttest_test.Harness) { th.WriteF("/app/tolerations/transformer.yaml", ` apiVersion: builtin kind: PatchTransformer @@ -231,7 +232,7 @@ patch: |- `) } -func writeTolerationsTransformerBase(th testingHarness) { +func writeTolerationsTransformerBase(th kusttest_test.Harness) { th.WriteK("/app/tolerations", ` resources: - transformer.yaml @@ -239,7 +240,7 @@ resources: writeTolerationsTransformerRaw(th) } -func writeStorageOverlay(th testingHarness) { +func writeStorageOverlay(th kusttest_test.Harness) { th.WriteK("/app/storage", ` resources: - ../base @@ -256,7 +257,7 @@ patchesJson6902: `) } -func writeStorageTransformerRaw(th testingHarness) { +func writeStorageTransformerRaw(th kusttest_test.Harness) { th.WriteF("/app/storage/transformer.yaml", ` apiVersion: builtin kind: PatchTransformer @@ -272,7 +273,7 @@ patch: |- `) } -func writeStorageTransformerBase(th testingHarness) { +func writeStorageTransformerBase(th kusttest_test.Harness) { th.WriteK("/app/storage", ` resources: - transformer.yaml @@ -280,14 +281,14 @@ resources: writeStorageTransformerRaw(th) } -func writePatchingOverlays(th testingHarness) { +func writePatchingOverlays(th kusttest_test.Harness) { writeStorageOverlay(th) writeConfigFromEnvOverlay(th) writeTolerationsOverlay(th) writeHTTPSOverlay(th) } -func writePatchingTransformersRaw(th testingHarness) { +func writePatchingTransformersRaw(th kusttest_test.Harness) { writeStorageTransformerRaw(th) writeConfigFromEnvTransformerRaw(th) writeTolerationsTransformerRaw(th) @@ -310,7 +311,7 @@ func writePatchingTransformersRaw(th testingHarness) { // must be self-contained, i.e. the config may not have fields that // refer to local files, since those files won't be present when // the plugin is instantiated and used. -func writePatchingTransformerBases(th testingHarness) { +func writePatchingTransformerBases(th kusttest_test.Harness) { writeStorageTransformerBase(th) writeConfigFromEnvTransformerBase(th) writeTolerationsTransformerBase(th) @@ -353,7 +354,7 @@ func writePatchingTransformerBases(th testingHarness) { // - prod: Combines the config, tolerations and https intermediate overlays. func TestComplexComposition_Dev_Failure(t *testing.T) { - th := makeTestHarness(t) + th := kusttest_test.MakeHarness(t) writeStatefulSetBase(th) writePatchingOverlays(th) th.WriteK("/app/dev", ` @@ -405,7 +406,7 @@ metadata: ` func TestComplexComposition_Dev_SuccessWithRawTransformers(t *testing.T) { - th := makeTestHarness(t) + th := kusttest_test.MakeHarness(t) writeStatefulSetBase(th) writePatchingTransformersRaw(th) th.WriteK("/app/dev", ` @@ -426,7 +427,7 @@ transformers: } func TestComplexComposition_Dev_SuccessWithBaseTransformers(t *testing.T) { - th := makeTestHarness(t) + th := kusttest_test.MakeHarness(t) writeStatefulSetBase(th) writePatchingTransformerBases(th) th.WriteK("/app/dev", ` @@ -443,7 +444,7 @@ transformers: } func TestComplexComposition_Prod_Failure(t *testing.T) { - th := makeTestHarness(t) + th := kusttest_test.MakeHarness(t) writeStatefulSetBase(th) writePatchingOverlays(th) th.WriteK("/app/prod", ` @@ -512,7 +513,7 @@ metadata: ` func TestComplexComposition_Prod_SuccessWithRawTransformers(t *testing.T) { - th := makeTestHarness(t) + th := kusttest_test.MakeHarness(t) writeStatefulSetBase(th) writePatchingTransformersRaw(th) th.WriteK("/app/prod", ` @@ -535,7 +536,7 @@ transformers: } func TestComplexComposition_Prod_SuccessWithBaseTransformers(t *testing.T) { - th := makeTestHarness(t) + th := kusttest_test.MakeHarness(t) writeStatefulSetBase(th) writePatchingTransformerBases(th) th.WriteK("/app/prod", ` diff --git a/api/krusty/configmaps_test.go b/api/krusty/configmaps_test.go index 924e47923..91874c3eb 100644 --- a/api/krusty/configmaps_test.go +++ b/api/krusty/configmaps_test.go @@ -5,12 +5,14 @@ package krusty_test import ( "testing" + + kusttest_test "sigs.k8s.io/kustomize/api/testutils/kusttest" ) // Generate a Secret and a ConfigMap from the same data // to compare the result. func TestGeneratorBasics(t *testing.T) { - th := makeTestHarness(t) + th := kusttest_test.MakeHarness(t) th.WriteK("/app", ` namePrefix: blah- configMapGenerator: @@ -107,7 +109,7 @@ type: Opaque // TODO: These should be errors instead. func TestGeneratorRepeatsInKustomization(t *testing.T) { - th := makeTestHarness(t) + th := kusttest_test.MakeHarness(t) th.WriteK("/app", ` namePrefix: blah- configMapGenerator: @@ -159,7 +161,7 @@ metadata: } func TestGeneratorOverlays(t *testing.T) { - th := makeTestHarness(t) + th := kusttest_test.MakeHarness(t) th.WriteK("/app/base1", ` namePrefix: p1- configMapGenerator: @@ -231,7 +233,7 @@ metadata: func TestConfigMapGeneratorMergeNamePrefix(t *testing.T) { - th := makeTestHarness(t) + th := kusttest_test.MakeHarness(t) th.WriteK("/app/base", ` configMapGenerator: - name: cm diff --git a/api/krusty/crd_test.go b/api/krusty/crd_test.go index 4204d66f1..29e3daa15 100644 --- a/api/krusty/crd_test.go +++ b/api/krusty/crd_test.go @@ -5,9 +5,11 @@ package krusty_test import ( "testing" + + kusttest_test "sigs.k8s.io/kustomize/api/testutils/kusttest" ) -func writeBaseWithCrd(th testingHarness) { +func writeBaseWithCrd(th kusttest_test.Harness) { th.WriteK("/app/base", ` apiVersion: kustomize.config.k8s.io/v1beta1 kind: Kustomization @@ -223,7 +225,7 @@ data: } func TestCrdBase(t *testing.T) { - th := makeTestHarness(t) + th := kusttest_test.MakeHarness(t) writeBaseWithCrd(th) m := th.Run("/app/base", th.MakeDefaultOptions()) th.AssertActualEqualsExpected(m, ` @@ -254,7 +256,7 @@ spec: } func TestCrdWithOverlay(t *testing.T) { - th := makeTestHarness(t) + th := kusttest_test.MakeHarness(t) writeBaseWithCrd(th) th.WriteK("/app/overlay", ` apiVersion: kustomize.config.k8s.io/v1beta1 @@ -303,7 +305,7 @@ spec: } func TestCrdWithContainers(t *testing.T) { - th := makeTestHarness(t) + th := kusttest_test.MakeHarness(t) th.WriteK("/app/crd/containers", ` apiVersion: kustomize.config.k8s.io/v1beta1 kind: Kustomization diff --git a/api/krusty/customconfig_test.go b/api/krusty/customconfig_test.go index bba81d5ac..e7946f432 100644 --- a/api/krusty/customconfig_test.go +++ b/api/krusty/customconfig_test.go @@ -5,9 +5,11 @@ package krusty_test import ( "testing" + + kusttest_test "sigs.k8s.io/kustomize/api/testutils/kusttest" ) -func makeBaseReferencingCustomConfig(th testingHarness) { +func makeBaseReferencingCustomConfig(th kusttest_test.Harness) { th.WriteK("/app/base", ` namePrefix: x- commonLabels: @@ -72,7 +74,7 @@ spec: } func TestCustomConfig(t *testing.T) { - th := makeTestHarness(t) + th := kusttest_test.MakeHarness(t) makeBaseReferencingCustomConfig(th) th.WriteLegacyConfigs("/app/base/config/defaults.yaml") th.WriteF("/app/base/config/custom.yaml", ` @@ -135,7 +137,7 @@ spec: } func TestCustomConfigWithDefaultOverspecification(t *testing.T) { - th := makeTestHarness(t) + th := kusttest_test.MakeHarness(t) makeBaseReferencingCustomConfig(th) th.WriteLegacyConfigs("/app/base/config/defaults.yaml") // Specifying namePrefix here conflicts with (is the same as) @@ -203,7 +205,7 @@ spec: } func TestFixedBug605_BaseCustomizationAvailableInOverlay(t *testing.T) { - th := makeTestHarness(t) + th := kusttest_test.MakeHarness(t) makeBaseReferencingCustomConfig(th) th.WriteLegacyConfigs("/app/base/config/defaults.yaml") th.WriteF("/app/base/config/custom.yaml", ` diff --git a/api/krusty/customconfigofbuiltinplugin_test.go b/api/krusty/customconfigofbuiltinplugin_test.go index 416e67176..58423a04e 100644 --- a/api/krusty/customconfigofbuiltinplugin_test.go +++ b/api/krusty/customconfigofbuiltinplugin_test.go @@ -19,7 +19,7 @@ func TestCustomNamePrefixer(t *testing.T) { tc.BuildGoPlugin( "builtin", "", "PrefixSuffixTransformer") - th := makeTestHarness(t) + th := kusttest_test.MakeHarness(t) th.WriteK("/app", ` resources: - deployment.yaml diff --git a/api/krusty/customconfigreusable_test.go b/api/krusty/customconfigreusable_test.go index 7f0e5b2aa..1569deb59 100644 --- a/api/krusty/customconfigreusable_test.go +++ b/api/krusty/customconfigreusable_test.go @@ -24,7 +24,7 @@ func TestReusableCustomTransformers(t *testing.T) { tc.BuildGoPlugin( "builtin", "", "LabelTransformer") - th := makeTestHarness(t) + th := kusttest_test.MakeHarness(t) // First write three custom configurations for builtin plugins. diff --git a/api/krusty/diamondcomposition_test.go b/api/krusty/diamondcomposition_test.go index a9d1f56e3..9cf5d40aa 100644 --- a/api/krusty/diamondcomposition_test.go +++ b/api/krusty/diamondcomposition_test.go @@ -58,7 +58,7 @@ spec: ` const patchJsonRestartPolicy = `[{"op": "add", "path": "/spec/template/spec/restartPolicy", "value": "Always"}]` -func writeDeploymentBase(th testingHarness) { +func writeDeploymentBase(th kusttest_test.Harness) { th.WriteK("/app/base", ` resources: - deployment.yaml @@ -79,7 +79,7 @@ spec: `) } -func writeProbeOverlay(th testingHarness) { +func writeProbeOverlay(th kusttest_test.Harness) { th.WriteK("/app/probe", ` resources: - ../base @@ -89,7 +89,7 @@ patchesStrategicMerge: th.WriteF("/app/probe/dep-patch.yaml", patchAddProbe) } -func writeDNSOverlay(th testingHarness) { +func writeDNSOverlay(th kusttest_test.Harness) { th.WriteK("/app/dns", ` resources: - ../base @@ -99,7 +99,7 @@ patchesStrategicMerge: th.WriteF("/app/dns/dep-patch.yaml", patchDnsPolicy) } -func writeRestartOverlay(th testingHarness) { +func writeRestartOverlay(th kusttest_test.Harness) { th.WriteK("/app/restart", ` resources: - ../base @@ -123,7 +123,7 @@ patchesStrategicMerge: // base // func TestIssue1251_CompositeDiamond_Failure(t *testing.T) { - th := makeTestHarness(t) + th := kusttest_test.MakeHarness(t) writeDeploymentBase(th) writeProbeOverlay(th) writeDNSOverlay(th) @@ -168,7 +168,7 @@ spec: // This test reuses some methods from TestIssue1251_CompositeDiamond, // but overwrites the kustomization files in the overlays. func TestIssue1251_Patches_Overlayed(t *testing.T) { - th := makeTestHarness(t) + th := kusttest_test.MakeHarness(t) writeDeploymentBase(th) // probe overlays base. @@ -197,7 +197,7 @@ patchesStrategicMerge: } func TestIssue1251_Patches_Local(t *testing.T) { - th := makeTestHarness(t) + th := kusttest_test.MakeHarness(t) writeDeploymentBase(th) th.WriteK("/app/composite", ` @@ -216,7 +216,7 @@ patchesStrategicMerge: th.AssertActualEqualsExpected(m, expectedPatchedDeployment) } -func definePatchDirStructure(th testingHarness) { +func definePatchDirStructure(th kusttest_test.Harness) { writeDeploymentBase(th) th.WriteF("/app/patches/patchRestartPolicy.yaml", patchRestartPolicy) @@ -226,7 +226,7 @@ func definePatchDirStructure(th testingHarness) { // Fails due to file load restrictor. func TestIssue1251_Patches_ProdVsDev_Failure(t *testing.T) { - th := makeTestHarness(t) + th := kusttest_test.MakeHarness(t) definePatchDirStructure(th) th.WriteK("/app/prod", ` @@ -299,7 +299,7 @@ spec: // the kustomization root), opening the user to whatever // threat the load restrictor was meant to address. func TestIssue1251_Patches_ProdVsDev(t *testing.T) { - th := makeTestHarness(t) + th := kusttest_test.MakeHarness(t) definePatchDirStructure(th) th.WriteK("/app/prod", ` @@ -315,7 +315,7 @@ patchesStrategicMerge: m := th.Run("/app/prod", opts) th.AssertActualEqualsExpected(m, prodDevMergeResult1) - th = makeTestHarness(t) + th = kusttest_test.MakeHarness(t) definePatchDirStructure(th) th.WriteK("/app/dev", ` @@ -337,7 +337,7 @@ func TestIssue1251_Plugins_ProdVsDev(t *testing.T) { tc.BuildGoPlugin( "builtin", "", "PatchJson6902Transformer") - th := makeTestHarness(t) + th := kusttest_test.MakeHarness(t) defineTransformerDirStructure(th) th.WriteK("/app/prod", ` resources: @@ -370,7 +370,7 @@ func TestIssue1251_Plugins_Local(t *testing.T) { tc.BuildGoPlugin( "builtin", "", "PatchJson6902Transformer") - th := makeTestHarness(t) + th := kusttest_test.MakeHarness(t) writeDeploymentBase(th) writeJsonTransformerPluginConfig( @@ -393,7 +393,7 @@ transformers: } func writeJsonTransformerPluginConfig( - th testingHarness, path, name, patch string) { + th kusttest_test.Harness, path, name, patch string) { th.WriteF(filepath.Join(path, name+"Config.yaml"), fmt.Sprintf(` apiVersion: builtin @@ -417,7 +417,7 @@ func TestIssue1251_Plugins_Bundled(t *testing.T) { tc.BuildGoPlugin( "builtin", "", "PatchJson6902Transformer") - th := makeTestHarness(t) + th := kusttest_test.MakeHarness(t) writeDeploymentBase(th) th.WriteK("/app/patches", ` @@ -443,7 +443,7 @@ transformers: th.AssertActualEqualsExpected(m, expectedPatchedDeployment) } -func defineTransformerDirStructure(th testingHarness) { +func defineTransformerDirStructure(th kusttest_test.Harness) { writeDeploymentBase(th) th.WriteK("/app/patches/addDnsPolicy", ` diff --git a/api/krusty/diamonds_test.go b/api/krusty/diamonds_test.go index b80598525..d4cb25ea6 100644 --- a/api/krusty/diamonds_test.go +++ b/api/krusty/diamonds_test.go @@ -5,6 +5,8 @@ package krusty_test import ( "testing" + + kusttest_test "sigs.k8s.io/kustomize/api/testutils/kusttest" ) // Here's a structure of two kustomizations, @@ -28,7 +30,7 @@ import ( // \ | / // base // -func writeDiamondBase(th testingHarness) { +func writeDiamondBase(th kusttest_test.Harness) { th.WriteK("/app/base", ` resources: - deploy.yaml @@ -43,7 +45,7 @@ spec: `) } -func writeKirk(th testingHarness) { +func writeKirk(th kusttest_test.Harness) { th.WriteK("/app/kirk", ` namePrefix: kirk- resources: @@ -70,7 +72,7 @@ data: `) } -func writeSpock(th testingHarness) { +func writeSpock(th kusttest_test.Harness) { th.WriteK("/app/spock", ` namePrefix: spock- resources: @@ -88,7 +90,7 @@ spec: `) } -func writeBones(th testingHarness) { +func writeBones(th kusttest_test.Harness) { th.WriteK("/app/bones", ` namePrefix: bones- resources: @@ -106,7 +108,7 @@ spec: `) } -func writeTenants(th testingHarness) { +func writeTenants(th kusttest_test.Harness) { th.WriteK("/app/tenants", ` namePrefix: t- resources: @@ -137,7 +139,7 @@ data: } func TestBasicDiamond(t *testing.T) { - th := makeTestHarness(t) + th := kusttest_test.MakeHarness(t) writeDiamondBase(th) writeKirk(th) writeSpock(th) diff --git a/api/krusty/directoryarrangement_test.go b/api/krusty/directoryarrangement_test.go index a5c1c95fd..cb4e755de 100644 --- a/api/krusty/directoryarrangement_test.go +++ b/api/krusty/directoryarrangement_test.go @@ -5,10 +5,12 @@ package krusty_test import ( "testing" + + kusttest_test "sigs.k8s.io/kustomize/api/testutils/kusttest" ) func TestIssue596AllowDirectoriesThatAreSubstringsOfEachOther(t *testing.T) { - th := makeTestHarness(t) + th := kusttest_test.MakeHarness(t) th.WriteK("/app/base", "") th.WriteK("/app/overlays/aws", ` resources: diff --git a/api/krusty/disablenamesuffix_test.go b/api/krusty/disablenamesuffix_test.go index 423ad5390..aef7d7154 100644 --- a/api/krusty/disablenamesuffix_test.go +++ b/api/krusty/disablenamesuffix_test.go @@ -9,6 +9,7 @@ import ( "sigs.k8s.io/kustomize/api/resmap" "sigs.k8s.io/kustomize/api/resource" + kusttest_test "sigs.k8s.io/kustomize/api/testutils/kusttest" ) func findSecret(m resmap.ResMap) *resource.Resource { @@ -21,7 +22,7 @@ func findSecret(m resmap.ResMap) *resource.Resource { } func TestDisableNameSuffixHash(t *testing.T) { - th := makeTestHarness(t) + th := kusttest_test.MakeHarness(t) const kustomizationContent = ` apiVersion: kustomize.config.k8s.io/v1beta1 kind: Kustomization diff --git a/api/krusty/extendedpatch_test.go b/api/krusty/extendedpatch_test.go index e6e149ada..ee04cef7a 100644 --- a/api/krusty/extendedpatch_test.go +++ b/api/krusty/extendedpatch_test.go @@ -5,9 +5,11 @@ package krusty_test import ( "testing" + + kusttest_test "sigs.k8s.io/kustomize/api/testutils/kusttest" ) -func makeCommonFileForExtendedPatchTest(th testingHarness) { +func makeCommonFileForExtendedPatchTest(th kusttest_test.Harness) { th.WriteF("/app/base/deployment.yaml", ` apiVersion: apps/v1beta2 kind: Deployment @@ -87,7 +89,7 @@ spec: } func TestExtendedPatchNameSelector(t *testing.T) { - th := makeTestHarness(t) + th := kusttest_test.MakeHarness(t) makeCommonFileForExtendedPatchTest(th) th.WriteK("/app/base", ` resources: @@ -189,7 +191,7 @@ spec: } func TestExtendedPatchGvkSelector(t *testing.T) { - th := makeTestHarness(t) + th := kusttest_test.MakeHarness(t) makeCommonFileForExtendedPatchTest(th) th.WriteK("/app/base", ` resources: @@ -291,7 +293,7 @@ spec: } func TestExtendedPatchLabelSelector(t *testing.T) { - th := makeTestHarness(t) + th := kusttest_test.MakeHarness(t) makeCommonFileForExtendedPatchTest(th) th.WriteK("/app/base", ` resources: @@ -393,7 +395,7 @@ spec: } func TestExtendedPatchNameGvkSelector(t *testing.T) { - th := makeTestHarness(t) + th := kusttest_test.MakeHarness(t) makeCommonFileForExtendedPatchTest(th) th.WriteK("/app/base", ` resources: @@ -494,7 +496,7 @@ spec: } func TestExtendedPatchNameLabelSelector(t *testing.T) { - th := makeTestHarness(t) + th := kusttest_test.MakeHarness(t) makeCommonFileForExtendedPatchTest(th) th.WriteK("/app/base", ` resources: @@ -597,7 +599,7 @@ spec: } func TestExtendedPatchGvkLabelSelector(t *testing.T) { - th := makeTestHarness(t) + th := kusttest_test.MakeHarness(t) makeCommonFileForExtendedPatchTest(th) th.WriteK("/app/base", ` resources: @@ -698,7 +700,7 @@ spec: } func TestExtendedPatchNameGvkLabelSelector(t *testing.T) { - th := makeTestHarness(t) + th := kusttest_test.MakeHarness(t) makeCommonFileForExtendedPatchTest(th) th.WriteK("/app/base", ` resources: @@ -800,7 +802,7 @@ spec: } func TestExtendedPatchNoMatch(t *testing.T) { - th := makeTestHarness(t) + th := kusttest_test.MakeHarness(t) makeCommonFileForExtendedPatchTest(th) th.WriteK("/app/base", ` resources: @@ -898,7 +900,7 @@ spec: } func TestExtendedPatchWithoutTarget(t *testing.T) { - th := makeTestHarness(t) + th := kusttest_test.MakeHarness(t) makeCommonFileForExtendedPatchTest(th) th.WriteK("/app/base", ` resources: @@ -996,7 +998,7 @@ spec: } func TestExtendedPatchNoMatchMultiplePatch(t *testing.T) { - th := makeTestHarness(t) + th := kusttest_test.MakeHarness(t) makeCommonFileForExtendedPatchTest(th) th.WriteK("/app/base", ` resources: @@ -1098,7 +1100,7 @@ spec: } func TestExtendedPatchMultiplePatchOverlapping(t *testing.T) { - th := makeTestHarness(t) + th := kusttest_test.MakeHarness(t) makeCommonFileForExtendedPatchTest(th) th.WriteK("/app/base", ` resources: diff --git a/api/krusty/generatormergeandreplace_test.go b/api/krusty/generatormergeandreplace_test.go index 95d91ea21..32407bd30 100644 --- a/api/krusty/generatormergeandreplace_test.go +++ b/api/krusty/generatormergeandreplace_test.go @@ -6,10 +6,12 @@ package krusty_test import ( "strings" "testing" + + kusttest_test "sigs.k8s.io/kustomize/api/testutils/kusttest" ) func TestSimpleBase(t *testing.T) { - th := makeTestHarness(t) + th := kusttest_test.MakeHarness(t) th.WriteK("/app/base", ` apiVersion: kustomize.config.k8s.io/v1beta1 kind: Kustomization @@ -146,7 +148,7 @@ spec: `) } -func makeBaseWithGenerators(th testingHarness) { +func makeBaseWithGenerators(th kusttest_test.Harness) { th.WriteK("/app", ` apiVersion: kustomize.config.k8s.io/v1beta1 kind: Kustomization @@ -212,7 +214,7 @@ spec: } func TestBaseWithGeneratorsAlone(t *testing.T) { - th := makeTestHarness(t) + th := kusttest_test.MakeHarness(t) makeBaseWithGenerators(th) m := th.Run("/app", th.MakeDefaultOptions()) th.AssertActualEqualsExpected(m, ` @@ -303,7 +305,7 @@ type: Opaque } func TestMergeAndReplaceGenerators(t *testing.T) { - th := makeTestHarness(t) + th := kusttest_test.MakeHarness(t) makeBaseWithGenerators(th) th.WriteF("/overlay/deployment.yaml", ` apiVersion: apps/v1beta2 @@ -458,7 +460,7 @@ metadata: } func TestGeneratingIntoNamespaces(t *testing.T) { - th := makeTestHarness(t) + th := kusttest_test.MakeHarness(t) th.WriteK("/app", ` configMapGenerator: - name: test @@ -524,7 +526,7 @@ type: Opaque // Valid that conflict is detected is the name are identical // and namespace left to default func TestConfigMapGeneratingIntoSameNamespace(t *testing.T) { - th := makeTestHarness(t) + th := kusttest_test.MakeHarness(t) th.WriteK("/app", ` configMapGenerator: - name: test @@ -547,7 +549,7 @@ configMapGenerator: // Valid that conflict is detected is the name are identical // and namespace left to default func TestSecretGeneratingIntoSameNamespace(t *testing.T) { - th := makeTestHarness(t) + th := kusttest_test.MakeHarness(t) th.WriteK("/app", ` secretGenerator: - name: test diff --git a/api/krusty/generatoroptions_test.go b/api/krusty/generatoroptions_test.go index 59701d08d..aa2566347 100644 --- a/api/krusty/generatoroptions_test.go +++ b/api/krusty/generatoroptions_test.go @@ -5,10 +5,12 @@ package krusty_test import ( "testing" + + kusttest_test "sigs.k8s.io/kustomize/api/testutils/kusttest" ) func TestSecretGenerator(t *testing.T) { - th := makeTestHarness(t) + th := kusttest_test.MakeHarness(t) th.WriteK("/app", ` secretGenerator: - name: bob @@ -44,7 +46,7 @@ type: Opaque } func TestGeneratorOptionsWithBases(t *testing.T) { - th := makeTestHarness(t) + th := kusttest_test.MakeHarness(t) th.WriteK("/app/base", ` apiVersion: kustomize.config.k8s.io/v1beta1 kind: Kustomization diff --git a/api/krusty/inlinepatch_test.go b/api/krusty/inlinepatch_test.go index 81de933c7..b49297c6c 100644 --- a/api/krusty/inlinepatch_test.go +++ b/api/krusty/inlinepatch_test.go @@ -5,9 +5,11 @@ package krusty_test import ( "testing" + + kusttest_test "sigs.k8s.io/kustomize/api/testutils/kusttest" ) -func makeResourcesForPatchTest(th testingHarness) { +func makeResourcesForPatchTest(th kusttest_test.Harness) { th.WriteF("/app/base/deployment.yaml", ` apiVersion: apps/v1 kind: Deployment @@ -37,7 +39,7 @@ spec: } func TestStrategicMergePatchInline(t *testing.T) { - th := makeTestHarness(t) + th := kusttest_test.MakeHarness(t) makeResourcesForPatchTest(th) th.WriteK("/app/base", ` resources: @@ -86,7 +88,7 @@ spec: } func TestJSONPatchInline(t *testing.T) { - th := makeTestHarness(t) + th := kusttest_test.MakeHarness(t) makeResourcesForPatchTest(th) th.WriteK("/app/base", ` resources: @@ -133,7 +135,7 @@ spec: } func TestExtendedPatchInlineJSON(t *testing.T) { - th := makeTestHarness(t) + th := kusttest_test.MakeHarness(t) makeResourcesForPatchTest(th) th.WriteK("/app/base", ` resources: @@ -178,7 +180,7 @@ spec: } func TestExtendedPatchInlineYAML(t *testing.T) { - th := makeTestHarness(t) + th := kusttest_test.MakeHarness(t) makeResourcesForPatchTest(th) th.WriteK("/app/base", ` resources: diff --git a/api/krusty/multiplepatch_test.go b/api/krusty/multiplepatch_test.go index 7966e8e5a..660ac7f2c 100644 --- a/api/krusty/multiplepatch_test.go +++ b/api/krusty/multiplepatch_test.go @@ -6,9 +6,11 @@ package krusty_test import ( "strings" "testing" + + kusttest_test "sigs.k8s.io/kustomize/api/testutils/kusttest" ) -func makeCommonFileForMultiplePatchTest(th testingHarness) { +func makeCommonFileForMultiplePatchTest(th kusttest_test.Harness) { th.WriteK("/app/base", ` apiVersion: kustomize.config.k8s.io/v1beta1 kind: Kustomization @@ -87,7 +89,7 @@ configMapGenerator: } func TestMultiplePatchesNoConflict(t *testing.T) { - th := makeTestHarness(t) + th := kusttest_test.MakeHarness(t) makeCommonFileForMultiplePatchTest(th) th.WriteF("/app/overlay/staging/deployment-patch1.yaml", ` apiVersion: apps/v1beta2 @@ -228,7 +230,7 @@ metadata: } func TestMultiplePatchesWithConflict(t *testing.T) { - th := makeTestHarness(t) + th := kusttest_test.MakeHarness(t) makeCommonFileForMultiplePatchTest(th) th.WriteF("/app/overlay/staging/deployment-patch1.yaml", ` apiVersion: apps/v1beta2 @@ -320,7 +322,7 @@ spec: } for _, c := range cases { t.Run(c.name, func(t *testing.T) { - th := makeTestHarness(t) + th := kusttest_test.MakeHarness(t) makeCommonFileForMultiplePatchTest(th) th.WriteF("/app/overlay/staging/deployment-patch1.yaml", c.patch1) @@ -418,7 +420,7 @@ metadata: } func TestMultiplePatchesBothWithPatchDeleteDirective(t *testing.T) { - th := makeTestHarness(t) + th := kusttest_test.MakeHarness(t) makeCommonFileForMultiplePatchTest(th) th.WriteF("/app/overlay/staging/deployment-patch1.yaml", ` apiVersion: apps/v1beta2 diff --git a/api/krusty/namespacedgenerators_test.go b/api/krusty/namespacedgenerators_test.go index 742c98ff1..b6349fa1e 100644 --- a/api/krusty/namespacedgenerators_test.go +++ b/api/krusty/namespacedgenerators_test.go @@ -5,10 +5,12 @@ package krusty_test import ( "testing" + + kusttest_test "sigs.k8s.io/kustomize/api/testutils/kusttest" ) func TestNamespacedGenerator(t *testing.T) { - th := makeTestHarness(t) + th := kusttest_test.MakeHarness(t) th.WriteK("/app", ` apiVersion: kustomize.config.k8s.io/v1beta1 kind: Kustomization @@ -71,7 +73,7 @@ type: Opaque } func TestNamespacedGeneratorWithOverlays(t *testing.T) { - th := makeTestHarness(t) + th := kusttest_test.MakeHarness(t) th.WriteK("/app/base", ` namespace: base diff --git a/api/krusty/namespaces_test.go b/api/krusty/namespaces_test.go index 873ecb98a..01183588d 100644 --- a/api/krusty/namespaces_test.go +++ b/api/krusty/namespaces_test.go @@ -6,10 +6,12 @@ package krusty_test import ( "strings" "testing" + + kusttest_test "sigs.k8s.io/kustomize/api/testutils/kusttest" ) func TestNamespacedSecrets(t *testing.T) { - th := makeTestHarness(t) + th := kusttest_test.MakeHarness(t) th.WriteF("/app/secrets.yaml", ` apiVersion: v1 kind: Secret @@ -93,7 +95,7 @@ rules: // PrefixSuffixTransformer and namereference transformers are // able to deal with simultaneous change of namespace and name. func TestNameAndNsTransformation(t *testing.T) { - th := makeTestHarness(t) + th := kusttest_test.MakeHarness(t) th.WriteK("/nameandns", ` namePrefix: p1- @@ -463,7 +465,7 @@ spec: // using the same name in different namespaces are treated as ambiguous if the namespace is // not specified func TestVariablesAmbiguous(t *testing.T) { - th := makeTestHarness(t) + th := kusttest_test.MakeHarness(t) th.WriteK("/namespaceNeedInVar/myapp", namespaceNeedInVarMyApp) th.WriteF("/namespaceNeedInVar/myapp/elasticsearch-dev-service.yaml", namespaceNeedInVarDevResources) th.WriteF("/namespaceNeedInVar/myapp/elasticsearch-test-service.yaml", namespaceNeedInVarTestResources) @@ -520,7 +522,7 @@ vars: // to TestVariablesAmbiguous problem. It requires to separate the variables // and resources into multiple kustomization context/folders instead of one. func TestVariablesAmbiguousWorkaround(t *testing.T) { - th := makeTestHarness(t) + th := kusttest_test.MakeHarness(t) th.WriteK("/namespaceNeedInVar/dev", namespaceNeedInVarDevFolder) th.WriteF("/namespaceNeedInVar/dev/elasticsearch-dev-service.yaml", namespaceNeedInVarDevResources) th.WriteK("/namespaceNeedInVar/test", namespaceNeedInVarTestFolder) @@ -576,7 +578,7 @@ vars: // TestVariablesDisambiguatedWithNamespace demonstrates that adding the namespace // to the variable declarations allows to disambiguate the variables. func TestVariablesDisambiguatedWithNamespace(t *testing.T) { - th := makeTestHarness(t) + th := kusttest_test.MakeHarness(t) th.WriteK("/namespaceNeedInVar/myapp", namespaceNeedInVarMyAppWithNamespace) th.WriteF("/namespaceNeedInVar/myapp/elasticsearch-dev-service.yaml", namespaceNeedInVarDevResources) th.WriteF("/namespaceNeedInVar/myapp/elasticsearch-test-service.yaml", namespaceNeedInVarTestResources) diff --git a/api/krusty/nullvalues_test.go b/api/krusty/nullvalues_test.go index fe111bd91..2fcb406ce 100644 --- a/api/krusty/nullvalues_test.go +++ b/api/krusty/nullvalues_test.go @@ -5,10 +5,12 @@ package krusty_test import ( "testing" + + kusttest_test "sigs.k8s.io/kustomize/api/testutils/kusttest" ) func TestNullValues(t *testing.T) { - th := makeTestHarness(t) + th := kusttest_test.MakeHarness(t) th.WriteF("/app/deployment.yaml", ` apiVersion: apps/v1 kind: Deployment diff --git a/api/krusty/pluginenv_test.go b/api/krusty/pluginenv_test.go index 6dbdd3f6b..6a79257dd 100644 --- a/api/krusty/pluginenv_test.go +++ b/api/krusty/pluginenv_test.go @@ -25,17 +25,17 @@ func TestPluginEnvironment(t *testing.T) { "someteam.example.com", "v1", "PrintPluginEnv") confirmBehavior( - makeTestHarnessWithFs(t, filesys.MakeFsInMemory()), + kusttest_test.MakeHarnessWithFs(t, filesys.MakeFsInMemory()), filesys.Separator) dir := makeTmpDir(t) defer os.RemoveAll(dir) confirmBehavior( - makeTestHarnessWithFs(t, filesys.MakeFsOnDisk()), + kusttest_test.MakeHarnessWithFs(t, filesys.MakeFsOnDisk()), dir) } -func confirmBehavior(th testingHarness, dir string) { +func confirmBehavior(th kusttest_test.Harness, dir string) { th.WriteK(dir, ` generators: - config.yaml diff --git a/api/krusty/pruneconfigmap_test.go b/api/krusty/pruneconfigmap_test.go index efbc150b5..6669a5ba0 100644 --- a/api/krusty/pruneconfigmap_test.go +++ b/api/krusty/pruneconfigmap_test.go @@ -5,10 +5,12 @@ package krusty_test import ( "testing" + + kusttest_test "sigs.k8s.io/kustomize/api/testutils/kusttest" ) func TestPruneConfigMap(t *testing.T) { - th := makeTestHarness(t) + th := kusttest_test.MakeHarness(t) th.WriteK("/app/base", ` resources: - deployment.yaml diff --git a/api/krusty/resourceconflict_test.go b/api/krusty/resourceconflict_test.go index 54919fb44..42166c696 100644 --- a/api/krusty/resourceconflict_test.go +++ b/api/krusty/resourceconflict_test.go @@ -6,9 +6,11 @@ package krusty_test import ( "strings" "testing" + + kusttest_test "sigs.k8s.io/kustomize/api/testutils/kusttest" ) -func writeBase(th testingHarness) { +func writeBase(th kusttest_test.Harness) { th.WriteK("/app/base", ` resources: - serviceaccount.yaml @@ -62,7 +64,7 @@ rules: `) } -func writeMidOverlays(th testingHarness) { +func writeMidOverlays(th kusttest_test.Harness) { // Mid-level overlays th.WriteK("/app/overlays/a", ` resources: @@ -78,7 +80,7 @@ nameSuffix: -suffixB `) } -func writeTopOverlay(th testingHarness) { +func writeTopOverlay(th kusttest_test.Harness) { // Top overlay, combining the mid-level overlays th.WriteK("/app/combined", ` resources: @@ -89,7 +91,7 @@ resources: func TestBase(t *testing.T) { //th := kusttest_test.NewKustTestHarness(t, "/app/base") - th := makeTestHarness(t) + th := kusttest_test.MakeHarness(t) writeBase(th) m := th.Run("/app/base", th.MakeDefaultOptions()) th.AssertActualEqualsExpected(m, ` @@ -139,7 +141,7 @@ rules: } func TestMidLevelA(t *testing.T) { - th := makeTestHarness(t) + th := kusttest_test.MakeHarness(t) writeBase(th) writeMidOverlays(th) m := th.Run("/app/overlays/a", th.MakeDefaultOptions()) @@ -190,7 +192,7 @@ rules: } func TestMidLevelB(t *testing.T) { - th := makeTestHarness(t) + th := kusttest_test.MakeHarness(t) writeBase(th) writeMidOverlays(th) m := th.Run("/app/overlays/b", th.MakeDefaultOptions()) @@ -241,7 +243,7 @@ rules: } func TestMultibasesNoConflict(t *testing.T) { - th := makeTestHarness(t) + th := kusttest_test.MakeHarness(t) writeBase(th) writeMidOverlays(th) writeTopOverlay(th) @@ -336,7 +338,7 @@ rules: } func TestMultibasesWithConflict(t *testing.T) { - th := makeTestHarness(t) + th := kusttest_test.MakeHarness(t) //th := kusttest_test.NewKustTestHarness(t, "/app/combined") writeBase(th) writeMidOverlays(th) diff --git a/api/krusty/testingharness_test.go b/api/krusty/testingharness_test.go deleted file mode 100644 index 2f7431abf..000000000 --- a/api/krusty/testingharness_test.go +++ /dev/null @@ -1,202 +0,0 @@ -// Copyright 2019 The Kubernetes Authors. -// SPDX-License-Identifier: Apache-2.0 - -package krusty_test - -import ( - "fmt" - "path/filepath" - "strings" - "testing" - - "sigs.k8s.io/kustomize/api/filesys" - "sigs.k8s.io/kustomize/api/konfig" - "sigs.k8s.io/kustomize/api/konfig/builtinpluginconsts" - . "sigs.k8s.io/kustomize/api/krusty" - "sigs.k8s.io/kustomize/api/resmap" - "sigs.k8s.io/kustomize/api/types" -) - -type testingHarness struct { - t *testing.T - fSys filesys.FileSystem -} - -func makeTestHarness(t *testing.T) testingHarness { - return makeTestHarnessWithFs(t, filesys.MakeFsInMemory()) -} - -func makeTestHarnessWithFs( - t *testing.T, fSys filesys.FileSystem) testingHarness { - return testingHarness{ - t: t, - fSys: fSys, - } -} - -func (th testingHarness) GetT() *testing.T { - return th.t -} - -func (th testingHarness) WriteK(path string, content string) { - th.fSys.WriteFile( - filepath.Join( - path, - konfig.DefaultKustomizationFileName()), []byte(` -apiVersion: kustomize.config.k8s.io/v1beta1 -kind: Kustomization -`+content)) -} - -func (th testingHarness) WriteF(path string, content string) { - th.fSys.WriteFile(path, []byte(content)) -} - -func (th testingHarness) MakeDefaultOptions() Options { - return th.MakeOptionsPluginsDisabled() -} - -// This has no impact on Builtin plugins, as they are always enabled. -func (th testingHarness) MakeOptionsPluginsDisabled() Options { - return Options{ - LoadRestrictions: types.LoadRestrictionsRootOnly, - PluginConfig: konfig.DisabledPluginConfig(), - } -} - -// Enables use of non-builtin plugins. -func (th testingHarness) MakeOptionsPluginsEnabled() Options { - c, err := konfig.EnabledPluginConfig() - 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) - } - return Options{ - LoadRestrictions: types.LoadRestrictionsRootOnly, - PluginConfig: c, - } -} - -// Run, failing on error. -func (th testingHarness) Run(path string, o Options) resmap.ResMap { - m, err := MakeKustomizer(th.fSys, &o).Run(path) - if err != nil { - th.t.Fatal(err) - } - return m -} - -// Run, failing if there is no error. -func (th testingHarness) RunWithErr(path string, o Options) error { - _, err := MakeKustomizer(th.fSys, &o).Run(path) - if err == nil { - th.t.Fatalf("expected error") - } - return err -} - -func (th testingHarness) AssertActualEqualsExpected( - m resmap.ResMap, expected string) { - th.AssertActualEqualsExpectedWithTweak(m, nil, expected) -} - -func (th testingHarness) AssertActualEqualsExpectedWithTweak( - m resmap.ResMap, tweaker func([]byte) []byte, expected string) { - if m == nil { - th.t.Fatalf("Map should not be nil.") - } - // Ignore leading linefeed in expected value - // to ease readability of tests. - if len(expected) > 0 && expected[0] == 10 { - expected = expected[1:] - } - actual, err := m.AsYaml() - if err != nil { - th.t.Fatalf("Unexpected err: %v", err) - } - if tweaker != nil { - actual = tweaker(actual) - } - if string(actual) != expected { - th.reportDiffAndFail(actual, expected) - } -} - -// Pretty printing of file differences. -func (th testingHarness) reportDiffAndFail(actual []byte, expected string) { - sE, maxLen := convertToArray(expected) - sA, _ := convertToArray(string(actual)) - fmt.Println("===== ACTUAL BEGIN ========================================") - fmt.Print(string(actual)) - fmt.Println("===== ACTUAL END ==========================================") - format := fmt.Sprintf("%%s %%-%ds %%s\n", maxLen+4) - limit := 0 - if len(sE) < len(sA) { - limit = len(sE) - } else { - limit = len(sA) - } - fmt.Printf(format, " ", "EXPECTED", "ACTUAL") - fmt.Printf(format, " ", "--------", "------") - for i := 0; i < limit; i++ { - fmt.Printf(format, hint(sE[i], sA[i]), sE[i], sA[i]) - } - if len(sE) < len(sA) { - for i := len(sE); i < len(sA); i++ { - fmt.Printf(format, "X", "", sA[i]) - } - } else { - for i := len(sA); i < len(sE); i++ { - fmt.Printf(format, "X", sE[i], "") - } - } - th.t.Fatalf("Expected not equal to actual") -} - -func convertToArray(x string) ([]string, int) { - a := strings.Split(strings.TrimSuffix(x, "\n"), "\n") - maxLen := 0 - for i, v := range a { - z := tabToSpace(v) - if len(z) > maxLen { - maxLen = len(z) - } - a[i] = z - } - return a, maxLen -} - -func hint(a, b string) string { - if a == b { - return " " - } - return "X" -} - -func tabToSpace(input string) string { - var result []string - for _, i := range input { - if i == 9 { - result = append(result, " ") - } else { - result = append(result, string(i)) - } - } - return strings.Join(result, "") -} - -func (th testingHarness) WriteLegacyConfigs(fName string) { - m := builtinpluginconsts.GetDefaultFieldSpecsAsMap() - var content []byte - for _, tCfg := range m { - content = append(content, []byte(tCfg)...) - } - err := th.fSys.WriteFile(fName, content) - if err != nil { - th.t.Fatalf("unable to add file %s", fName) - } -} diff --git a/api/krusty/transformerplugin_test.go b/api/krusty/transformerplugin_test.go index 83988bdf5..2c3a54630 100644 --- a/api/krusty/transformerplugin_test.go +++ b/api/krusty/transformerplugin_test.go @@ -10,7 +10,7 @@ import ( "sigs.k8s.io/kustomize/api/types" ) -func writeDeployment(th testingHarness, path string) { +func writeDeployment(th kusttest_test.Harness, path string) { th.WriteF(path, ` apiVersion: apps/v1 kind: Deployment @@ -28,7 +28,7 @@ spec: `) } -func writeStringPrefixer(th testingHarness, path, name string) { +func writeStringPrefixer(th kusttest_test.Harness, path, name string) { th.WriteF(path, ` apiVersion: someteam.example.com/v1 kind: StringPrefixer @@ -37,7 +37,7 @@ metadata: `) } -func writeDatePrefixer(th testingHarness, path, name string) { +func writeDatePrefixer(th kusttest_test.Harness, path, name string) { th.WriteF(path, ` apiVersion: someteam.example.com/v1 kind: DatePrefixer @@ -55,7 +55,7 @@ func TestOrderedTransformers(t *testing.T) { tc.BuildGoPlugin( "someteam.example.com", "v1", "DatePrefixer") - th := makeTestHarness(t) + th := kusttest_test.MakeHarness(t) th.WriteK("/app", ` resources: - deployment.yaml @@ -95,7 +95,7 @@ func TestPluginsNotEnabled(t *testing.T) { tc.BuildGoPlugin( "someteam.example.com", "v1", "StringPrefixer") - th := makeTestHarness(t) + th := kusttest_test.MakeHarness(t) th.WriteK("/app", ` transformers: - stringPrefixer.yaml @@ -117,7 +117,7 @@ func TestSedTransformer(t *testing.T) { tc.PrepExecPlugin( "someteam.example.com", "v1", "SedTransformer") - th := makeTestHarness(t) + th := kusttest_test.MakeHarness(t) th.WriteK("/app", ` resources: - configmap.yaml @@ -185,7 +185,7 @@ func TestTransformedTransformers(t *testing.T) { tc.BuildGoPlugin( "someteam.example.com", "v1", "DatePrefixer") - th := makeTestHarness(t) + th := kusttest_test.MakeHarness(t) th.WriteK("/app/base", ` resources: diff --git a/api/krusty/transformersarrays_test.go b/api/krusty/transformersarrays_test.go index 90f13874d..d32931fcf 100644 --- a/api/krusty/transformersarrays_test.go +++ b/api/krusty/transformersarrays_test.go @@ -5,9 +5,11 @@ package krusty_test import ( "testing" + + kusttest_test "sigs.k8s.io/kustomize/api/testutils/kusttest" ) -func makeStatefulSetKustomization(th testingHarness) { +func makeStatefulSetKustomization(th kusttest_test.Harness) { th.WriteK("/app", ` commonLabels: notIn: arrays @@ -90,7 +92,7 @@ spec: } func TestTransformersNoCreateArrays(t *testing.T) { - th := makeTestHarness(t) + th := kusttest_test.MakeHarness(t) makeStatefulSetKustomization(th) m := th.Run("/app", th.MakeDefaultOptions()) th.AssertActualEqualsExpected(m, ` diff --git a/api/krusty/transformersimage_test.go b/api/krusty/transformersimage_test.go index 1b6d4da77..795be617e 100644 --- a/api/krusty/transformersimage_test.go +++ b/api/krusty/transformersimage_test.go @@ -5,9 +5,11 @@ package krusty_test import ( "testing" + + kusttest_test "sigs.k8s.io/kustomize/api/testutils/kusttest" ) -func makeTransfomersImageBase(th testingHarness) { +func makeTransfomersImageBase(th kusttest_test.Harness) { th.WriteK("/app/base", ` resources: - deploy1.yaml @@ -92,7 +94,7 @@ spec3: } func TestIssue1281_JsonPatchAndImageTag(t *testing.T) { - th := makeTestHarness(t) + th := kusttest_test.MakeHarness(t) th.WriteK("/app", ` resources: - deployment.yaml @@ -172,7 +174,7 @@ spec: } func TestTransfomersImageDefaultConfig(t *testing.T) { - th := makeTestHarness(t) + th := kusttest_test.MakeHarness(t) makeTransfomersImageBase(th) m := th.Run("/app/base", th.MakeDefaultOptions()) th.AssertActualEqualsExpected(m, ` @@ -233,7 +235,7 @@ spec3: `) } -func makeTransfomersImageCustomBase(th testingHarness) { +func makeTransfomersImageCustomBase(th kusttest_test.Harness) { th.WriteK("/app/base", ` resources: - custom.yaml @@ -306,7 +308,7 @@ images: } func TestTransfomersImageCustomConfig(t *testing.T) { - th := makeTestHarness(t) + th := kusttest_test.MakeHarness(t) makeTransfomersImageCustomBase(th) m := th.Run("/app/base", th.MakeDefaultOptions()) th.AssertActualEqualsExpected(m, ` @@ -346,7 +348,7 @@ spec3: `) } -func makeTransfomersImageKnativeBase(th testingHarness) { +func makeTransfomersImageKnativeBase(th kusttest_test.Harness) { th.WriteK("/app/base", ` resources: - knative.yaml @@ -378,7 +380,7 @@ images: } func TestTransfomersImageKnativeConfig(t *testing.T) { - th := makeTestHarness(t) + th := kusttest_test.MakeHarness(t) makeTransfomersImageKnativeBase(th) m := th.Run("/app/base", th.MakeDefaultOptions()) th.AssertActualEqualsExpected(m, ` diff --git a/api/krusty/variableref_test.go b/api/krusty/variableref_test.go index d88947d31..8ca85f9fc 100644 --- a/api/krusty/variableref_test.go +++ b/api/krusty/variableref_test.go @@ -6,10 +6,12 @@ package krusty_test import ( "strings" "testing" + + kusttest_test "sigs.k8s.io/kustomize/api/testutils/kusttest" ) func TestBasicVariableRef(t *testing.T) { - th := makeTestHarness(t) + th := kusttest_test.MakeHarness(t) th.WriteK("/app", ` namePrefix: base- resources: @@ -60,7 +62,7 @@ spec: } func TestBasicVarCollision(t *testing.T) { - th := makeTestHarness(t) + th := kusttest_test.MakeHarness(t) th.WriteK("/app/base1", ` namePrefix: base1- resources: @@ -136,7 +138,7 @@ resources: } func TestVarPropagatesUp(t *testing.T) { - th := makeTestHarness(t) + th := kusttest_test.MakeHarness(t) th.WriteK("/app/base1", ` namePrefix: base1- resources: @@ -279,7 +281,7 @@ spec: // are global. So if a base with a variable is included // twice, it's a collision, so it's denied. func TestBug506(t *testing.T) { - th := makeTestHarness(t) + th := kusttest_test.MakeHarness(t) th.WriteK("/app/base", ` namePrefix: base- resources: @@ -359,7 +361,7 @@ resources: } func TestVarRefBig(t *testing.T) { - th := makeTestHarness(t) + th := kusttest_test.MakeHarness(t) th.WriteK("/app/base", ` namePrefix: base- resources: @@ -925,7 +927,7 @@ metadata: } func TestVariableRefIngress(t *testing.T) { - th := makeTestHarness(t) + th := kusttest_test.MakeHarness(t) th.WriteK("/app/base", ` resources: - service.yaml @@ -1064,7 +1066,7 @@ spec: } func TestVariableRefMountPath(t *testing.T) { - th := makeTestHarness(t) + th := kusttest_test.MakeHarness(t) th.WriteK("/app/base", ` resources: - deployment.yaml @@ -1136,7 +1138,7 @@ metadata: } func TestVariableRefMaps(t *testing.T) { - th := makeTestHarness(t) + th := kusttest_test.MakeHarness(t) th.WriteK("/app/base", ` resources: - deployment.yaml @@ -1192,7 +1194,7 @@ metadata: } func TestVaribaleRefDifferentPrefix(t *testing.T) { - th := makeTestHarness(t) + th := kusttest_test.MakeHarness(t) th.WriteK("/app/base", ` namePrefix: base- resources: diff --git a/api/testutils/kusttest/harness.go b/api/testutils/kusttest/harness.go new file mode 100644 index 000000000..cdeb1c347 --- /dev/null +++ b/api/testutils/kusttest/harness.go @@ -0,0 +1,126 @@ +// Copyright 2019 The Kubernetes Authors. +// SPDX-License-Identifier: Apache-2.0 + +package kusttest_test + +import ( + "path/filepath" + "strings" + "testing" + + "sigs.k8s.io/kustomize/api/filesys" + "sigs.k8s.io/kustomize/api/konfig" + "sigs.k8s.io/kustomize/api/konfig/builtinpluginconsts" + "sigs.k8s.io/kustomize/api/krusty" + "sigs.k8s.io/kustomize/api/resmap" + "sigs.k8s.io/kustomize/api/types" +) + +// Harness manages a kustomize environment for tests. +type Harness struct { + t *testing.T + fSys filesys.FileSystem +} + +func MakeHarness(t *testing.T) Harness { + return MakeHarnessWithFs(t, filesys.MakeFsInMemory()) +} + +func MakeHarnessWithFs( + t *testing.T, fSys filesys.FileSystem) Harness { + return Harness{ + t: t, + fSys: fSys, + } +} + +func (th Harness) GetT() *testing.T { + return th.t +} + +func (th Harness) GetFSys() filesys.FileSystem { + return th.fSys +} + +func (th Harness) WriteK(path string, content string) { + th.fSys.WriteFile( + filepath.Join( + path, + konfig.DefaultKustomizationFileName()), []byte(` +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization +`+content)) +} + +func (th Harness) WriteF(path string, content string) { + th.fSys.WriteFile(path, []byte(content)) +} + +func (th Harness) MakeDefaultOptions() krusty.Options { + return th.MakeOptionsPluginsDisabled() +} + +// This has no impact on Builtin plugins, as they are always enabled. +func (th Harness) MakeOptionsPluginsDisabled() krusty.Options { + return krusty.Options{ + LoadRestrictions: types.LoadRestrictionsRootOnly, + PluginConfig: konfig.DisabledPluginConfig(), + } +} + +// Enables use of non-builtin plugins. +func (th Harness) MakeOptionsPluginsEnabled() krusty.Options { + c, err := konfig.EnabledPluginConfig() + 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) + } + return krusty.Options{ + LoadRestrictions: types.LoadRestrictionsRootOnly, + PluginConfig: c, + } +} + +// Run, failing on error. +func (th Harness) Run(path string, o krusty.Options) resmap.ResMap { + m, err := krusty.MakeKustomizer(th.fSys, &o).Run(path) + if err != nil { + th.t.Fatal(err) + } + return m +} + +// Run, failing if there is no error. +func (th Harness) RunWithErr(path string, o krusty.Options) error { + _, err := krusty.MakeKustomizer(th.fSys, &o).Run(path) + if err == nil { + th.t.Fatalf("expected error") + } + return err +} + +func (th Harness) WriteLegacyConfigs(fName string) { + m := builtinpluginconsts.GetDefaultFieldSpecsAsMap() + var content []byte + for _, tCfg := range m { + content = append(content, []byte(tCfg)...) + } + err := th.fSys.WriteFile(fName, content) + if err != nil { + th.t.Fatalf("unable to add file %s", fName) + } +} + +func (th Harness) AssertActualEqualsExpected( + m resmap.ResMap, expected string) { + th.AssertActualEqualsExpectedWithTweak(m, nil, expected) +} + +func (th Harness) AssertActualEqualsExpectedWithTweak( + m resmap.ResMap, tweaker func([]byte) []byte, expected string) { + assertActualEqualsExpectedWithTweak(th, m, tweaker, expected) +} diff --git a/api/testutils/kusttest/harnessenhanced.go b/api/testutils/kusttest/harnessenhanced.go new file mode 100644 index 000000000..a597064a0 --- /dev/null +++ b/api/testutils/kusttest/harnessenhanced.go @@ -0,0 +1,104 @@ +// Copyright 2019 The Kubernetes Authors. +// SPDX-License-Identifier: Apache-2.0 + +package kusttest_test + +import ( + "testing" + + "sigs.k8s.io/kustomize/api/filesys" + + "sigs.k8s.io/kustomize/api/internal/k8sdeps/transformer" + "sigs.k8s.io/kustomize/api/internal/loadertest" + pLdr "sigs.k8s.io/kustomize/api/internal/plugins/loader" + "sigs.k8s.io/kustomize/api/k8sdeps/kunstruct" + "sigs.k8s.io/kustomize/api/konfig" + fLdr "sigs.k8s.io/kustomize/api/loader" + "sigs.k8s.io/kustomize/api/resmap" + "sigs.k8s.io/kustomize/api/resource" + valtest_test "sigs.k8s.io/kustomize/api/testutils/valtest" +) + +// HarnessEnhanced manages a full plugin environment for tests. +// TODO: get rid of this. Combine Harness and PluginTestEnv. +type HarnessEnhanced struct { + Harness + rf *resmap.Factory + ldr loadertest.FakeLoader + pl *pLdr.Loader +} + +func MakeHarnessEnhanced( + t *testing.T, path string) *HarnessEnhanced { + pc, err := konfig.EnabledPluginConfig() + if err != nil { + t.Fatal(err) + } + fSys := filesys.MakeFsInMemory() + rf := resmap.NewFactory( + resource.NewFactory(kunstruct.NewKunstructuredFactoryImpl()), + transformer.NewFactoryImpl()) + return &HarnessEnhanced{ + Harness: Harness{t: t, fSys: fSys}, + rf: rf, + ldr: loadertest.NewFakeLoaderWithRestrictor( + fLdr.RestrictionRootOnly, fSys, path), + pl: pLdr.NewLoader(pc, rf)} +} + +func (th *HarnessEnhanced) LoadAndRunGenerator( + config string) resmap.ResMap { + res, err := th.rf.RF().FromBytes([]byte(config)) + if err != nil { + th.t.Fatalf("Err: %v", err) + } + g, err := th.pl.LoadGenerator( + th.ldr, valtest_test.MakeFakeValidator(), res) + if err != nil { + th.t.Fatalf("Err: %v", err) + } + rm, err := g.Generate() + if err != nil { + th.t.Fatalf("Err: %v", err) + } + return rm +} + +func (th *HarnessEnhanced) LoadAndRunTransformer( + config, input string) resmap.ResMap { + resMap, err := th.RunTransformer(config, input) + if err != nil { + th.t.Fatalf("Err: %v", err) + } + return resMap +} + +func (th *HarnessEnhanced) ErrorFromLoadAndRunTransformer( + config, input string) error { + _, err := th.RunTransformer(config, input) + return err +} + +func (th *HarnessEnhanced) RunTransformer( + config, input string) (resmap.ResMap, error) { + resMap, err := th.rf.NewResMapFromBytes([]byte(input)) + if err != nil { + th.t.Fatalf("Err: %v", err) + } + return th.RunTransformerFromResMap(config, resMap) +} + +func (th *HarnessEnhanced) RunTransformerFromResMap( + config string, resMap resmap.ResMap) (resmap.ResMap, error) { + transConfig, err := th.rf.RF().FromBytes([]byte(config)) + if err != nil { + th.t.Fatalf("Err: %v", err) + } + g, err := th.pl.LoadTransformer( + th.ldr, valtest_test.MakeFakeValidator(), transConfig) + if err != nil { + return nil, err + } + err = g.Transform(resMap) + return resMap, err +} diff --git a/api/testutils/kusttest/hasgett.go b/api/testutils/kusttest/hasgett.go new file mode 100644 index 000000000..22df9b245 --- /dev/null +++ b/api/testutils/kusttest/hasgett.go @@ -0,0 +1,104 @@ +// Copyright 2019 The Kubernetes Authors. +// SPDX-License-Identifier: Apache-2.0 + +package kusttest_test + +import ( + "fmt" + "strings" + "testing" + + "sigs.k8s.io/kustomize/api/resmap" +) + +type hasGetT interface { + GetT() *testing.T +} + +func assertActualEqualsExpectedWithTweak( + ht hasGetT, + m resmap.ResMap, + tweaker func([]byte) []byte, expected string) { + if m == nil { + ht.GetT().Fatalf("Map should not be nil.") + } + // Ignore leading linefeed in expected value + // to ease readability of tests. + if len(expected) > 0 && expected[0] == 10 { + expected = expected[1:] + } + actual, err := m.AsYaml() + if err != nil { + ht.GetT().Fatalf("Unexpected err: %v", err) + } + if tweaker != nil { + actual = tweaker(actual) + } + if string(actual) != expected { + reportDiffAndFail(ht.GetT(), actual, expected) + } +} + +// Pretty printing of file differences. +func reportDiffAndFail( + t *testing.T, actual []byte, expected string) { + sE, maxLen := convertToArray(expected) + sA, _ := convertToArray(string(actual)) + fmt.Println("===== ACTUAL BEGIN ========================================") + fmt.Print(string(actual)) + fmt.Println("===== ACTUAL END ==========================================") + format := fmt.Sprintf("%%s %%-%ds %%s\n", maxLen+4) + limit := 0 + if len(sE) < len(sA) { + limit = len(sE) + } else { + limit = len(sA) + } + fmt.Printf(format, " ", "EXPECTED", "ACTUAL") + fmt.Printf(format, " ", "--------", "------") + for i := 0; i < limit; i++ { + fmt.Printf(format, hint(sE[i], sA[i]), sE[i], sA[i]) + } + if len(sE) < len(sA) { + for i := len(sE); i < len(sA); i++ { + fmt.Printf(format, "X", "", sA[i]) + } + } else { + for i := len(sA); i < len(sE); i++ { + fmt.Printf(format, "X", sE[i], "") + } + } + t.Fatalf("Expected not equal to actual") +} + +func hint(a, b string) string { + if a == b { + return " " + } + return "X" +} + +func convertToArray(x string) ([]string, int) { + a := strings.Split(strings.TrimSuffix(x, "\n"), "\n") + maxLen := 0 + for i, v := range a { + z := tabToSpace(v) + if len(z) > maxLen { + maxLen = len(z) + } + a[i] = z + } + return a, maxLen +} + +func tabToSpace(input string) string { + var result []string + for _, i := range input { + if i == 9 { + result = append(result, " ") + } else { + result = append(result, string(i)) + } + } + return strings.Join(result, "") +} diff --git a/api/testutils/kusttest/kusttestharness.go b/api/testutils/kusttest/kusttestharness.go deleted file mode 100644 index fbaf9c125..000000000 --- a/api/testutils/kusttest/kusttestharness.go +++ /dev/null @@ -1,267 +0,0 @@ -// Copyright 2019 The Kubernetes Authors. -// SPDX-License-Identifier: Apache-2.0 - -package kusttest_test - -import ( - "fmt" - "path/filepath" - "strings" - "testing" - - "sigs.k8s.io/kustomize/api/internal/k8sdeps/transformer" - "sigs.k8s.io/kustomize/api/internal/loadertest" - pLdr "sigs.k8s.io/kustomize/api/internal/plugins/loader" - "sigs.k8s.io/kustomize/api/internal/target" - "sigs.k8s.io/kustomize/api/k8sdeps/kunstruct" - "sigs.k8s.io/kustomize/api/konfig" - "sigs.k8s.io/kustomize/api/konfig/builtinpluginconsts" - fLdr "sigs.k8s.io/kustomize/api/loader" - "sigs.k8s.io/kustomize/api/resmap" - "sigs.k8s.io/kustomize/api/resource" - valtest_test "sigs.k8s.io/kustomize/api/testutils/valtest" - "sigs.k8s.io/kustomize/api/types" -) - -// KustTestHarness is an environment for running a kustomize build, -// aka a run of MakeCustomizedResMap. It holds a file loader -// presumably primed with an in-memory file system, a plugin -// loader, factories to make what it needs, etc. -type KustTestHarness struct { - t *testing.T - rf *resmap.Factory - ldr loadertest.FakeLoader - pl *pLdr.Loader -} - -func NewKustTestHarness(t *testing.T, path string) *KustTestHarness { - return NewKustTestHarnessFull( - t, path, fLdr.RestrictionRootOnly, konfig.DisabledPluginConfig()) -} - -func NewKustTestHarnessAllowPlugins(t *testing.T, path string) *KustTestHarness { - c, err := konfig.EnabledPluginConfig() - if err != nil { - t.Fatal(err) - } - return NewKustTestHarnessFull(t, path, fLdr.RestrictionRootOnly, c) -} - -func NewKustTestHarnessNoLoadRestrictor(t *testing.T, path string) *KustTestHarness { - return NewKustTestHarnessFull( - t, path, fLdr.RestrictionNone, konfig.DisabledPluginConfig()) -} - -func NewKustTestHarnessFull( - t *testing.T, path string, - lr fLdr.LoadRestrictorFunc, pc *types.PluginConfig) *KustTestHarness { - rf := resmap.NewFactory(resource.NewFactory( - kunstruct.NewKunstructuredFactoryImpl()), transformer.NewFactoryImpl()) - return &KustTestHarness{ - t: t, - rf: rf, - ldr: loadertest.NewFakeLoaderWithRestrictor(lr, path), - pl: pLdr.NewLoader(pc, rf)} -} - -func (th *KustTestHarness) MakeKustTarget() *target.KustTarget { - kt := target.NewKustTarget( - th.ldr, valtest_test.MakeFakeValidator(), th.rf, - transformer.NewFactoryImpl(), th.pl) - err := kt.Load() - if err != nil { - th.t.Fatalf("Unexpected construction error %v", err) - } - return kt -} - -func (th *KustTestHarness) WriteF(dir string, content string) { - err := th.ldr.AddFile(dir, []byte(content)) - if err != nil { - th.t.Fatalf("failed write to %s; %v", dir, err) - } -} - -func (th *KustTestHarness) WriteK(dir string, content string) { - th.WriteF( - filepath.Join( - dir, - konfig.DefaultKustomizationFileName()), ` -apiVersion: kustomize.config.k8s.io/v1beta1 -kind: Kustomization -`+content) -} - -func (th *KustTestHarness) RF() *resource.Factory { - return th.rf.RF() -} - -func (th *KustTestHarness) FromMap(m map[string]interface{}) *resource.Resource { - return th.rf.RF().FromMap(m) -} - -func (th *KustTestHarness) FromMapAndOption( - m map[string]interface{}, - args *types.GeneratorArgs, - option *types.GeneratorOptions) *resource.Resource { - return th.rf.RF().FromMapAndOption(m, args, option) -} - -func (th *KustTestHarness) WriteDefaultConfigs(fName string) { - m := builtinpluginconsts.GetDefaultFieldSpecsAsMap() - var content []byte - for _, tCfg := range m { - content = append(content, []byte(tCfg)...) - } - err := th.ldr.AddFile(fName, content) - if err != nil { - th.t.Fatalf("unable to add file %s", fName) - } -} - -func (th *KustTestHarness) LoadAndRunGenerator( - config string) resmap.ResMap { - res, err := th.rf.RF().FromBytes([]byte(config)) - if err != nil { - th.t.Fatalf("Err: %v", err) - } - g, err := th.pl.LoadGenerator( - th.ldr, valtest_test.MakeFakeValidator(), res) - if err != nil { - th.t.Fatalf("Err: %v", err) - } - rm, err := g.Generate() - if err != nil { - th.t.Fatalf("Err: %v", err) - } - return rm -} - -func (th *KustTestHarness) LoadAndRunTransformer( - config, input string) resmap.ResMap { - resMap, err := th.RunTransformer(config, input) - if err != nil { - th.t.Fatalf("Err: %v", err) - } - return resMap -} - -func (th *KustTestHarness) ErrorFromLoadAndRunTransformer( - config, input string) error { - _, err := th.RunTransformer(config, input) - return err -} - -func (th *KustTestHarness) RunTransformer( - config, input string) (resmap.ResMap, error) { - resMap, err := th.rf.NewResMapFromBytes([]byte(input)) - if err != nil { - th.t.Fatalf("Err: %v", err) - } - return th.RunTransformerFromResMap(config, resMap) -} - -func (th *KustTestHarness) RunTransformerFromResMap( - config string, resMap resmap.ResMap) (resmap.ResMap, error) { - transConfig, err := th.rf.RF().FromBytes([]byte(config)) - if err != nil { - th.t.Fatalf("Err: %v", err) - } - g, err := th.pl.LoadTransformer( - th.ldr, valtest_test.MakeFakeValidator(), transConfig) - if err != nil { - return nil, err - } - err = g.Transform(resMap) - return resMap, err -} - -func tabToSpace(input string) string { - var result []string - for _, i := range input { - if i == 9 { - result = append(result, " ") - } else { - result = append(result, string(i)) - } - } - return strings.Join(result, "") -} - -func convertToArray(x string) ([]string, int) { - a := strings.Split(strings.TrimSuffix(x, "\n"), "\n") - maxLen := 0 - for i, v := range a { - z := tabToSpace(v) - if len(z) > maxLen { - maxLen = len(z) - } - a[i] = z - } - return a, maxLen -} - -func hint(a, b string) string { - if a == b { - return " " - } - return "X" -} - -func (th *KustTestHarness) AssertActualEqualsExpected( - m resmap.ResMap, expected string) { - th.AssertActualEqualsExpectedWithTweak(m, nil, expected) -} - -func (th *KustTestHarness) AssertActualEqualsExpectedWithTweak( - m resmap.ResMap, tweaker func([]byte) []byte, expected string) { - if m == nil { - th.t.Fatalf("Map should not be nil.") - } - // Ignore leading linefeed in expected value - // to ease readability of tests. - if len(expected) > 0 && expected[0] == 10 { - expected = expected[1:] - } - actual, err := m.AsYaml() - if err != nil { - th.t.Fatalf("Unexpected err: %v", err) - } - if tweaker != nil { - actual = tweaker(actual) - } - if string(actual) != expected { - th.reportDiffAndFail(actual, expected) - } -} - -// Pretty printing of file differences. -func (th *KustTestHarness) reportDiffAndFail(actual []byte, expected string) { - sE, maxLen := convertToArray(expected) - sA, _ := convertToArray(string(actual)) - fmt.Println("===== ACTUAL BEGIN ========================================") - fmt.Print(string(actual)) - fmt.Println("===== ACTUAL END ==========================================") - format := fmt.Sprintf("%%s %%-%ds %%s\n", maxLen+4) - limit := 0 - if len(sE) < len(sA) { - limit = len(sE) - } else { - limit = len(sA) - } - fmt.Printf(format, " ", "EXPECTED", "ACTUAL") - fmt.Printf(format, " ", "--------", "------") - for i := 0; i < limit; i++ { - fmt.Printf(format, hint(sE[i], sA[i]), sE[i], sA[i]) - } - if len(sE) < len(sA) { - for i := len(sE); i < len(sA); i++ { - fmt.Printf(format, "X", "", sA[i]) - } - } else { - for i := len(sA); i < len(sE); i++ { - fmt.Printf(format, "X", sE[i], "") - } - } - th.t.Fatalf("Expected not equal to actual") -} diff --git a/hack/imports.sh b/hack/imports.sh index a9b834246..cc2668f5a 100755 --- a/hack/imports.sh +++ b/hack/imports.sh @@ -1,4 +1,4 @@ -for f in $(find ./ -name '*.go'); do +for f in $(find $1 -name '*.go'); do echo $f # go run go.coder.com/go-tools/cmd/goimports ~/gopath/bin/goimports -w $f diff --git a/plugin/builtin/annotationstransformer/AnnotationsTransformer_test.go b/plugin/builtin/annotationstransformer/AnnotationsTransformer_test.go index 0c74cd3ed..28ff5121f 100644 --- a/plugin/builtin/annotationstransformer/AnnotationsTransformer_test.go +++ b/plugin/builtin/annotationstransformer/AnnotationsTransformer_test.go @@ -16,7 +16,7 @@ func TestAnnotationsTransformer(t *testing.T) { tc.BuildGoPlugin( "builtin", "", "AnnotationsTransformer") - th := kusttest_test.NewKustTestHarnessAllowPlugins(t, "/app") + th := kusttest_test.MakeHarnessEnhanced(t, "/app") rm := th.LoadAndRunTransformer(` apiVersion: builtin diff --git a/plugin/builtin/configmapgenerator/ConfigMapGenerator_test.go b/plugin/builtin/configmapgenerator/ConfigMapGenerator_test.go index 7524e5722..6670c062c 100644 --- a/plugin/builtin/configmapgenerator/ConfigMapGenerator_test.go +++ b/plugin/builtin/configmapgenerator/ConfigMapGenerator_test.go @@ -16,7 +16,7 @@ func TestConfigMapGenerator(t *testing.T) { tc.BuildGoPlugin( "builtin", "", "ConfigMapGenerator") - th := kusttest_test.NewKustTestHarnessAllowPlugins(t, "/app") + th := kusttest_test.MakeHarnessEnhanced(t, "/app") th.WriteF("/app/devops.env", ` SERVICE_PORT=32 diff --git a/plugin/builtin/hashtransformer/HashTransformer_test.go b/plugin/builtin/hashtransformer/HashTransformer_test.go index 7f016f268..68f1f4c48 100644 --- a/plugin/builtin/hashtransformer/HashTransformer_test.go +++ b/plugin/builtin/hashtransformer/HashTransformer_test.go @@ -16,7 +16,7 @@ func TestHashTransformer(t *testing.T) { tc.BuildGoPlugin( "builtin", "", "HashTransformer") - th := kusttest_test.NewKustTestHarnessAllowPlugins(t, "/app") + th := kusttest_test.MakeHarnessEnhanced(t, "/app") rm := th.LoadAndRunTransformer(` apiVersion: builtin diff --git a/plugin/builtin/imagetagtransformer/ImageTagTransformer_test.go b/plugin/builtin/imagetagtransformer/ImageTagTransformer_test.go index 1234dd4ed..85096d5f4 100644 --- a/plugin/builtin/imagetagtransformer/ImageTagTransformer_test.go +++ b/plugin/builtin/imagetagtransformer/ImageTagTransformer_test.go @@ -16,7 +16,7 @@ func TestImageTagTransformerNewTag(t *testing.T) { tc.BuildGoPlugin( "builtin", "", "ImageTagTransformer") - th := kusttest_test.NewKustTestHarnessAllowPlugins(t, "/app") + th := kusttest_test.MakeHarnessEnhanced(t, "/app") rm := th.LoadAndRunTransformer(` apiVersion: builtin @@ -87,7 +87,7 @@ func TestImageTagTransformerNewImage(t *testing.T) { tc.BuildGoPlugin( "builtin", "", "ImageTagTransformer") - th := kusttest_test.NewKustTestHarnessAllowPlugins(t, "/app") + th := kusttest_test.MakeHarnessEnhanced(t, "/app") rm := th.LoadAndRunTransformer(` apiVersion: builtin @@ -159,7 +159,7 @@ func TestImageTagTransformerNewImageAndTag(t *testing.T) { tc.BuildGoPlugin( "builtin", "", "ImageTagTransformer") - th := kusttest_test.NewKustTestHarnessAllowPlugins(t, "/app") + th := kusttest_test.MakeHarnessEnhanced(t, "/app") rm := th.LoadAndRunTransformer(` apiVersion: builtin @@ -232,7 +232,7 @@ func TestImageTagTransformerNewDigest(t *testing.T) { tc.BuildGoPlugin( "builtin", "", "ImageTagTransformer") - th := kusttest_test.NewKustTestHarnessAllowPlugins(t, "/app") + th := kusttest_test.MakeHarnessEnhanced(t, "/app") rm := th.LoadAndRunTransformer(` apiVersion: builtin @@ -304,7 +304,7 @@ func TestImageTagTransformerNewImageAndDigest(t *testing.T) { tc.BuildGoPlugin( "builtin", "", "ImageTagTransformer") - th := kusttest_test.NewKustTestHarnessAllowPlugins(t, "/app") + th := kusttest_test.MakeHarnessEnhanced(t, "/app") rm := th.LoadAndRunTransformer(` apiVersion: builtin @@ -376,7 +376,7 @@ func TestImageTagTransformerEmptyContainers(t *testing.T) { tc.BuildGoPlugin( "builtin", "", "ImageTagTransformer") - th := kusttest_test.NewKustTestHarnessAllowPlugins(t, "/app") + th := kusttest_test.MakeHarnessEnhanced(t, "/app") rm := th.LoadAndRunTransformer(` apiVersion: builtin diff --git a/plugin/builtin/inventorytransformer/InventoryTransformer_test.go b/plugin/builtin/inventorytransformer/InventoryTransformer_test.go index 27e301bef..9c12f6ff7 100644 --- a/plugin/builtin/inventorytransformer/InventoryTransformer_test.go +++ b/plugin/builtin/inventorytransformer/InventoryTransformer_test.go @@ -64,7 +64,7 @@ func TestInventoryTransformerCollect(t *testing.T) { tc.BuildGoPlugin( "builtin", "", "InventoryTransformer") - th := kusttest_test.NewKustTestHarnessAllowPlugins(t, "/app") + th := kusttest_test.MakeHarnessEnhanced(t, "/app") rm := th.LoadAndRunTransformer(` apiVersion: builtin @@ -85,7 +85,7 @@ func TestInventoryTransformerIgnore(t *testing.T) { tc.BuildGoPlugin( "builtin", "", "InventoryTransformer") - th := kusttest_test.NewKustTestHarnessAllowPlugins(t, "/app") + th := kusttest_test.MakeHarnessEnhanced(t, "/app") rm := th.LoadAndRunTransformer(` apiVersion: builtin @@ -106,7 +106,7 @@ func TestInventoryTransformerDefaultPolicy(t *testing.T) { tc.BuildGoPlugin( "builtin", "", "InventoryTransformer") - th := kusttest_test.NewKustTestHarnessAllowPlugins(t, "/app") + th := kusttest_test.MakeHarnessEnhanced(t, "/app") rm := th.LoadAndRunTransformer(` apiVersion: builtin diff --git a/plugin/builtin/labeltransformer/LabelTransformer_test.go b/plugin/builtin/labeltransformer/LabelTransformer_test.go index 305fc1c78..aa778f091 100644 --- a/plugin/builtin/labeltransformer/LabelTransformer_test.go +++ b/plugin/builtin/labeltransformer/LabelTransformer_test.go @@ -16,7 +16,7 @@ func TestLabelTransformer(t *testing.T) { tc.BuildGoPlugin( "builtin", "", "LabelTransformer") - th := kusttest_test.NewKustTestHarnessAllowPlugins(t, "/app") + th := kusttest_test.MakeHarnessEnhanced(t, "/app") rm := th.LoadAndRunTransformer(` apiVersion: builtin diff --git a/plugin/builtin/legacyordertransformer/LegacyOrderTransformer_test.go b/plugin/builtin/legacyordertransformer/LegacyOrderTransformer_test.go index 5c283bb76..a644e0c19 100644 --- a/plugin/builtin/legacyordertransformer/LegacyOrderTransformer_test.go +++ b/plugin/builtin/legacyordertransformer/LegacyOrderTransformer_test.go @@ -16,7 +16,7 @@ func TestLegacyOrderTransformer(t *testing.T) { tc.BuildGoPlugin( "builtin", "", "LegacyOrderTransformer") - th := kusttest_test.NewKustTestHarnessAllowPlugins(t, "/app") + th := kusttest_test.MakeHarnessEnhanced(t, "/app") rm := th.LoadAndRunTransformer(` apiVersion: builtin kind: LegacyOrderTransformer diff --git a/plugin/builtin/namespacetransformer/NamespaceTransformer_test.go b/plugin/builtin/namespacetransformer/NamespaceTransformer_test.go index a42e1a2c9..9a62606fa 100644 --- a/plugin/builtin/namespacetransformer/NamespaceTransformer_test.go +++ b/plugin/builtin/namespacetransformer/NamespaceTransformer_test.go @@ -17,7 +17,7 @@ func TestNamespaceTransformer1(t *testing.T) { tc.BuildGoPlugin( "builtin", "", "NamespaceTransformer") - th := kusttest_test.NewKustTestHarnessAllowPlugins(t, "/app") + th := kusttest_test.MakeHarnessEnhanced(t, "/app") rm := th.LoadAndRunTransformer(` apiVersion: builtin @@ -195,7 +195,7 @@ func TestNamespaceTransformerClusterLevelKinds(t *testing.T) { tc.BuildGoPlugin( "builtin", "", "NamespaceTransformer") - th := kusttest_test.NewKustTestHarnessAllowPlugins(t, "/app") + th := kusttest_test.MakeHarnessEnhanced(t, "/app") const noChangeExpected = ` apiVersion: v1 @@ -246,7 +246,7 @@ func TestNamespaceTransformerObjectConflict(t *testing.T) { tc.BuildGoPlugin( "builtin", "", "NamespaceTransformer") - th := kusttest_test.NewKustTestHarnessAllowPlugins(t, "/app") + th := kusttest_test.MakeHarnessEnhanced(t, "/app") err := th.ErrorFromLoadAndRunTransformer(` apiVersion: builtin diff --git a/plugin/builtin/patchjson6902transformer/PatchJson6902Transformer_test.go b/plugin/builtin/patchjson6902transformer/PatchJson6902Transformer_test.go index 7b4110e9f..e328bd736 100644 --- a/plugin/builtin/patchjson6902transformer/PatchJson6902Transformer_test.go +++ b/plugin/builtin/patchjson6902transformer/PatchJson6902Transformer_test.go @@ -34,7 +34,7 @@ func TestPatchJson6902TransformerMissingFile(t *testing.T) { tc.BuildGoPlugin( "builtin", "", "PatchJson6902Transformer") - th := kusttest_test.NewKustTestHarnessAllowPlugins(t, "/app") + th := kusttest_test.MakeHarnessEnhanced(t, "/app") _, err := th.RunTransformer(` apiVersion: builtin @@ -63,7 +63,7 @@ func TestBadPatchJson6902Transformer(t *testing.T) { tc.BuildGoPlugin( "builtin", "", "PatchJson6902Transformer") - th := kusttest_test.NewKustTestHarnessAllowPlugins(t, "/app") + th := kusttest_test.MakeHarnessEnhanced(t, "/app") _, err := th.RunTransformer(` apiVersion: builtin @@ -92,7 +92,7 @@ func TestBothEmptyJson6902Transformer(t *testing.T) { tc.BuildGoPlugin( "builtin", "", "PatchJson6902Transformer") - th := kusttest_test.NewKustTestHarnessAllowPlugins(t, "/app") + th := kusttest_test.MakeHarnessEnhanced(t, "/app") _, err := th.RunTransformer(` apiVersion: builtin @@ -120,7 +120,7 @@ func TestBothSpecifiedJson6902Transformer(t *testing.T) { tc.BuildGoPlugin( "builtin", "", "PatchJson6902Transformer") - th := kusttest_test.NewKustTestHarnessAllowPlugins(t, "/app") + th := kusttest_test.MakeHarnessEnhanced(t, "/app") th.WriteF("/app/jsonpatch.json", `[ {"op": "replace", "path": "/spec/template/spec/containers/0/name", "value": "my-nginx"}, @@ -156,7 +156,7 @@ func TestPatchJson6902TransformerFromJsonFile(t *testing.T) { tc.BuildGoPlugin( "builtin", "", "PatchJson6902Transformer") - th := kusttest_test.NewKustTestHarnessAllowPlugins(t, "/app") + th := kusttest_test.MakeHarnessEnhanced(t, "/app") th.WriteF("/app/jsonpatch.json", `[ {"op": "replace", "path": "/spec/template/spec/containers/0/name", "value": "my-nginx"}, @@ -206,7 +206,7 @@ func TestPatchJson6902TransformerFromYamlFile(t *testing.T) { tc.BuildGoPlugin( "builtin", "", "PatchJson6902Transformer") - th := kusttest_test.NewKustTestHarnessAllowPlugins(t, "/app") + th := kusttest_test.MakeHarnessEnhanced(t, "/app") th.WriteF("/app/jsonpatch.json", ` - op: add @@ -256,7 +256,7 @@ func TestPatchJson6902TransformerWithInlineJSON(t *testing.T) { tc.BuildGoPlugin( "builtin", "", "PatchJson6902Transformer") - th := kusttest_test.NewKustTestHarnessAllowPlugins(t, "/app") + th := kusttest_test.MakeHarnessEnhanced(t, "/app") rm := th.LoadAndRunTransformer(` apiVersion: builtin @@ -297,7 +297,7 @@ func TestPatchJson6902TransformerWithInlineYAML(t *testing.T) { tc.BuildGoPlugin( "builtin", "", "PatchJson6902Transformer") - th := kusttest_test.NewKustTestHarnessAllowPlugins(t, "/app") + th := kusttest_test.MakeHarnessEnhanced(t, "/app") rm := th.LoadAndRunTransformer(` apiVersion: builtin diff --git a/plugin/builtin/patchstrategicmergetransformer/PatchStrategicMergeTransformer_test.go b/plugin/builtin/patchstrategicmergetransformer/PatchStrategicMergeTransformer_test.go index 585595f35..751397887 100644 --- a/plugin/builtin/patchstrategicmergetransformer/PatchStrategicMergeTransformer_test.go +++ b/plugin/builtin/patchstrategicmergetransformer/PatchStrategicMergeTransformer_test.go @@ -63,7 +63,7 @@ func TestPatchStrategicMergeTransformerMissingFile(t *testing.T) { tc.BuildGoPlugin( "builtin", "", "PatchStrategicMergeTransformer") - th := kusttest_test.NewKustTestHarnessAllowPlugins(t, "/app") + th := kusttest_test.MakeHarnessEnhanced(t, "/app") _, err := th.RunTransformer(` apiVersion: builtin @@ -91,7 +91,7 @@ func TestBadPatchStrategicMergeTransformer(t *testing.T) { tc.BuildGoPlugin( "builtin", "", "PatchStrategicMergeTransformer") - th := kusttest_test.NewKustTestHarnessAllowPlugins(t, "/app") + th := kusttest_test.MakeHarnessEnhanced(t, "/app") _, err := th.RunTransformer(` apiVersion: builtin @@ -116,7 +116,7 @@ func TestBothEmptyPatchStrategicMergeTransformer(t *testing.T) { tc.BuildGoPlugin( "builtin", "", "PatchStrategicMergeTransformer") - th := kusttest_test.NewKustTestHarnessAllowPlugins(t, "/app") + th := kusttest_test.MakeHarnessEnhanced(t, "/app") _, err := th.RunTransformer(` apiVersion: builtin @@ -139,7 +139,7 @@ func TestPatchStrategicMergeTransformerFromFiles(t *testing.T) { tc.BuildGoPlugin( "builtin", "", "PatchStrategicMergeTransformer") - th := kusttest_test.NewKustTestHarnessAllowPlugins(t, "/app") + th := kusttest_test.MakeHarnessEnhanced(t, "/app") th.WriteF("/app/patch.yaml", ` apiVersion: apps/v1 @@ -189,7 +189,7 @@ func TestPatchStrategicMergeTransformerWithInlineJSON(t *testing.T) { tc.BuildGoPlugin( "builtin", "", "PatchStrategicMergeTransformer") - th := kusttest_test.NewKustTestHarnessAllowPlugins(t, "/app") + th := kusttest_test.MakeHarnessEnhanced(t, "/app") rm := th.LoadAndRunTransformer(` apiVersion: builtin @@ -224,7 +224,7 @@ func TestPatchStrategicMergeTransformerWithInlineYAML(t *testing.T) { tc.BuildGoPlugin( "builtin", "", "PatchStrategicMergeTransformer") - th := kusttest_test.NewKustTestHarnessAllowPlugins(t, "/app") + th := kusttest_test.MakeHarnessEnhanced(t, "/app") rm := th.LoadAndRunTransformer(` apiVersion: builtin @@ -276,7 +276,7 @@ func TestPatchStrategicMergeTransformerMultiplePatches(t *testing.T) { tc.BuildGoPlugin( "builtin", "", "PatchStrategicMergeTransformer") - th := kusttest_test.NewKustTestHarnessAllowPlugins(t, "/app") + th := kusttest_test.MakeHarnessEnhanced(t, "/app") th.WriteF("/app/patch1.yaml", ` apiVersion: apps/v1 @@ -353,7 +353,7 @@ func TestStrategicMergeTransformerMultiplePatchesWithConflicts(t *testing.T) { tc.BuildGoPlugin( "builtin", "", "PatchStrategicMergeTransformer") - th := kusttest_test.NewKustTestHarnessAllowPlugins(t, "/app") + th := kusttest_test.MakeHarnessEnhanced(t, "/app") th.WriteF("/app/patch1.yaml", ` apiVersion: apps/v1 @@ -414,7 +414,7 @@ func TestStrategicMergeTransformerWrongNamespace(t *testing.T) { tc.BuildGoPlugin( "builtin", "", "PatchStrategicMergeTransformer") - th := kusttest_test.NewKustTestHarnessAllowPlugins(t, "/app") + th := kusttest_test.MakeHarnessEnhanced(t, "/app") th.WriteF("/app/patch.yaml", ` apiVersion: apps/v1 @@ -457,7 +457,7 @@ func TestStrategicMergeTransformerNoSchema(t *testing.T) { tc.BuildGoPlugin( "builtin", "", "PatchStrategicMergeTransformer") - th := kusttest_test.NewKustTestHarnessAllowPlugins(t, "/app") + th := kusttest_test.MakeHarnessEnhanced(t, "/app") th.WriteF("/app/patch.yaml", ` apiVersion: example.com/v1 @@ -497,7 +497,7 @@ func TestStrategicMergeTransformerNoSchemaMultiPatches(t *testing.T) { tc.BuildGoPlugin( "builtin", "", "PatchStrategicMergeTransformer") - th := kusttest_test.NewKustTestHarnessAllowPlugins(t, "/app") + th := kusttest_test.MakeHarnessEnhanced(t, "/app") th.WriteF("/app/patch1.yaml", ` apiVersion: example.com/v1 @@ -553,7 +553,7 @@ func TestStrategicMergeTransformerNoSchemaMultiPatchesWithConflict(t *testing.T) tc.BuildGoPlugin( "builtin", "", "PatchStrategicMergeTransformer") - th := kusttest_test.NewKustTestHarnessAllowPlugins(t, "/app") + th := kusttest_test.MakeHarnessEnhanced(t, "/app") th.WriteF("/app/patch1.yaml", ` apiVersion: example.com/v1 @@ -889,7 +889,7 @@ func TestSinglePatch(t *testing.T) { "builtin", "", "PatchStrategicMergeTransformer") for _, test := range tests { - th := kusttest_test.NewKustTestHarnessAllowPlugins(t, fmt.Sprintf("/%s", test.name)) + th := kusttest_test.MakeHarnessEnhanced(t, fmt.Sprintf("/%s", test.name)) th.WriteF(fmt.Sprintf("/%s/patch%d.yaml", test.name, 0), test.patch) if test.errorExpected { @@ -992,7 +992,7 @@ func TestMultiplePatches(t *testing.T) { "builtin", "", "PatchStrategicMergeTransformer") for _, test := range tests { - th := kusttest_test.NewKustTestHarnessAllowPlugins(t, fmt.Sprintf("/%s", test.name)) + th := kusttest_test.MakeHarnessEnhanced(t, fmt.Sprintf("/%s", test.name)) for idx, patch := range test.patch { th.WriteF(fmt.Sprintf("/%s/patch%d.yaml", test.name, idx), patch) } @@ -1123,7 +1123,7 @@ func TestMultiplePatchesWithConflict(t *testing.T) { "builtin", "", "PatchStrategicMergeTransformer") for _, test := range tests { - th := kusttest_test.NewKustTestHarnessAllowPlugins(t, fmt.Sprintf("/%s", test.name)) + th := kusttest_test.MakeHarnessEnhanced(t, fmt.Sprintf("/%s", test.name)) for idx, patch := range test.patch { th.WriteF(fmt.Sprintf("/%s/patch%d.yaml", test.name, idx), patch) } @@ -1232,7 +1232,7 @@ func TestMultipleNamespaces(t *testing.T) { "builtin", "", "PatchStrategicMergeTransformer") for _, test := range tests { - th := kusttest_test.NewKustTestHarnessAllowPlugins(t, fmt.Sprintf("/%s", test.name)) + th := kusttest_test.MakeHarnessEnhanced(t, fmt.Sprintf("/%s", test.name)) for idx, patch := range test.patch { th.WriteF(fmt.Sprintf("/%s/patch%d.yaml", test.name, idx), patch) } @@ -1254,7 +1254,7 @@ func TestPatchStrategicMergeTransformerPatchDelete(t *testing.T) { tc.BuildGoPlugin( "builtin", "", "PatchStrategicMergeTransformer") - th := kusttest_test.NewKustTestHarnessAllowPlugins(t, "/app") + th := kusttest_test.MakeHarnessEnhanced(t, "/app") th.WriteF("/app/patch.yaml", ` apiVersion: apps/v1 diff --git a/plugin/builtin/patchtransformer/PatchTransformer_test.go b/plugin/builtin/patchtransformer/PatchTransformer_test.go index b641cb74a..fe4b2e4b4 100644 --- a/plugin/builtin/patchtransformer/PatchTransformer_test.go +++ b/plugin/builtin/patchtransformer/PatchTransformer_test.go @@ -70,7 +70,7 @@ func TestPatchTransformerMissingFile(t *testing.T) { tc.BuildGoPlugin( "builtin", "", "PatchTransformer") - th := kusttest_test.NewKustTestHarnessAllowPlugins(t, "/app") + th := kusttest_test.MakeHarnessEnhanced(t, "/app") _, err := th.RunTransformer(` apiVersion: builtin @@ -94,7 +94,7 @@ func TestPatchTransformerBadPatch(t *testing.T) { tc.BuildGoPlugin( "builtin", "", "PatchTransformer") - th := kusttest_test.NewKustTestHarnessAllowPlugins(t, "/app") + th := kusttest_test.MakeHarnessEnhanced(t, "/app") _, err := th.RunTransformer(` apiVersion: builtin @@ -118,7 +118,7 @@ func TestPatchTransformerMissingSelector(t *testing.T) { tc.BuildGoPlugin( "builtin", "", "PatchTransformer") - th := kusttest_test.NewKustTestHarnessAllowPlugins(t, "/app") + th := kusttest_test.MakeHarnessEnhanced(t, "/app") _, err := th.RunTransformer(` apiVersion: builtin @@ -143,7 +143,7 @@ func TestPatchTransformerBothEmptyPathAndPatch(t *testing.T) { tc.BuildGoPlugin( "builtin", "", "PatchTransformer") - th := kusttest_test.NewKustTestHarnessAllowPlugins(t, "/app") + th := kusttest_test.MakeHarnessEnhanced(t, "/app") _, err := th.RunTransformer(` apiVersion: builtin @@ -166,7 +166,7 @@ func TestPatchTransformerBothNonEmptyPathAndPatch(t *testing.T) { tc.BuildGoPlugin( "builtin", "", "PatchTransformer") - th := kusttest_test.NewKustTestHarnessAllowPlugins(t, "/app") + th := kusttest_test.MakeHarnessEnhanced(t, "/app") _, err := th.RunTransformer(` apiVersion: builtin @@ -191,7 +191,7 @@ func TestPatchTransformerFromFiles(t *testing.T) { tc.BuildGoPlugin( "builtin", "", "PatchTransformer") - th := kusttest_test.NewKustTestHarnessAllowPlugins(t, "/app") + th := kusttest_test.MakeHarnessEnhanced(t, "/app") th.WriteF("/app/patch.yaml", ` apiVersion: apps/v1 @@ -273,7 +273,7 @@ func TestPatchTransformerWithInline(t *testing.T) { tc.BuildGoPlugin( "builtin", "", "PatchTransformer") - th := kusttest_test.NewKustTestHarnessAllowPlugins(t, "/app") + th := kusttest_test.MakeHarnessEnhanced(t, "/app") rm := th.LoadAndRunTransformer(` apiVersion: builtin diff --git a/plugin/builtin/prefixsuffixtransformer/PrefixSuffixTransformer_test.go b/plugin/builtin/prefixsuffixtransformer/PrefixSuffixTransformer_test.go index 9d9b091e4..d04447bac 100644 --- a/plugin/builtin/prefixsuffixtransformer/PrefixSuffixTransformer_test.go +++ b/plugin/builtin/prefixsuffixtransformer/PrefixSuffixTransformer_test.go @@ -16,7 +16,7 @@ func TestPrefixSuffixTransformer(t *testing.T) { tc.BuildGoPlugin( "builtin", "", "PrefixSuffixTransformer") - th := kusttest_test.NewKustTestHarnessAllowPlugins(t, "/app") + th := kusttest_test.MakeHarnessEnhanced(t, "/app") rm := th.LoadAndRunTransformer(` apiVersion: builtin kind: PrefixSuffixTransformer diff --git a/plugin/builtin/replicacounttransformer/ReplicaCountTransformer_test.go b/plugin/builtin/replicacounttransformer/ReplicaCountTransformer_test.go index a1bf59d17..375d60429 100644 --- a/plugin/builtin/replicacounttransformer/ReplicaCountTransformer_test.go +++ b/plugin/builtin/replicacounttransformer/ReplicaCountTransformer_test.go @@ -16,7 +16,7 @@ func TestReplicaCountTransformer(t *testing.T) { tc.BuildGoPlugin( "builtin", "", "ReplicaCountTransformer") - th := kusttest_test.NewKustTestHarnessAllowPlugins(t, "/app") + th := kusttest_test.MakeHarnessEnhanced(t, "/app") rm := th.LoadAndRunTransformer(` apiVersion: builtin @@ -158,7 +158,7 @@ func TestMatchesCurrentID(t *testing.T) { tc.BuildGoPlugin("builtin", "", "PrefixSuffixTransformer") tc.BuildGoPlugin("builtin", "", "ReplicaCountTransformer") - th := kusttest_test.NewKustTestHarnessAllowPlugins(t, "/app") + th := kusttest_test.MakeHarnessEnhanced(t, "/app") rm := th.LoadAndRunTransformer(` apiVersion: builtin @@ -203,7 +203,7 @@ func TestNoMatch(t *testing.T) { tc.BuildGoPlugin("builtin", "", "ReplicaCountTransformer") - th := kusttest_test.NewKustTestHarnessAllowPlugins(t, "/app") + th := kusttest_test.MakeHarnessEnhanced(t, "/app") err := th.ErrorFromLoadAndRunTransformer(` apiVersion: builtin diff --git a/plugin/builtin/secretgenerator/SecretGenerator_test.go b/plugin/builtin/secretgenerator/SecretGenerator_test.go index c4e00126c..9eda665e8 100644 --- a/plugin/builtin/secretgenerator/SecretGenerator_test.go +++ b/plugin/builtin/secretgenerator/SecretGenerator_test.go @@ -16,7 +16,7 @@ func TestSecretGenerator(t *testing.T) { tc.BuildGoPlugin( "builtin", "", "SecretGenerator") - th := kusttest_test.NewKustTestHarnessAllowPlugins(t, "/app") + th := kusttest_test.MakeHarnessEnhanced(t, "/app") th.WriteF("/app/a.env", ` ROUTER_PASSWORD=admin diff --git a/plugin/someteam.example.com/v1/bashedconfigmap/BashedConfigMap_test.go b/plugin/someteam.example.com/v1/bashedconfigmap/BashedConfigMap_test.go index 097fda8f3..32c458441 100644 --- a/plugin/someteam.example.com/v1/bashedconfigmap/BashedConfigMap_test.go +++ b/plugin/someteam.example.com/v1/bashedconfigmap/BashedConfigMap_test.go @@ -16,7 +16,7 @@ func TestBashedConfigMapPlugin(t *testing.T) { tc.PrepExecPlugin( "someteam.example.com", "v1", "BashedConfigMap") - th := kusttest_test.NewKustTestHarnessAllowPlugins(t, "/app") + th := kusttest_test.MakeHarnessEnhanced(t, "/app") m := th.LoadAndRunGenerator(` apiVersion: someteam.example.com/v1 diff --git a/plugin/someteam.example.com/v1/chartinflator/ChartInflator_test.go b/plugin/someteam.example.com/v1/chartinflator/ChartInflator_test.go index efb136a18..409ccaab4 100644 --- a/plugin/someteam.example.com/v1/chartinflator/ChartInflator_test.go +++ b/plugin/someteam.example.com/v1/chartinflator/ChartInflator_test.go @@ -25,7 +25,7 @@ func TestChartInflator(t *testing.T) { tc.PrepExecPlugin( "someteam.example.com", "v1", "ChartInflator") - th := kusttest_test.NewKustTestHarnessAllowPlugins(t, "/app") + th := kusttest_test.MakeHarnessEnhanced(t, "/app") m := th.LoadAndRunGenerator(` apiVersion: someteam.example.com/v1 diff --git a/plugin/someteam.example.com/v1/dateprefixer/DatePrefixer_test.go b/plugin/someteam.example.com/v1/dateprefixer/DatePrefixer_test.go index 05cf0d3b6..50a05e033 100644 --- a/plugin/someteam.example.com/v1/dateprefixer/DatePrefixer_test.go +++ b/plugin/someteam.example.com/v1/dateprefixer/DatePrefixer_test.go @@ -15,7 +15,7 @@ func TestDatePrefixerPlugin(t *testing.T) { tc.BuildGoPlugin( "someteam.example.com", "v1", "DatePrefixer") - th := kusttest_test.NewKustTestHarnessAllowPlugins(t, "/app") + th := kusttest_test.MakeHarnessEnhanced(t, "/app") m := th.LoadAndRunTransformer(` apiVersion: someteam.example.com/v1 diff --git a/plugin/someteam.example.com/v1/gogetter/GoGetter_test.go b/plugin/someteam.example.com/v1/gogetter/GoGetter_test.go index 1171f5b4d..52bf5255c 100644 --- a/plugin/someteam.example.com/v1/gogetter/GoGetter_test.go +++ b/plugin/someteam.example.com/v1/gogetter/GoGetter_test.go @@ -22,7 +22,7 @@ func TestGoGetter(t *testing.T) { tc.PrepExecPlugin( "someteam.example.com", "v1", "GoGetter") - th := kusttest_test.NewKustTestHarnessAllowPlugins(t, "/app") + th := kusttest_test.MakeHarnessEnhanced(t, "/app") m := th.LoadAndRunGenerator(` apiVersion: someteam.example.com/v1 @@ -50,7 +50,7 @@ func TestGoGetterUrl(t *testing.T) { tc.PrepExecPlugin( "someteam.example.com", "v1", "GoGetter") - th := kusttest_test.NewKustTestHarnessAllowPlugins(t, "/app") + th := kusttest_test.MakeHarnessEnhanced(t, "/app") m := th.LoadAndRunGenerator(` apiVersion: someteam.example.com/v1 @@ -79,7 +79,7 @@ func TestGoGetterCommand(t *testing.T) { tc.PrepExecPlugin( "someteam.example.com", "v1", "GoGetter") - th := kusttest_test.NewKustTestHarnessAllowPlugins(t, "/app") + th := kusttest_test.MakeHarnessEnhanced(t, "/app") m := th.LoadAndRunGenerator(` apiVersion: someteam.example.com/v1 @@ -108,7 +108,7 @@ func TestGoGetterSubPath(t *testing.T) { tc.PrepExecPlugin( "someteam.example.com", "v1", "GoGetter") - th := kusttest_test.NewKustTestHarnessAllowPlugins(t, "/app") + th := kusttest_test.MakeHarnessEnhanced(t, "/app") m := th.LoadAndRunGenerator(` apiVersion: someteam.example.com/v1 diff --git a/plugin/someteam.example.com/v1/printpluginenv/PrintPluginEnv_test.go b/plugin/someteam.example.com/v1/printpluginenv/PrintPluginEnv_test.go index c01e3d7e5..9f6ec6902 100644 --- a/plugin/someteam.example.com/v1/printpluginenv/PrintPluginEnv_test.go +++ b/plugin/someteam.example.com/v1/printpluginenv/PrintPluginEnv_test.go @@ -23,7 +23,7 @@ func TestPrintPluginEnvPlugin(t *testing.T) { tc.PrepExecPlugin( "someteam.example.com", "v1", "PrintPluginEnv") - th := kusttest_test.NewKustTestHarnessAllowPlugins(t, "/theAppRoot") + th := kusttest_test.MakeHarnessEnhanced(t, "/theAppRoot") m := th.LoadAndRunGenerator(` apiVersion: someteam.example.com/v1 diff --git a/plugin/someteam.example.com/v1/secretsfromdatabase/SecretsFromDatabase_test.go b/plugin/someteam.example.com/v1/secretsfromdatabase/SecretsFromDatabase_test.go index a34cebf36..ceb590457 100644 --- a/plugin/someteam.example.com/v1/secretsfromdatabase/SecretsFromDatabase_test.go +++ b/plugin/someteam.example.com/v1/secretsfromdatabase/SecretsFromDatabase_test.go @@ -16,7 +16,7 @@ func TestSecretsFromDatabasePlugin(t *testing.T) { tc.BuildGoPlugin( "someteam.example.com", "v1", "SecretsFromDatabase") - th := kusttest_test.NewKustTestHarnessAllowPlugins(t, "/app") + th := kusttest_test.MakeHarnessEnhanced(t, "/app") m := th.LoadAndRunGenerator(` apiVersion: someteam.example.com/v1 diff --git a/plugin/someteam.example.com/v1/sedtransformer/SedTransformer_test.go b/plugin/someteam.example.com/v1/sedtransformer/SedTransformer_test.go index eaed5dfc1..de95b70d7 100644 --- a/plugin/someteam.example.com/v1/sedtransformer/SedTransformer_test.go +++ b/plugin/someteam.example.com/v1/sedtransformer/SedTransformer_test.go @@ -14,7 +14,7 @@ func TestSedTransformer(t *testing.T) { defer tc.Reset() tc.PrepExecPlugin("someteam.example.com", "v1", "SedTransformer") - th := kusttest_test.NewKustTestHarnessAllowPlugins(t, "/app") + th := kusttest_test.MakeHarnessEnhanced(t, "/app") th.WriteF("/app/sed-input.txt", ` s/$FRUIT/orange/g diff --git a/plugin/someteam.example.com/v1/someservicegenerator/SomeServiceGenerator_test.go b/plugin/someteam.example.com/v1/someservicegenerator/SomeServiceGenerator_test.go index 8966c135e..bf0988be0 100644 --- a/plugin/someteam.example.com/v1/someservicegenerator/SomeServiceGenerator_test.go +++ b/plugin/someteam.example.com/v1/someservicegenerator/SomeServiceGenerator_test.go @@ -16,7 +16,7 @@ func TestSomeServiceGeneratorPlugin(t *testing.T) { tc.BuildGoPlugin( "someteam.example.com", "v1", "SomeServiceGenerator") - th := kusttest_test.NewKustTestHarnessAllowPlugins(t, "/app") + th := kusttest_test.MakeHarnessEnhanced(t, "/app") m := th.LoadAndRunGenerator(` apiVersion: someteam.example.com/v1 diff --git a/plugin/someteam.example.com/v1/stringprefixer/StringPrefixer_test.go b/plugin/someteam.example.com/v1/stringprefixer/StringPrefixer_test.go index cbeefb1ef..11672da59 100644 --- a/plugin/someteam.example.com/v1/stringprefixer/StringPrefixer_test.go +++ b/plugin/someteam.example.com/v1/stringprefixer/StringPrefixer_test.go @@ -15,7 +15,7 @@ func TestStringPrefixerPlugin(t *testing.T) { tc.BuildGoPlugin( "someteam.example.com", "v1", "StringPrefixer") - th := kusttest_test.NewKustTestHarnessAllowPlugins(t, "/app") + th := kusttest_test.MakeHarnessEnhanced(t, "/app") m := th.LoadAndRunTransformer(` apiVersion: someteam.example.com/v1 diff --git a/plugin/someteam.example.com/v1/validator/validator_test.go b/plugin/someteam.example.com/v1/validator/validator_test.go index 6a580f1b3..7632e898d 100644 --- a/plugin/someteam.example.com/v1/validator/validator_test.go +++ b/plugin/someteam.example.com/v1/validator/validator_test.go @@ -17,7 +17,7 @@ func TestValidatorHappy(t *testing.T) { defer tc.Reset() tc.PrepExecPlugin("someteam.example.com", "v1", "Validator") - th := kusttest_test.NewKustTestHarnessAllowPlugins(t, "/app") + th := kusttest_test.MakeHarnessEnhanced(t, "/app") rm := th.LoadAndRunTransformer(` apiVersion: someteam.example.com/v1 @@ -52,7 +52,7 @@ func TestValidatorUnHappy(t *testing.T) { defer tc.Reset() tc.PrepExecPlugin("someteam.example.com", "v1", "Validator") - th := kusttest_test.NewKustTestHarnessAllowPlugins(t, "/app") + th := kusttest_test.MakeHarnessEnhanced(t, "/app") err := th.ErrorFromLoadAndRunTransformer(` apiVersion: someteam.example.com/v1