mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-09-15 12:18:57 +00:00
Consolidate test harness to one package.
This commit is contained in:
@@ -23,16 +23,16 @@ type FakeLoader struct {
|
|||||||
// The initialDir argument should be an absolute file path.
|
// The initialDir argument should be an absolute file path.
|
||||||
func NewFakeLoader(initialDir string) FakeLoader {
|
func NewFakeLoader(initialDir string) FakeLoader {
|
||||||
return NewFakeLoaderWithRestrictor(
|
return NewFakeLoaderWithRestrictor(
|
||||||
loader.RestrictionRootOnly, initialDir)
|
loader.RestrictionRootOnly, filesys.MakeFsInMemory(), initialDir)
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewFakeLoaderWithRestrictor returns a Loader that
|
// NewFakeLoaderWithRestrictor returns a Loader that
|
||||||
// uses a fake filesystem.
|
// uses a fake filesystem.
|
||||||
// The initialDir argument should be an absolute file path.
|
// The initialDir argument should be an absolute file path.
|
||||||
func NewFakeLoaderWithRestrictor(
|
func NewFakeLoaderWithRestrictor(
|
||||||
lr loader.LoadRestrictorFunc, initialDir string) FakeLoader {
|
lr loader.LoadRestrictorFunc,
|
||||||
// Create fake filesystem and inject it into initial Loader.
|
fSys filesys.FileSystem,
|
||||||
fSys := filesys.MakeFsInMemory()
|
initialDir string) FakeLoader {
|
||||||
fSys.Mkdir(initialDir)
|
fSys.Mkdir(initialDir)
|
||||||
ldr, err := loader.NewLoader(lr, initialDir, fSys)
|
ldr, err := loader.NewLoader(lr, initialDir, fSys)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -7,7 +7,9 @@ import (
|
|||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"sigs.k8s.io/kustomize/api/filesys"
|
||||||
"sigs.k8s.io/kustomize/api/ifc"
|
"sigs.k8s.io/kustomize/api/ifc"
|
||||||
|
"sigs.k8s.io/kustomize/api/k8sdeps/kunstruct"
|
||||||
"sigs.k8s.io/kustomize/api/resmap"
|
"sigs.k8s.io/kustomize/api/resmap"
|
||||||
"sigs.k8s.io/kustomize/api/resource"
|
"sigs.k8s.io/kustomize/api/resource"
|
||||||
kusttest_test "sigs.k8s.io/kustomize/api/testutils/kusttest"
|
kusttest_test "sigs.k8s.io/kustomize/api/testutils/kusttest"
|
||||||
@@ -17,7 +19,8 @@ import (
|
|||||||
// high level tests.
|
// high level tests.
|
||||||
|
|
||||||
func TestMakeCustomizedResMap(t *testing.T) {
|
func TestMakeCustomizedResMap(t *testing.T) {
|
||||||
th := kusttest_test.NewKustTestHarness(t, "/whatever")
|
fSys := filesys.MakeFsInMemory()
|
||||||
|
th := kusttest_test.MakeHarnessWithFs(t, fSys)
|
||||||
th.WriteK("/whatever", `
|
th.WriteK("/whatever", `
|
||||||
apiVersion: kustomize.config.k8s.io/v1beta1
|
apiVersion: kustomize.config.k8s.io/v1beta1
|
||||||
kind: Kustomization
|
kind: Kustomization
|
||||||
@@ -68,8 +71,10 @@ metadata:
|
|||||||
{"op": "add", "path": "/spec/replica", "value": "3"}
|
{"op": "add", "path": "/spec/replica", "value": "3"}
|
||||||
]`)
|
]`)
|
||||||
|
|
||||||
|
resFactory := resource.NewFactory(kunstruct.NewKunstructuredFactoryImpl())
|
||||||
|
|
||||||
resources := []*resource.Resource{
|
resources := []*resource.Resource{
|
||||||
th.RF().FromMapWithName("dply1", map[string]interface{}{
|
resFactory.FromMapWithName("dply1", map[string]interface{}{
|
||||||
"apiVersion": "apps/v1",
|
"apiVersion": "apps/v1",
|
||||||
"kind": "Deployment",
|
"kind": "Deployment",
|
||||||
"metadata": map[string]interface{}{
|
"metadata": map[string]interface{}{
|
||||||
@@ -101,7 +106,7 @@ metadata:
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
th.RF().FromMapWithName("ns1", map[string]interface{}{
|
resFactory.FromMapWithName("ns1", map[string]interface{}{
|
||||||
"apiVersion": "v1",
|
"apiVersion": "v1",
|
||||||
"kind": "Namespace",
|
"kind": "Namespace",
|
||||||
"metadata": map[string]interface{}{
|
"metadata": map[string]interface{}{
|
||||||
@@ -114,7 +119,7 @@ metadata:
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
th.RF().FromMapWithName("literalConfigMap",
|
resFactory.FromMapWithName("literalConfigMap",
|
||||||
map[string]interface{}{
|
map[string]interface{}{
|
||||||
"apiVersion": "v1",
|
"apiVersion": "v1",
|
||||||
"kind": "ConfigMap",
|
"kind": "ConfigMap",
|
||||||
@@ -133,7 +138,7 @@ metadata:
|
|||||||
"DB_PASSWORD": "somepw",
|
"DB_PASSWORD": "somepw",
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
th.RF().FromMapWithName("secret",
|
resFactory.FromMapWithName("secret",
|
||||||
map[string]interface{}{
|
map[string]interface{}{
|
||||||
"apiVersion": "v1",
|
"apiVersion": "v1",
|
||||||
"kind": "Secret",
|
"kind": "Secret",
|
||||||
@@ -162,7 +167,8 @@ metadata:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
actual, err := th.MakeKustTarget().MakeCustomizedResMap()
|
actual, err := makeKustTargetWithRf(
|
||||||
|
t, fSys, "/whatever", resFactory).MakeCustomizedResMap()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unexpected Resources error %v", err)
|
t.Fatalf("unexpected Resources error %v", err)
|
||||||
}
|
}
|
||||||
|
|||||||
48
api/internal/target/maker_test.go
Normal file
48
api/internal/target/maker_test.go
Normal file
@@ -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
|
||||||
|
}
|
||||||
@@ -48,7 +48,7 @@ var someVars = []types.Var{
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestGetAllVarsSimple(t *testing.T) {
|
func TestGetAllVarsSimple(t *testing.T) {
|
||||||
th := kusttest_test.NewKustTestHarness(t, "/app")
|
th := kusttest_test.MakeHarness(t)
|
||||||
th.WriteK("/app", `
|
th.WriteK("/app", `
|
||||||
vars:
|
vars:
|
||||||
- name: AWARD
|
- name: AWARD
|
||||||
@@ -64,7 +64,8 @@ vars:
|
|||||||
name: heron
|
name: heron
|
||||||
apiVersion: v300
|
apiVersion: v300
|
||||||
`)
|
`)
|
||||||
ra, err := th.MakeKustTarget().AccumulateTarget()
|
ra, err := makeKustTarget(
|
||||||
|
t, th.GetFSys(), "/app").AccumulateTarget()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Err: %v", err)
|
t.Fatalf("Err: %v", err)
|
||||||
}
|
}
|
||||||
@@ -83,7 +84,7 @@ vars:
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestGetAllVarsNested(t *testing.T) {
|
func TestGetAllVarsNested(t *testing.T) {
|
||||||
th := kusttest_test.NewKustTestHarness(t, "/app/overlays/o2")
|
th := kusttest_test.MakeHarness(t)
|
||||||
th.WriteK("/app/base", `
|
th.WriteK("/app/base", `
|
||||||
vars:
|
vars:
|
||||||
- name: AWARD
|
- name: AWARD
|
||||||
@@ -117,7 +118,9 @@ vars:
|
|||||||
resources:
|
resources:
|
||||||
- ../o1
|
- ../o1
|
||||||
`)
|
`)
|
||||||
ra, err := th.MakeKustTarget().AccumulateTarget()
|
|
||||||
|
ra, err := makeKustTarget(
|
||||||
|
t, th.GetFSys(), "/app/overlays/o2").AccumulateTarget()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Err: %v", err)
|
t.Fatalf("Err: %v", err)
|
||||||
}
|
}
|
||||||
@@ -139,7 +142,7 @@ resources:
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestVarCollisionsForbidden(t *testing.T) {
|
func TestVarCollisionsForbidden(t *testing.T) {
|
||||||
th := kusttest_test.NewKustTestHarness(t, "/app/overlays/o2")
|
th := kusttest_test.MakeHarness(t)
|
||||||
th.WriteK("/app/base", `
|
th.WriteK("/app/base", `
|
||||||
vars:
|
vars:
|
||||||
- name: AWARD
|
- name: AWARD
|
||||||
@@ -173,7 +176,8 @@ vars:
|
|||||||
resources:
|
resources:
|
||||||
- ../o1
|
- ../o1
|
||||||
`)
|
`)
|
||||||
_, err := th.MakeKustTarget().AccumulateTarget()
|
_, err := makeKustTarget(
|
||||||
|
t, th.GetFSys(), "/app/overlays/o2").AccumulateTarget()
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Fatalf("expected var collision")
|
t.Fatalf("expected var collision")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,13 +8,13 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"sigs.k8s.io/kustomize/api/konfig"
|
|
||||||
|
|
||||||
. "sigs.k8s.io/kustomize/api/internal/target"
|
. "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) {
|
func TestTargetMustHaveKustomizationFile(t *testing.T) {
|
||||||
th := makeTestHarness(t)
|
th := kusttest_test.MakeHarness(t)
|
||||||
th.WriteF("/app/service.yaml", `
|
th.WriteF("/app/service.yaml", `
|
||||||
apiVersion: v1
|
apiVersion: v1
|
||||||
kind: Service
|
kind: Service
|
||||||
@@ -37,7 +37,7 @@ metadata:
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestTargetMustHaveOnlyOneKustomizationFile(t *testing.T) {
|
func TestTargetMustHaveOnlyOneKustomizationFile(t *testing.T) {
|
||||||
th := makeTestHarness(t)
|
th := kusttest_test.MakeHarness(t)
|
||||||
for _, n := range konfig.RecognizedKustomizationFileNames() {
|
for _, n := range konfig.RecognizedKustomizationFileNames() {
|
||||||
th.WriteF(filepath.Join("/app", n), `
|
th.WriteF(filepath.Join("/app", n), `
|
||||||
apiVersion: kustomize.config.k8s.io/v1beta1
|
apiVersion: kustomize.config.k8s.io/v1beta1
|
||||||
@@ -54,7 +54,7 @@ kind: Kustomization
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestBaseMustHaveKustomizationFile(t *testing.T) {
|
func TestBaseMustHaveKustomizationFile(t *testing.T) {
|
||||||
th := makeTestHarness(t)
|
th := kusttest_test.MakeHarness(t)
|
||||||
th.WriteK("/app", `
|
th.WriteK("/app", `
|
||||||
resources:
|
resources:
|
||||||
- base
|
- base
|
||||||
@@ -80,7 +80,7 @@ spec:
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestResourceNotFound(t *testing.T) {
|
func TestResourceNotFound(t *testing.T) {
|
||||||
th := makeTestHarness(t)
|
th := kusttest_test.MakeHarness(t)
|
||||||
th.WriteK("/app", `
|
th.WriteK("/app", `
|
||||||
resources:
|
resources:
|
||||||
- deployment.yaml
|
- deployment.yaml
|
||||||
|
|||||||
@@ -5,9 +5,11 @@ package krusty_test
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
kusttest_test "sigs.k8s.io/kustomize/api/testutils/kusttest"
|
||||||
)
|
)
|
||||||
|
|
||||||
func writeMediumBase(th testingHarness) {
|
func writeMediumBase(th kusttest_test.Harness) {
|
||||||
th.WriteK("/app/base", `
|
th.WriteK("/app/base", `
|
||||||
namePrefix: baseprefix-
|
namePrefix: baseprefix-
|
||||||
commonLabels:
|
commonLabels:
|
||||||
@@ -57,7 +59,7 @@ spec:
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestMediumBase(t *testing.T) {
|
func TestMediumBase(t *testing.T) {
|
||||||
th := makeTestHarness(t)
|
th := kusttest_test.MakeHarness(t)
|
||||||
writeMediumBase(th)
|
writeMediumBase(th)
|
||||||
m := th.Run("/app/base", th.MakeDefaultOptions())
|
m := th.Run("/app/base", th.MakeDefaultOptions())
|
||||||
th.AssertActualEqualsExpected(m, `
|
th.AssertActualEqualsExpected(m, `
|
||||||
@@ -111,7 +113,7 @@ spec:
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestMediumOverlay(t *testing.T) {
|
func TestMediumOverlay(t *testing.T) {
|
||||||
th := makeTestHarness(t)
|
th := kusttest_test.MakeHarness(t)
|
||||||
writeMediumBase(th)
|
writeMediumBase(th)
|
||||||
th.WriteK("/app/overlay", `
|
th.WriteK("/app/overlay", `
|
||||||
namePrefix: test-infra-
|
namePrefix: test-infra-
|
||||||
|
|||||||
@@ -8,11 +8,12 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
. "sigs.k8s.io/kustomize/api/krusty"
|
. "sigs.k8s.io/kustomize/api/krusty"
|
||||||
|
kusttest_test "sigs.k8s.io/kustomize/api/testutils/kusttest"
|
||||||
"sigs.k8s.io/kustomize/api/types"
|
"sigs.k8s.io/kustomize/api/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestOrderPreserved(t *testing.T) {
|
func TestOrderPreserved(t *testing.T) {
|
||||||
th := makeTestHarness(t)
|
th := kusttest_test.MakeHarness(t)
|
||||||
th.WriteK("/app/base", `
|
th.WriteK("/app/base", `
|
||||||
namePrefix: b-
|
namePrefix: b-
|
||||||
resources:
|
resources:
|
||||||
@@ -99,7 +100,7 @@ metadata:
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestBaseInResourceList(t *testing.T) {
|
func TestBaseInResourceList(t *testing.T) {
|
||||||
th := makeTestHarness(t)
|
th := kusttest_test.MakeHarness(t)
|
||||||
th.WriteK("/app/prod", `
|
th.WriteK("/app/prod", `
|
||||||
namePrefix: b-
|
namePrefix: b-
|
||||||
resources:
|
resources:
|
||||||
@@ -131,7 +132,7 @@ spec:
|
|||||||
`)
|
`)
|
||||||
}
|
}
|
||||||
|
|
||||||
func writeSmallBase(th testingHarness) {
|
func writeSmallBase(th kusttest_test.Harness) {
|
||||||
th.WriteK("/app/base", `
|
th.WriteK("/app/base", `
|
||||||
namePrefix: a-
|
namePrefix: a-
|
||||||
commonLabels:
|
commonLabels:
|
||||||
@@ -169,7 +170,7 @@ spec:
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestSmallBase(t *testing.T) {
|
func TestSmallBase(t *testing.T) {
|
||||||
th := makeTestHarness(t)
|
th := kusttest_test.MakeHarness(t)
|
||||||
writeSmallBase(th)
|
writeSmallBase(th)
|
||||||
m := th.Run("/app/base", th.MakeDefaultOptions())
|
m := th.Run("/app/base", th.MakeDefaultOptions())
|
||||||
th.AssertActualEqualsExpected(m, `
|
th.AssertActualEqualsExpected(m, `
|
||||||
@@ -209,7 +210,7 @@ spec:
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestSmallOverlay(t *testing.T) {
|
func TestSmallOverlay(t *testing.T) {
|
||||||
th := makeTestHarness(t)
|
th := kusttest_test.MakeHarness(t)
|
||||||
writeSmallBase(th)
|
writeSmallBase(th)
|
||||||
th.WriteK("/app/overlay", `
|
th.WriteK("/app/overlay", `
|
||||||
namePrefix: b-
|
namePrefix: b-
|
||||||
@@ -284,7 +285,7 @@ spec:
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestSharedPatchDisAllowed(t *testing.T) {
|
func TestSharedPatchDisAllowed(t *testing.T) {
|
||||||
th := makeTestHarness(t)
|
th := kusttest_test.MakeHarness(t)
|
||||||
writeSmallBase(th)
|
writeSmallBase(th)
|
||||||
th.WriteK("/app/overlay", `
|
th.WriteK("/app/overlay", `
|
||||||
commonLabels:
|
commonLabels:
|
||||||
@@ -315,7 +316,7 @@ spec:
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestSharedPatchAllowed(t *testing.T) {
|
func TestSharedPatchAllowed(t *testing.T) {
|
||||||
th := makeTestHarness(t)
|
th := kusttest_test.MakeHarness(t)
|
||||||
writeSmallBase(th)
|
writeSmallBase(th)
|
||||||
th.WriteK("/app/overlay", `
|
th.WriteK("/app/overlay", `
|
||||||
commonLabels:
|
commonLabels:
|
||||||
@@ -381,7 +382,7 @@ spec:
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestSmallOverlayJSONPatch(t *testing.T) {
|
func TestSmallOverlayJSONPatch(t *testing.T) {
|
||||||
th := makeTestHarness(t)
|
th := kusttest_test.MakeHarness(t)
|
||||||
writeSmallBase(th)
|
writeSmallBase(th)
|
||||||
th.WriteK("/app/overlay", `
|
th.WriteK("/app/overlay", `
|
||||||
resources:
|
resources:
|
||||||
|
|||||||
@@ -5,6 +5,8 @@ package krusty_test
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
kusttest_test "sigs.k8s.io/kustomize/api/testutils/kusttest"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Here is a structure of a kustomization of two components, component1
|
// Here is a structure of a kustomization of two components, component1
|
||||||
@@ -38,7 +40,7 @@ import (
|
|||||||
// ├── kustomization.yaml
|
// ├── kustomization.yaml
|
||||||
|
|
||||||
func TestBaseReuseNameConflict(t *testing.T) {
|
func TestBaseReuseNameConflict(t *testing.T) {
|
||||||
th := makeTestHarness(t)
|
th := kusttest_test.MakeHarness(t)
|
||||||
th.WriteK("/app/component1/base", `
|
th.WriteK("/app/component1/base", `
|
||||||
resources:
|
resources:
|
||||||
- ../../shared
|
- ../../shared
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import (
|
|||||||
"regexp"
|
"regexp"
|
||||||
"testing"
|
"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,
|
// This is an example of using a helm chart as a base,
|
||||||
@@ -34,7 +34,7 @@ func TestChartInflatorPlugin(t *testing.T) {
|
|||||||
tc.PrepExecPlugin(
|
tc.PrepExecPlugin(
|
||||||
"someteam.example.com", "v1", "ChartInflator")
|
"someteam.example.com", "v1", "ChartInflator")
|
||||||
|
|
||||||
th := makeTestHarness(t)
|
th := kusttest_test.MakeHarness(t)
|
||||||
th.WriteK("/app", `
|
th.WriteK("/app", `
|
||||||
generators:
|
generators:
|
||||||
- chartInflator.yaml
|
- chartInflator.yaml
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
. "sigs.k8s.io/kustomize/api/krusty"
|
. "sigs.k8s.io/kustomize/api/krusty"
|
||||||
|
kusttest_test "sigs.k8s.io/kustomize/api/testutils/kusttest"
|
||||||
"sigs.k8s.io/kustomize/api/types"
|
"sigs.k8s.io/kustomize/api/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -25,7 +26,7 @@ spec:
|
|||||||
app: my-app
|
app: my-app
|
||||||
`
|
`
|
||||||
|
|
||||||
func writeStatefulSetBase(th testingHarness) {
|
func writeStatefulSetBase(th kusttest_test.Harness) {
|
||||||
th.WriteK("/app/base", `
|
th.WriteK("/app/base", `
|
||||||
resources:
|
resources:
|
||||||
- statefulset.yaml
|
- statefulset.yaml
|
||||||
@@ -54,7 +55,7 @@ spec:
|
|||||||
`)
|
`)
|
||||||
}
|
}
|
||||||
|
|
||||||
func writeHTTPSOverlay(th testingHarness) {
|
func writeHTTPSOverlay(th kusttest_test.Harness) {
|
||||||
th.WriteK("/app/https", `
|
th.WriteK("/app/https", `
|
||||||
resources:
|
resources:
|
||||||
- ../base
|
- ../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/service/https-svc.yaml", httpsService)
|
||||||
th.WriteF("/app/https/transformer/transformer.yaml", `
|
th.WriteF("/app/https/transformer/transformer.yaml", `
|
||||||
apiVersion: builtin
|
apiVersion: builtin
|
||||||
@@ -95,7 +96,7 @@ patch: |-
|
|||||||
`)
|
`)
|
||||||
}
|
}
|
||||||
|
|
||||||
func writeHTTPSTransformerBase(th testingHarness) {
|
func writeHTTPSTransformerBase(th kusttest_test.Harness) {
|
||||||
th.WriteK("/app/https/service", `
|
th.WriteK("/app/https/service", `
|
||||||
resources:
|
resources:
|
||||||
- https-svc.yaml
|
- https-svc.yaml
|
||||||
@@ -107,7 +108,7 @@ resources:
|
|||||||
writeHTTPSTransformerRaw(th)
|
writeHTTPSTransformerRaw(th)
|
||||||
}
|
}
|
||||||
|
|
||||||
func writeConfigFromEnvOverlay(th testingHarness) {
|
func writeConfigFromEnvOverlay(th kusttest_test.Harness) {
|
||||||
th.WriteK("/app/config", `
|
th.WriteK("/app/config", `
|
||||||
resources:
|
resources:
|
||||||
- ../base
|
- ../base
|
||||||
@@ -136,7 +137,7 @@ spec:
|
|||||||
`)
|
`)
|
||||||
}
|
}
|
||||||
|
|
||||||
func writeConfigFromEnvTransformerRaw(th testingHarness) {
|
func writeConfigFromEnvTransformerRaw(th kusttest_test.Harness) {
|
||||||
th.WriteF("/app/config/map/generator.yaml", `
|
th.WriteF("/app/config/map/generator.yaml", `
|
||||||
apiVersion: builtin
|
apiVersion: builtin
|
||||||
kind: ConfigMapGenerator
|
kind: ConfigMapGenerator
|
||||||
@@ -171,7 +172,7 @@ patch: |-
|
|||||||
name: my-config
|
name: my-config
|
||||||
`)
|
`)
|
||||||
}
|
}
|
||||||
func writeConfigFromEnvTransformerBase(th testingHarness) {
|
func writeConfigFromEnvTransformerBase(th kusttest_test.Harness) {
|
||||||
th.WriteK("/app/config/map", `
|
th.WriteK("/app/config/map", `
|
||||||
resources:
|
resources:
|
||||||
- generator.yaml
|
- generator.yaml
|
||||||
@@ -183,7 +184,7 @@ resources:
|
|||||||
writeConfigFromEnvTransformerRaw(th)
|
writeConfigFromEnvTransformerRaw(th)
|
||||||
}
|
}
|
||||||
|
|
||||||
func writeTolerationsOverlay(th testingHarness) {
|
func writeTolerationsOverlay(th kusttest_test.Harness) {
|
||||||
th.WriteK("/app/tolerations", `
|
th.WriteK("/app/tolerations", `
|
||||||
resources:
|
resources:
|
||||||
- ../base
|
- ../base
|
||||||
@@ -205,7 +206,7 @@ spec:
|
|||||||
`)
|
`)
|
||||||
}
|
}
|
||||||
|
|
||||||
func writeTolerationsTransformerRaw(th testingHarness) {
|
func writeTolerationsTransformerRaw(th kusttest_test.Harness) {
|
||||||
th.WriteF("/app/tolerations/transformer.yaml", `
|
th.WriteF("/app/tolerations/transformer.yaml", `
|
||||||
apiVersion: builtin
|
apiVersion: builtin
|
||||||
kind: PatchTransformer
|
kind: PatchTransformer
|
||||||
@@ -231,7 +232,7 @@ patch: |-
|
|||||||
`)
|
`)
|
||||||
}
|
}
|
||||||
|
|
||||||
func writeTolerationsTransformerBase(th testingHarness) {
|
func writeTolerationsTransformerBase(th kusttest_test.Harness) {
|
||||||
th.WriteK("/app/tolerations", `
|
th.WriteK("/app/tolerations", `
|
||||||
resources:
|
resources:
|
||||||
- transformer.yaml
|
- transformer.yaml
|
||||||
@@ -239,7 +240,7 @@ resources:
|
|||||||
writeTolerationsTransformerRaw(th)
|
writeTolerationsTransformerRaw(th)
|
||||||
}
|
}
|
||||||
|
|
||||||
func writeStorageOverlay(th testingHarness) {
|
func writeStorageOverlay(th kusttest_test.Harness) {
|
||||||
th.WriteK("/app/storage", `
|
th.WriteK("/app/storage", `
|
||||||
resources:
|
resources:
|
||||||
- ../base
|
- ../base
|
||||||
@@ -256,7 +257,7 @@ patchesJson6902:
|
|||||||
`)
|
`)
|
||||||
}
|
}
|
||||||
|
|
||||||
func writeStorageTransformerRaw(th testingHarness) {
|
func writeStorageTransformerRaw(th kusttest_test.Harness) {
|
||||||
th.WriteF("/app/storage/transformer.yaml", `
|
th.WriteF("/app/storage/transformer.yaml", `
|
||||||
apiVersion: builtin
|
apiVersion: builtin
|
||||||
kind: PatchTransformer
|
kind: PatchTransformer
|
||||||
@@ -272,7 +273,7 @@ patch: |-
|
|||||||
`)
|
`)
|
||||||
}
|
}
|
||||||
|
|
||||||
func writeStorageTransformerBase(th testingHarness) {
|
func writeStorageTransformerBase(th kusttest_test.Harness) {
|
||||||
th.WriteK("/app/storage", `
|
th.WriteK("/app/storage", `
|
||||||
resources:
|
resources:
|
||||||
- transformer.yaml
|
- transformer.yaml
|
||||||
@@ -280,14 +281,14 @@ resources:
|
|||||||
writeStorageTransformerRaw(th)
|
writeStorageTransformerRaw(th)
|
||||||
}
|
}
|
||||||
|
|
||||||
func writePatchingOverlays(th testingHarness) {
|
func writePatchingOverlays(th kusttest_test.Harness) {
|
||||||
writeStorageOverlay(th)
|
writeStorageOverlay(th)
|
||||||
writeConfigFromEnvOverlay(th)
|
writeConfigFromEnvOverlay(th)
|
||||||
writeTolerationsOverlay(th)
|
writeTolerationsOverlay(th)
|
||||||
writeHTTPSOverlay(th)
|
writeHTTPSOverlay(th)
|
||||||
}
|
}
|
||||||
|
|
||||||
func writePatchingTransformersRaw(th testingHarness) {
|
func writePatchingTransformersRaw(th kusttest_test.Harness) {
|
||||||
writeStorageTransformerRaw(th)
|
writeStorageTransformerRaw(th)
|
||||||
writeConfigFromEnvTransformerRaw(th)
|
writeConfigFromEnvTransformerRaw(th)
|
||||||
writeTolerationsTransformerRaw(th)
|
writeTolerationsTransformerRaw(th)
|
||||||
@@ -310,7 +311,7 @@ func writePatchingTransformersRaw(th testingHarness) {
|
|||||||
// must be self-contained, i.e. the config may not have fields that
|
// 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
|
// refer to local files, since those files won't be present when
|
||||||
// the plugin is instantiated and used.
|
// the plugin is instantiated and used.
|
||||||
func writePatchingTransformerBases(th testingHarness) {
|
func writePatchingTransformerBases(th kusttest_test.Harness) {
|
||||||
writeStorageTransformerBase(th)
|
writeStorageTransformerBase(th)
|
||||||
writeConfigFromEnvTransformerBase(th)
|
writeConfigFromEnvTransformerBase(th)
|
||||||
writeTolerationsTransformerBase(th)
|
writeTolerationsTransformerBase(th)
|
||||||
@@ -353,7 +354,7 @@ func writePatchingTransformerBases(th testingHarness) {
|
|||||||
// - prod: Combines the config, tolerations and https intermediate overlays.
|
// - prod: Combines the config, tolerations and https intermediate overlays.
|
||||||
|
|
||||||
func TestComplexComposition_Dev_Failure(t *testing.T) {
|
func TestComplexComposition_Dev_Failure(t *testing.T) {
|
||||||
th := makeTestHarness(t)
|
th := kusttest_test.MakeHarness(t)
|
||||||
writeStatefulSetBase(th)
|
writeStatefulSetBase(th)
|
||||||
writePatchingOverlays(th)
|
writePatchingOverlays(th)
|
||||||
th.WriteK("/app/dev", `
|
th.WriteK("/app/dev", `
|
||||||
@@ -405,7 +406,7 @@ metadata:
|
|||||||
`
|
`
|
||||||
|
|
||||||
func TestComplexComposition_Dev_SuccessWithRawTransformers(t *testing.T) {
|
func TestComplexComposition_Dev_SuccessWithRawTransformers(t *testing.T) {
|
||||||
th := makeTestHarness(t)
|
th := kusttest_test.MakeHarness(t)
|
||||||
writeStatefulSetBase(th)
|
writeStatefulSetBase(th)
|
||||||
writePatchingTransformersRaw(th)
|
writePatchingTransformersRaw(th)
|
||||||
th.WriteK("/app/dev", `
|
th.WriteK("/app/dev", `
|
||||||
@@ -426,7 +427,7 @@ transformers:
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestComplexComposition_Dev_SuccessWithBaseTransformers(t *testing.T) {
|
func TestComplexComposition_Dev_SuccessWithBaseTransformers(t *testing.T) {
|
||||||
th := makeTestHarness(t)
|
th := kusttest_test.MakeHarness(t)
|
||||||
writeStatefulSetBase(th)
|
writeStatefulSetBase(th)
|
||||||
writePatchingTransformerBases(th)
|
writePatchingTransformerBases(th)
|
||||||
th.WriteK("/app/dev", `
|
th.WriteK("/app/dev", `
|
||||||
@@ -443,7 +444,7 @@ transformers:
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestComplexComposition_Prod_Failure(t *testing.T) {
|
func TestComplexComposition_Prod_Failure(t *testing.T) {
|
||||||
th := makeTestHarness(t)
|
th := kusttest_test.MakeHarness(t)
|
||||||
writeStatefulSetBase(th)
|
writeStatefulSetBase(th)
|
||||||
writePatchingOverlays(th)
|
writePatchingOverlays(th)
|
||||||
th.WriteK("/app/prod", `
|
th.WriteK("/app/prod", `
|
||||||
@@ -512,7 +513,7 @@ metadata:
|
|||||||
`
|
`
|
||||||
|
|
||||||
func TestComplexComposition_Prod_SuccessWithRawTransformers(t *testing.T) {
|
func TestComplexComposition_Prod_SuccessWithRawTransformers(t *testing.T) {
|
||||||
th := makeTestHarness(t)
|
th := kusttest_test.MakeHarness(t)
|
||||||
writeStatefulSetBase(th)
|
writeStatefulSetBase(th)
|
||||||
writePatchingTransformersRaw(th)
|
writePatchingTransformersRaw(th)
|
||||||
th.WriteK("/app/prod", `
|
th.WriteK("/app/prod", `
|
||||||
@@ -535,7 +536,7 @@ transformers:
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestComplexComposition_Prod_SuccessWithBaseTransformers(t *testing.T) {
|
func TestComplexComposition_Prod_SuccessWithBaseTransformers(t *testing.T) {
|
||||||
th := makeTestHarness(t)
|
th := kusttest_test.MakeHarness(t)
|
||||||
writeStatefulSetBase(th)
|
writeStatefulSetBase(th)
|
||||||
writePatchingTransformerBases(th)
|
writePatchingTransformerBases(th)
|
||||||
th.WriteK("/app/prod", `
|
th.WriteK("/app/prod", `
|
||||||
|
|||||||
@@ -5,12 +5,14 @@ package krusty_test
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
kusttest_test "sigs.k8s.io/kustomize/api/testutils/kusttest"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Generate a Secret and a ConfigMap from the same data
|
// Generate a Secret and a ConfigMap from the same data
|
||||||
// to compare the result.
|
// to compare the result.
|
||||||
func TestGeneratorBasics(t *testing.T) {
|
func TestGeneratorBasics(t *testing.T) {
|
||||||
th := makeTestHarness(t)
|
th := kusttest_test.MakeHarness(t)
|
||||||
th.WriteK("/app", `
|
th.WriteK("/app", `
|
||||||
namePrefix: blah-
|
namePrefix: blah-
|
||||||
configMapGenerator:
|
configMapGenerator:
|
||||||
@@ -107,7 +109,7 @@ type: Opaque
|
|||||||
|
|
||||||
// TODO: These should be errors instead.
|
// TODO: These should be errors instead.
|
||||||
func TestGeneratorRepeatsInKustomization(t *testing.T) {
|
func TestGeneratorRepeatsInKustomization(t *testing.T) {
|
||||||
th := makeTestHarness(t)
|
th := kusttest_test.MakeHarness(t)
|
||||||
th.WriteK("/app", `
|
th.WriteK("/app", `
|
||||||
namePrefix: blah-
|
namePrefix: blah-
|
||||||
configMapGenerator:
|
configMapGenerator:
|
||||||
@@ -159,7 +161,7 @@ metadata:
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestGeneratorOverlays(t *testing.T) {
|
func TestGeneratorOverlays(t *testing.T) {
|
||||||
th := makeTestHarness(t)
|
th := kusttest_test.MakeHarness(t)
|
||||||
th.WriteK("/app/base1", `
|
th.WriteK("/app/base1", `
|
||||||
namePrefix: p1-
|
namePrefix: p1-
|
||||||
configMapGenerator:
|
configMapGenerator:
|
||||||
@@ -231,7 +233,7 @@ metadata:
|
|||||||
|
|
||||||
func TestConfigMapGeneratorMergeNamePrefix(t *testing.T) {
|
func TestConfigMapGeneratorMergeNamePrefix(t *testing.T) {
|
||||||
|
|
||||||
th := makeTestHarness(t)
|
th := kusttest_test.MakeHarness(t)
|
||||||
th.WriteK("/app/base", `
|
th.WriteK("/app/base", `
|
||||||
configMapGenerator:
|
configMapGenerator:
|
||||||
- name: cm
|
- name: cm
|
||||||
|
|||||||
@@ -5,9 +5,11 @@ package krusty_test
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
kusttest_test "sigs.k8s.io/kustomize/api/testutils/kusttest"
|
||||||
)
|
)
|
||||||
|
|
||||||
func writeBaseWithCrd(th testingHarness) {
|
func writeBaseWithCrd(th kusttest_test.Harness) {
|
||||||
th.WriteK("/app/base", `
|
th.WriteK("/app/base", `
|
||||||
apiVersion: kustomize.config.k8s.io/v1beta1
|
apiVersion: kustomize.config.k8s.io/v1beta1
|
||||||
kind: Kustomization
|
kind: Kustomization
|
||||||
@@ -223,7 +225,7 @@ data:
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestCrdBase(t *testing.T) {
|
func TestCrdBase(t *testing.T) {
|
||||||
th := makeTestHarness(t)
|
th := kusttest_test.MakeHarness(t)
|
||||||
writeBaseWithCrd(th)
|
writeBaseWithCrd(th)
|
||||||
m := th.Run("/app/base", th.MakeDefaultOptions())
|
m := th.Run("/app/base", th.MakeDefaultOptions())
|
||||||
th.AssertActualEqualsExpected(m, `
|
th.AssertActualEqualsExpected(m, `
|
||||||
@@ -254,7 +256,7 @@ spec:
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestCrdWithOverlay(t *testing.T) {
|
func TestCrdWithOverlay(t *testing.T) {
|
||||||
th := makeTestHarness(t)
|
th := kusttest_test.MakeHarness(t)
|
||||||
writeBaseWithCrd(th)
|
writeBaseWithCrd(th)
|
||||||
th.WriteK("/app/overlay", `
|
th.WriteK("/app/overlay", `
|
||||||
apiVersion: kustomize.config.k8s.io/v1beta1
|
apiVersion: kustomize.config.k8s.io/v1beta1
|
||||||
@@ -303,7 +305,7 @@ spec:
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestCrdWithContainers(t *testing.T) {
|
func TestCrdWithContainers(t *testing.T) {
|
||||||
th := makeTestHarness(t)
|
th := kusttest_test.MakeHarness(t)
|
||||||
th.WriteK("/app/crd/containers", `
|
th.WriteK("/app/crd/containers", `
|
||||||
apiVersion: kustomize.config.k8s.io/v1beta1
|
apiVersion: kustomize.config.k8s.io/v1beta1
|
||||||
kind: Kustomization
|
kind: Kustomization
|
||||||
|
|||||||
@@ -5,9 +5,11 @@ package krusty_test
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
kusttest_test "sigs.k8s.io/kustomize/api/testutils/kusttest"
|
||||||
)
|
)
|
||||||
|
|
||||||
func makeBaseReferencingCustomConfig(th testingHarness) {
|
func makeBaseReferencingCustomConfig(th kusttest_test.Harness) {
|
||||||
th.WriteK("/app/base", `
|
th.WriteK("/app/base", `
|
||||||
namePrefix: x-
|
namePrefix: x-
|
||||||
commonLabels:
|
commonLabels:
|
||||||
@@ -72,7 +74,7 @@ spec:
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestCustomConfig(t *testing.T) {
|
func TestCustomConfig(t *testing.T) {
|
||||||
th := makeTestHarness(t)
|
th := kusttest_test.MakeHarness(t)
|
||||||
makeBaseReferencingCustomConfig(th)
|
makeBaseReferencingCustomConfig(th)
|
||||||
th.WriteLegacyConfigs("/app/base/config/defaults.yaml")
|
th.WriteLegacyConfigs("/app/base/config/defaults.yaml")
|
||||||
th.WriteF("/app/base/config/custom.yaml", `
|
th.WriteF("/app/base/config/custom.yaml", `
|
||||||
@@ -135,7 +137,7 @@ spec:
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestCustomConfigWithDefaultOverspecification(t *testing.T) {
|
func TestCustomConfigWithDefaultOverspecification(t *testing.T) {
|
||||||
th := makeTestHarness(t)
|
th := kusttest_test.MakeHarness(t)
|
||||||
makeBaseReferencingCustomConfig(th)
|
makeBaseReferencingCustomConfig(th)
|
||||||
th.WriteLegacyConfigs("/app/base/config/defaults.yaml")
|
th.WriteLegacyConfigs("/app/base/config/defaults.yaml")
|
||||||
// Specifying namePrefix here conflicts with (is the same as)
|
// Specifying namePrefix here conflicts with (is the same as)
|
||||||
@@ -203,7 +205,7 @@ spec:
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestFixedBug605_BaseCustomizationAvailableInOverlay(t *testing.T) {
|
func TestFixedBug605_BaseCustomizationAvailableInOverlay(t *testing.T) {
|
||||||
th := makeTestHarness(t)
|
th := kusttest_test.MakeHarness(t)
|
||||||
makeBaseReferencingCustomConfig(th)
|
makeBaseReferencingCustomConfig(th)
|
||||||
th.WriteLegacyConfigs("/app/base/config/defaults.yaml")
|
th.WriteLegacyConfigs("/app/base/config/defaults.yaml")
|
||||||
th.WriteF("/app/base/config/custom.yaml", `
|
th.WriteF("/app/base/config/custom.yaml", `
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ func TestCustomNamePrefixer(t *testing.T) {
|
|||||||
tc.BuildGoPlugin(
|
tc.BuildGoPlugin(
|
||||||
"builtin", "", "PrefixSuffixTransformer")
|
"builtin", "", "PrefixSuffixTransformer")
|
||||||
|
|
||||||
th := makeTestHarness(t)
|
th := kusttest_test.MakeHarness(t)
|
||||||
th.WriteK("/app", `
|
th.WriteK("/app", `
|
||||||
resources:
|
resources:
|
||||||
- deployment.yaml
|
- deployment.yaml
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ func TestReusableCustomTransformers(t *testing.T) {
|
|||||||
tc.BuildGoPlugin(
|
tc.BuildGoPlugin(
|
||||||
"builtin", "", "LabelTransformer")
|
"builtin", "", "LabelTransformer")
|
||||||
|
|
||||||
th := makeTestHarness(t)
|
th := kusttest_test.MakeHarness(t)
|
||||||
|
|
||||||
// First write three custom configurations for builtin plugins.
|
// First write three custom configurations for builtin plugins.
|
||||||
|
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ spec:
|
|||||||
`
|
`
|
||||||
const patchJsonRestartPolicy = `[{"op": "add", "path": "/spec/template/spec/restartPolicy", "value": "Always"}]`
|
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", `
|
th.WriteK("/app/base", `
|
||||||
resources:
|
resources:
|
||||||
- deployment.yaml
|
- deployment.yaml
|
||||||
@@ -79,7 +79,7 @@ spec:
|
|||||||
`)
|
`)
|
||||||
}
|
}
|
||||||
|
|
||||||
func writeProbeOverlay(th testingHarness) {
|
func writeProbeOverlay(th kusttest_test.Harness) {
|
||||||
th.WriteK("/app/probe", `
|
th.WriteK("/app/probe", `
|
||||||
resources:
|
resources:
|
||||||
- ../base
|
- ../base
|
||||||
@@ -89,7 +89,7 @@ patchesStrategicMerge:
|
|||||||
th.WriteF("/app/probe/dep-patch.yaml", patchAddProbe)
|
th.WriteF("/app/probe/dep-patch.yaml", patchAddProbe)
|
||||||
}
|
}
|
||||||
|
|
||||||
func writeDNSOverlay(th testingHarness) {
|
func writeDNSOverlay(th kusttest_test.Harness) {
|
||||||
th.WriteK("/app/dns", `
|
th.WriteK("/app/dns", `
|
||||||
resources:
|
resources:
|
||||||
- ../base
|
- ../base
|
||||||
@@ -99,7 +99,7 @@ patchesStrategicMerge:
|
|||||||
th.WriteF("/app/dns/dep-patch.yaml", patchDnsPolicy)
|
th.WriteF("/app/dns/dep-patch.yaml", patchDnsPolicy)
|
||||||
}
|
}
|
||||||
|
|
||||||
func writeRestartOverlay(th testingHarness) {
|
func writeRestartOverlay(th kusttest_test.Harness) {
|
||||||
th.WriteK("/app/restart", `
|
th.WriteK("/app/restart", `
|
||||||
resources:
|
resources:
|
||||||
- ../base
|
- ../base
|
||||||
@@ -123,7 +123,7 @@ patchesStrategicMerge:
|
|||||||
// base
|
// base
|
||||||
//
|
//
|
||||||
func TestIssue1251_CompositeDiamond_Failure(t *testing.T) {
|
func TestIssue1251_CompositeDiamond_Failure(t *testing.T) {
|
||||||
th := makeTestHarness(t)
|
th := kusttest_test.MakeHarness(t)
|
||||||
writeDeploymentBase(th)
|
writeDeploymentBase(th)
|
||||||
writeProbeOverlay(th)
|
writeProbeOverlay(th)
|
||||||
writeDNSOverlay(th)
|
writeDNSOverlay(th)
|
||||||
@@ -168,7 +168,7 @@ spec:
|
|||||||
// This test reuses some methods from TestIssue1251_CompositeDiamond,
|
// This test reuses some methods from TestIssue1251_CompositeDiamond,
|
||||||
// but overwrites the kustomization files in the overlays.
|
// but overwrites the kustomization files in the overlays.
|
||||||
func TestIssue1251_Patches_Overlayed(t *testing.T) {
|
func TestIssue1251_Patches_Overlayed(t *testing.T) {
|
||||||
th := makeTestHarness(t)
|
th := kusttest_test.MakeHarness(t)
|
||||||
writeDeploymentBase(th)
|
writeDeploymentBase(th)
|
||||||
|
|
||||||
// probe overlays base.
|
// probe overlays base.
|
||||||
@@ -197,7 +197,7 @@ patchesStrategicMerge:
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestIssue1251_Patches_Local(t *testing.T) {
|
func TestIssue1251_Patches_Local(t *testing.T) {
|
||||||
th := makeTestHarness(t)
|
th := kusttest_test.MakeHarness(t)
|
||||||
writeDeploymentBase(th)
|
writeDeploymentBase(th)
|
||||||
|
|
||||||
th.WriteK("/app/composite", `
|
th.WriteK("/app/composite", `
|
||||||
@@ -216,7 +216,7 @@ patchesStrategicMerge:
|
|||||||
th.AssertActualEqualsExpected(m, expectedPatchedDeployment)
|
th.AssertActualEqualsExpected(m, expectedPatchedDeployment)
|
||||||
}
|
}
|
||||||
|
|
||||||
func definePatchDirStructure(th testingHarness) {
|
func definePatchDirStructure(th kusttest_test.Harness) {
|
||||||
writeDeploymentBase(th)
|
writeDeploymentBase(th)
|
||||||
|
|
||||||
th.WriteF("/app/patches/patchRestartPolicy.yaml", patchRestartPolicy)
|
th.WriteF("/app/patches/patchRestartPolicy.yaml", patchRestartPolicy)
|
||||||
@@ -226,7 +226,7 @@ func definePatchDirStructure(th testingHarness) {
|
|||||||
|
|
||||||
// Fails due to file load restrictor.
|
// Fails due to file load restrictor.
|
||||||
func TestIssue1251_Patches_ProdVsDev_Failure(t *testing.T) {
|
func TestIssue1251_Patches_ProdVsDev_Failure(t *testing.T) {
|
||||||
th := makeTestHarness(t)
|
th := kusttest_test.MakeHarness(t)
|
||||||
definePatchDirStructure(th)
|
definePatchDirStructure(th)
|
||||||
|
|
||||||
th.WriteK("/app/prod", `
|
th.WriteK("/app/prod", `
|
||||||
@@ -299,7 +299,7 @@ spec:
|
|||||||
// the kustomization root), opening the user to whatever
|
// the kustomization root), opening the user to whatever
|
||||||
// threat the load restrictor was meant to address.
|
// threat the load restrictor was meant to address.
|
||||||
func TestIssue1251_Patches_ProdVsDev(t *testing.T) {
|
func TestIssue1251_Patches_ProdVsDev(t *testing.T) {
|
||||||
th := makeTestHarness(t)
|
th := kusttest_test.MakeHarness(t)
|
||||||
definePatchDirStructure(th)
|
definePatchDirStructure(th)
|
||||||
|
|
||||||
th.WriteK("/app/prod", `
|
th.WriteK("/app/prod", `
|
||||||
@@ -315,7 +315,7 @@ patchesStrategicMerge:
|
|||||||
m := th.Run("/app/prod", opts)
|
m := th.Run("/app/prod", opts)
|
||||||
th.AssertActualEqualsExpected(m, prodDevMergeResult1)
|
th.AssertActualEqualsExpected(m, prodDevMergeResult1)
|
||||||
|
|
||||||
th = makeTestHarness(t)
|
th = kusttest_test.MakeHarness(t)
|
||||||
definePatchDirStructure(th)
|
definePatchDirStructure(th)
|
||||||
|
|
||||||
th.WriteK("/app/dev", `
|
th.WriteK("/app/dev", `
|
||||||
@@ -337,7 +337,7 @@ func TestIssue1251_Plugins_ProdVsDev(t *testing.T) {
|
|||||||
tc.BuildGoPlugin(
|
tc.BuildGoPlugin(
|
||||||
"builtin", "", "PatchJson6902Transformer")
|
"builtin", "", "PatchJson6902Transformer")
|
||||||
|
|
||||||
th := makeTestHarness(t)
|
th := kusttest_test.MakeHarness(t)
|
||||||
defineTransformerDirStructure(th)
|
defineTransformerDirStructure(th)
|
||||||
th.WriteK("/app/prod", `
|
th.WriteK("/app/prod", `
|
||||||
resources:
|
resources:
|
||||||
@@ -370,7 +370,7 @@ func TestIssue1251_Plugins_Local(t *testing.T) {
|
|||||||
tc.BuildGoPlugin(
|
tc.BuildGoPlugin(
|
||||||
"builtin", "", "PatchJson6902Transformer")
|
"builtin", "", "PatchJson6902Transformer")
|
||||||
|
|
||||||
th := makeTestHarness(t)
|
th := kusttest_test.MakeHarness(t)
|
||||||
writeDeploymentBase(th)
|
writeDeploymentBase(th)
|
||||||
|
|
||||||
writeJsonTransformerPluginConfig(
|
writeJsonTransformerPluginConfig(
|
||||||
@@ -393,7 +393,7 @@ transformers:
|
|||||||
}
|
}
|
||||||
|
|
||||||
func writeJsonTransformerPluginConfig(
|
func writeJsonTransformerPluginConfig(
|
||||||
th testingHarness, path, name, patch string) {
|
th kusttest_test.Harness, path, name, patch string) {
|
||||||
th.WriteF(filepath.Join(path, name+"Config.yaml"),
|
th.WriteF(filepath.Join(path, name+"Config.yaml"),
|
||||||
fmt.Sprintf(`
|
fmt.Sprintf(`
|
||||||
apiVersion: builtin
|
apiVersion: builtin
|
||||||
@@ -417,7 +417,7 @@ func TestIssue1251_Plugins_Bundled(t *testing.T) {
|
|||||||
tc.BuildGoPlugin(
|
tc.BuildGoPlugin(
|
||||||
"builtin", "", "PatchJson6902Transformer")
|
"builtin", "", "PatchJson6902Transformer")
|
||||||
|
|
||||||
th := makeTestHarness(t)
|
th := kusttest_test.MakeHarness(t)
|
||||||
writeDeploymentBase(th)
|
writeDeploymentBase(th)
|
||||||
|
|
||||||
th.WriteK("/app/patches", `
|
th.WriteK("/app/patches", `
|
||||||
@@ -443,7 +443,7 @@ transformers:
|
|||||||
th.AssertActualEqualsExpected(m, expectedPatchedDeployment)
|
th.AssertActualEqualsExpected(m, expectedPatchedDeployment)
|
||||||
}
|
}
|
||||||
|
|
||||||
func defineTransformerDirStructure(th testingHarness) {
|
func defineTransformerDirStructure(th kusttest_test.Harness) {
|
||||||
writeDeploymentBase(th)
|
writeDeploymentBase(th)
|
||||||
|
|
||||||
th.WriteK("/app/patches/addDnsPolicy", `
|
th.WriteK("/app/patches/addDnsPolicy", `
|
||||||
|
|||||||
@@ -5,6 +5,8 @@ package krusty_test
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
kusttest_test "sigs.k8s.io/kustomize/api/testutils/kusttest"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Here's a structure of two kustomizations,
|
// Here's a structure of two kustomizations,
|
||||||
@@ -28,7 +30,7 @@ import (
|
|||||||
// \ | /
|
// \ | /
|
||||||
// base
|
// base
|
||||||
//
|
//
|
||||||
func writeDiamondBase(th testingHarness) {
|
func writeDiamondBase(th kusttest_test.Harness) {
|
||||||
th.WriteK("/app/base", `
|
th.WriteK("/app/base", `
|
||||||
resources:
|
resources:
|
||||||
- deploy.yaml
|
- deploy.yaml
|
||||||
@@ -43,7 +45,7 @@ spec:
|
|||||||
`)
|
`)
|
||||||
}
|
}
|
||||||
|
|
||||||
func writeKirk(th testingHarness) {
|
func writeKirk(th kusttest_test.Harness) {
|
||||||
th.WriteK("/app/kirk", `
|
th.WriteK("/app/kirk", `
|
||||||
namePrefix: kirk-
|
namePrefix: kirk-
|
||||||
resources:
|
resources:
|
||||||
@@ -70,7 +72,7 @@ data:
|
|||||||
`)
|
`)
|
||||||
}
|
}
|
||||||
|
|
||||||
func writeSpock(th testingHarness) {
|
func writeSpock(th kusttest_test.Harness) {
|
||||||
th.WriteK("/app/spock", `
|
th.WriteK("/app/spock", `
|
||||||
namePrefix: spock-
|
namePrefix: spock-
|
||||||
resources:
|
resources:
|
||||||
@@ -88,7 +90,7 @@ spec:
|
|||||||
`)
|
`)
|
||||||
}
|
}
|
||||||
|
|
||||||
func writeBones(th testingHarness) {
|
func writeBones(th kusttest_test.Harness) {
|
||||||
th.WriteK("/app/bones", `
|
th.WriteK("/app/bones", `
|
||||||
namePrefix: bones-
|
namePrefix: bones-
|
||||||
resources:
|
resources:
|
||||||
@@ -106,7 +108,7 @@ spec:
|
|||||||
`)
|
`)
|
||||||
}
|
}
|
||||||
|
|
||||||
func writeTenants(th testingHarness) {
|
func writeTenants(th kusttest_test.Harness) {
|
||||||
th.WriteK("/app/tenants", `
|
th.WriteK("/app/tenants", `
|
||||||
namePrefix: t-
|
namePrefix: t-
|
||||||
resources:
|
resources:
|
||||||
@@ -137,7 +139,7 @@ data:
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestBasicDiamond(t *testing.T) {
|
func TestBasicDiamond(t *testing.T) {
|
||||||
th := makeTestHarness(t)
|
th := kusttest_test.MakeHarness(t)
|
||||||
writeDiamondBase(th)
|
writeDiamondBase(th)
|
||||||
writeKirk(th)
|
writeKirk(th)
|
||||||
writeSpock(th)
|
writeSpock(th)
|
||||||
|
|||||||
@@ -5,10 +5,12 @@ package krusty_test
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
kusttest_test "sigs.k8s.io/kustomize/api/testutils/kusttest"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestIssue596AllowDirectoriesThatAreSubstringsOfEachOther(t *testing.T) {
|
func TestIssue596AllowDirectoriesThatAreSubstringsOfEachOther(t *testing.T) {
|
||||||
th := makeTestHarness(t)
|
th := kusttest_test.MakeHarness(t)
|
||||||
th.WriteK("/app/base", "")
|
th.WriteK("/app/base", "")
|
||||||
th.WriteK("/app/overlays/aws", `
|
th.WriteK("/app/overlays/aws", `
|
||||||
resources:
|
resources:
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import (
|
|||||||
|
|
||||||
"sigs.k8s.io/kustomize/api/resmap"
|
"sigs.k8s.io/kustomize/api/resmap"
|
||||||
"sigs.k8s.io/kustomize/api/resource"
|
"sigs.k8s.io/kustomize/api/resource"
|
||||||
|
kusttest_test "sigs.k8s.io/kustomize/api/testutils/kusttest"
|
||||||
)
|
)
|
||||||
|
|
||||||
func findSecret(m resmap.ResMap) *resource.Resource {
|
func findSecret(m resmap.ResMap) *resource.Resource {
|
||||||
@@ -21,7 +22,7 @@ func findSecret(m resmap.ResMap) *resource.Resource {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestDisableNameSuffixHash(t *testing.T) {
|
func TestDisableNameSuffixHash(t *testing.T) {
|
||||||
th := makeTestHarness(t)
|
th := kusttest_test.MakeHarness(t)
|
||||||
const kustomizationContent = `
|
const kustomizationContent = `
|
||||||
apiVersion: kustomize.config.k8s.io/v1beta1
|
apiVersion: kustomize.config.k8s.io/v1beta1
|
||||||
kind: Kustomization
|
kind: Kustomization
|
||||||
|
|||||||
@@ -5,9 +5,11 @@ package krusty_test
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"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", `
|
th.WriteF("/app/base/deployment.yaml", `
|
||||||
apiVersion: apps/v1beta2
|
apiVersion: apps/v1beta2
|
||||||
kind: Deployment
|
kind: Deployment
|
||||||
@@ -87,7 +89,7 @@ spec:
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestExtendedPatchNameSelector(t *testing.T) {
|
func TestExtendedPatchNameSelector(t *testing.T) {
|
||||||
th := makeTestHarness(t)
|
th := kusttest_test.MakeHarness(t)
|
||||||
makeCommonFileForExtendedPatchTest(th)
|
makeCommonFileForExtendedPatchTest(th)
|
||||||
th.WriteK("/app/base", `
|
th.WriteK("/app/base", `
|
||||||
resources:
|
resources:
|
||||||
@@ -189,7 +191,7 @@ spec:
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestExtendedPatchGvkSelector(t *testing.T) {
|
func TestExtendedPatchGvkSelector(t *testing.T) {
|
||||||
th := makeTestHarness(t)
|
th := kusttest_test.MakeHarness(t)
|
||||||
makeCommonFileForExtendedPatchTest(th)
|
makeCommonFileForExtendedPatchTest(th)
|
||||||
th.WriteK("/app/base", `
|
th.WriteK("/app/base", `
|
||||||
resources:
|
resources:
|
||||||
@@ -291,7 +293,7 @@ spec:
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestExtendedPatchLabelSelector(t *testing.T) {
|
func TestExtendedPatchLabelSelector(t *testing.T) {
|
||||||
th := makeTestHarness(t)
|
th := kusttest_test.MakeHarness(t)
|
||||||
makeCommonFileForExtendedPatchTest(th)
|
makeCommonFileForExtendedPatchTest(th)
|
||||||
th.WriteK("/app/base", `
|
th.WriteK("/app/base", `
|
||||||
resources:
|
resources:
|
||||||
@@ -393,7 +395,7 @@ spec:
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestExtendedPatchNameGvkSelector(t *testing.T) {
|
func TestExtendedPatchNameGvkSelector(t *testing.T) {
|
||||||
th := makeTestHarness(t)
|
th := kusttest_test.MakeHarness(t)
|
||||||
makeCommonFileForExtendedPatchTest(th)
|
makeCommonFileForExtendedPatchTest(th)
|
||||||
th.WriteK("/app/base", `
|
th.WriteK("/app/base", `
|
||||||
resources:
|
resources:
|
||||||
@@ -494,7 +496,7 @@ spec:
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestExtendedPatchNameLabelSelector(t *testing.T) {
|
func TestExtendedPatchNameLabelSelector(t *testing.T) {
|
||||||
th := makeTestHarness(t)
|
th := kusttest_test.MakeHarness(t)
|
||||||
makeCommonFileForExtendedPatchTest(th)
|
makeCommonFileForExtendedPatchTest(th)
|
||||||
th.WriteK("/app/base", `
|
th.WriteK("/app/base", `
|
||||||
resources:
|
resources:
|
||||||
@@ -597,7 +599,7 @@ spec:
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestExtendedPatchGvkLabelSelector(t *testing.T) {
|
func TestExtendedPatchGvkLabelSelector(t *testing.T) {
|
||||||
th := makeTestHarness(t)
|
th := kusttest_test.MakeHarness(t)
|
||||||
makeCommonFileForExtendedPatchTest(th)
|
makeCommonFileForExtendedPatchTest(th)
|
||||||
th.WriteK("/app/base", `
|
th.WriteK("/app/base", `
|
||||||
resources:
|
resources:
|
||||||
@@ -698,7 +700,7 @@ spec:
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestExtendedPatchNameGvkLabelSelector(t *testing.T) {
|
func TestExtendedPatchNameGvkLabelSelector(t *testing.T) {
|
||||||
th := makeTestHarness(t)
|
th := kusttest_test.MakeHarness(t)
|
||||||
makeCommonFileForExtendedPatchTest(th)
|
makeCommonFileForExtendedPatchTest(th)
|
||||||
th.WriteK("/app/base", `
|
th.WriteK("/app/base", `
|
||||||
resources:
|
resources:
|
||||||
@@ -800,7 +802,7 @@ spec:
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestExtendedPatchNoMatch(t *testing.T) {
|
func TestExtendedPatchNoMatch(t *testing.T) {
|
||||||
th := makeTestHarness(t)
|
th := kusttest_test.MakeHarness(t)
|
||||||
makeCommonFileForExtendedPatchTest(th)
|
makeCommonFileForExtendedPatchTest(th)
|
||||||
th.WriteK("/app/base", `
|
th.WriteK("/app/base", `
|
||||||
resources:
|
resources:
|
||||||
@@ -898,7 +900,7 @@ spec:
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestExtendedPatchWithoutTarget(t *testing.T) {
|
func TestExtendedPatchWithoutTarget(t *testing.T) {
|
||||||
th := makeTestHarness(t)
|
th := kusttest_test.MakeHarness(t)
|
||||||
makeCommonFileForExtendedPatchTest(th)
|
makeCommonFileForExtendedPatchTest(th)
|
||||||
th.WriteK("/app/base", `
|
th.WriteK("/app/base", `
|
||||||
resources:
|
resources:
|
||||||
@@ -996,7 +998,7 @@ spec:
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestExtendedPatchNoMatchMultiplePatch(t *testing.T) {
|
func TestExtendedPatchNoMatchMultiplePatch(t *testing.T) {
|
||||||
th := makeTestHarness(t)
|
th := kusttest_test.MakeHarness(t)
|
||||||
makeCommonFileForExtendedPatchTest(th)
|
makeCommonFileForExtendedPatchTest(th)
|
||||||
th.WriteK("/app/base", `
|
th.WriteK("/app/base", `
|
||||||
resources:
|
resources:
|
||||||
@@ -1098,7 +1100,7 @@ spec:
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestExtendedPatchMultiplePatchOverlapping(t *testing.T) {
|
func TestExtendedPatchMultiplePatchOverlapping(t *testing.T) {
|
||||||
th := makeTestHarness(t)
|
th := kusttest_test.MakeHarness(t)
|
||||||
makeCommonFileForExtendedPatchTest(th)
|
makeCommonFileForExtendedPatchTest(th)
|
||||||
th.WriteK("/app/base", `
|
th.WriteK("/app/base", `
|
||||||
resources:
|
resources:
|
||||||
|
|||||||
@@ -6,10 +6,12 @@ package krusty_test
|
|||||||
import (
|
import (
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
kusttest_test "sigs.k8s.io/kustomize/api/testutils/kusttest"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestSimpleBase(t *testing.T) {
|
func TestSimpleBase(t *testing.T) {
|
||||||
th := makeTestHarness(t)
|
th := kusttest_test.MakeHarness(t)
|
||||||
th.WriteK("/app/base", `
|
th.WriteK("/app/base", `
|
||||||
apiVersion: kustomize.config.k8s.io/v1beta1
|
apiVersion: kustomize.config.k8s.io/v1beta1
|
||||||
kind: Kustomization
|
kind: Kustomization
|
||||||
@@ -146,7 +148,7 @@ spec:
|
|||||||
`)
|
`)
|
||||||
}
|
}
|
||||||
|
|
||||||
func makeBaseWithGenerators(th testingHarness) {
|
func makeBaseWithGenerators(th kusttest_test.Harness) {
|
||||||
th.WriteK("/app", `
|
th.WriteK("/app", `
|
||||||
apiVersion: kustomize.config.k8s.io/v1beta1
|
apiVersion: kustomize.config.k8s.io/v1beta1
|
||||||
kind: Kustomization
|
kind: Kustomization
|
||||||
@@ -212,7 +214,7 @@ spec:
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestBaseWithGeneratorsAlone(t *testing.T) {
|
func TestBaseWithGeneratorsAlone(t *testing.T) {
|
||||||
th := makeTestHarness(t)
|
th := kusttest_test.MakeHarness(t)
|
||||||
makeBaseWithGenerators(th)
|
makeBaseWithGenerators(th)
|
||||||
m := th.Run("/app", th.MakeDefaultOptions())
|
m := th.Run("/app", th.MakeDefaultOptions())
|
||||||
th.AssertActualEqualsExpected(m, `
|
th.AssertActualEqualsExpected(m, `
|
||||||
@@ -303,7 +305,7 @@ type: Opaque
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestMergeAndReplaceGenerators(t *testing.T) {
|
func TestMergeAndReplaceGenerators(t *testing.T) {
|
||||||
th := makeTestHarness(t)
|
th := kusttest_test.MakeHarness(t)
|
||||||
makeBaseWithGenerators(th)
|
makeBaseWithGenerators(th)
|
||||||
th.WriteF("/overlay/deployment.yaml", `
|
th.WriteF("/overlay/deployment.yaml", `
|
||||||
apiVersion: apps/v1beta2
|
apiVersion: apps/v1beta2
|
||||||
@@ -458,7 +460,7 @@ metadata:
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestGeneratingIntoNamespaces(t *testing.T) {
|
func TestGeneratingIntoNamespaces(t *testing.T) {
|
||||||
th := makeTestHarness(t)
|
th := kusttest_test.MakeHarness(t)
|
||||||
th.WriteK("/app", `
|
th.WriteK("/app", `
|
||||||
configMapGenerator:
|
configMapGenerator:
|
||||||
- name: test
|
- name: test
|
||||||
@@ -524,7 +526,7 @@ type: Opaque
|
|||||||
// Valid that conflict is detected is the name are identical
|
// Valid that conflict is detected is the name are identical
|
||||||
// and namespace left to default
|
// and namespace left to default
|
||||||
func TestConfigMapGeneratingIntoSameNamespace(t *testing.T) {
|
func TestConfigMapGeneratingIntoSameNamespace(t *testing.T) {
|
||||||
th := makeTestHarness(t)
|
th := kusttest_test.MakeHarness(t)
|
||||||
th.WriteK("/app", `
|
th.WriteK("/app", `
|
||||||
configMapGenerator:
|
configMapGenerator:
|
||||||
- name: test
|
- name: test
|
||||||
@@ -547,7 +549,7 @@ configMapGenerator:
|
|||||||
// Valid that conflict is detected is the name are identical
|
// Valid that conflict is detected is the name are identical
|
||||||
// and namespace left to default
|
// and namespace left to default
|
||||||
func TestSecretGeneratingIntoSameNamespace(t *testing.T) {
|
func TestSecretGeneratingIntoSameNamespace(t *testing.T) {
|
||||||
th := makeTestHarness(t)
|
th := kusttest_test.MakeHarness(t)
|
||||||
th.WriteK("/app", `
|
th.WriteK("/app", `
|
||||||
secretGenerator:
|
secretGenerator:
|
||||||
- name: test
|
- name: test
|
||||||
|
|||||||
@@ -5,10 +5,12 @@ package krusty_test
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
kusttest_test "sigs.k8s.io/kustomize/api/testutils/kusttest"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestSecretGenerator(t *testing.T) {
|
func TestSecretGenerator(t *testing.T) {
|
||||||
th := makeTestHarness(t)
|
th := kusttest_test.MakeHarness(t)
|
||||||
th.WriteK("/app", `
|
th.WriteK("/app", `
|
||||||
secretGenerator:
|
secretGenerator:
|
||||||
- name: bob
|
- name: bob
|
||||||
@@ -44,7 +46,7 @@ type: Opaque
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestGeneratorOptionsWithBases(t *testing.T) {
|
func TestGeneratorOptionsWithBases(t *testing.T) {
|
||||||
th := makeTestHarness(t)
|
th := kusttest_test.MakeHarness(t)
|
||||||
th.WriteK("/app/base", `
|
th.WriteK("/app/base", `
|
||||||
apiVersion: kustomize.config.k8s.io/v1beta1
|
apiVersion: kustomize.config.k8s.io/v1beta1
|
||||||
kind: Kustomization
|
kind: Kustomization
|
||||||
|
|||||||
@@ -5,9 +5,11 @@ package krusty_test
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"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", `
|
th.WriteF("/app/base/deployment.yaml", `
|
||||||
apiVersion: apps/v1
|
apiVersion: apps/v1
|
||||||
kind: Deployment
|
kind: Deployment
|
||||||
@@ -37,7 +39,7 @@ spec:
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestStrategicMergePatchInline(t *testing.T) {
|
func TestStrategicMergePatchInline(t *testing.T) {
|
||||||
th := makeTestHarness(t)
|
th := kusttest_test.MakeHarness(t)
|
||||||
makeResourcesForPatchTest(th)
|
makeResourcesForPatchTest(th)
|
||||||
th.WriteK("/app/base", `
|
th.WriteK("/app/base", `
|
||||||
resources:
|
resources:
|
||||||
@@ -86,7 +88,7 @@ spec:
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestJSONPatchInline(t *testing.T) {
|
func TestJSONPatchInline(t *testing.T) {
|
||||||
th := makeTestHarness(t)
|
th := kusttest_test.MakeHarness(t)
|
||||||
makeResourcesForPatchTest(th)
|
makeResourcesForPatchTest(th)
|
||||||
th.WriteK("/app/base", `
|
th.WriteK("/app/base", `
|
||||||
resources:
|
resources:
|
||||||
@@ -133,7 +135,7 @@ spec:
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestExtendedPatchInlineJSON(t *testing.T) {
|
func TestExtendedPatchInlineJSON(t *testing.T) {
|
||||||
th := makeTestHarness(t)
|
th := kusttest_test.MakeHarness(t)
|
||||||
makeResourcesForPatchTest(th)
|
makeResourcesForPatchTest(th)
|
||||||
th.WriteK("/app/base", `
|
th.WriteK("/app/base", `
|
||||||
resources:
|
resources:
|
||||||
@@ -178,7 +180,7 @@ spec:
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestExtendedPatchInlineYAML(t *testing.T) {
|
func TestExtendedPatchInlineYAML(t *testing.T) {
|
||||||
th := makeTestHarness(t)
|
th := kusttest_test.MakeHarness(t)
|
||||||
makeResourcesForPatchTest(th)
|
makeResourcesForPatchTest(th)
|
||||||
th.WriteK("/app/base", `
|
th.WriteK("/app/base", `
|
||||||
resources:
|
resources:
|
||||||
|
|||||||
@@ -6,9 +6,11 @@ package krusty_test
|
|||||||
import (
|
import (
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
kusttest_test "sigs.k8s.io/kustomize/api/testutils/kusttest"
|
||||||
)
|
)
|
||||||
|
|
||||||
func makeCommonFileForMultiplePatchTest(th testingHarness) {
|
func makeCommonFileForMultiplePatchTest(th kusttest_test.Harness) {
|
||||||
th.WriteK("/app/base", `
|
th.WriteK("/app/base", `
|
||||||
apiVersion: kustomize.config.k8s.io/v1beta1
|
apiVersion: kustomize.config.k8s.io/v1beta1
|
||||||
kind: Kustomization
|
kind: Kustomization
|
||||||
@@ -87,7 +89,7 @@ configMapGenerator:
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestMultiplePatchesNoConflict(t *testing.T) {
|
func TestMultiplePatchesNoConflict(t *testing.T) {
|
||||||
th := makeTestHarness(t)
|
th := kusttest_test.MakeHarness(t)
|
||||||
makeCommonFileForMultiplePatchTest(th)
|
makeCommonFileForMultiplePatchTest(th)
|
||||||
th.WriteF("/app/overlay/staging/deployment-patch1.yaml", `
|
th.WriteF("/app/overlay/staging/deployment-patch1.yaml", `
|
||||||
apiVersion: apps/v1beta2
|
apiVersion: apps/v1beta2
|
||||||
@@ -228,7 +230,7 @@ metadata:
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestMultiplePatchesWithConflict(t *testing.T) {
|
func TestMultiplePatchesWithConflict(t *testing.T) {
|
||||||
th := makeTestHarness(t)
|
th := kusttest_test.MakeHarness(t)
|
||||||
makeCommonFileForMultiplePatchTest(th)
|
makeCommonFileForMultiplePatchTest(th)
|
||||||
th.WriteF("/app/overlay/staging/deployment-patch1.yaml", `
|
th.WriteF("/app/overlay/staging/deployment-patch1.yaml", `
|
||||||
apiVersion: apps/v1beta2
|
apiVersion: apps/v1beta2
|
||||||
@@ -320,7 +322,7 @@ spec:
|
|||||||
}
|
}
|
||||||
for _, c := range cases {
|
for _, c := range cases {
|
||||||
t.Run(c.name, func(t *testing.T) {
|
t.Run(c.name, func(t *testing.T) {
|
||||||
th := makeTestHarness(t)
|
th := kusttest_test.MakeHarness(t)
|
||||||
|
|
||||||
makeCommonFileForMultiplePatchTest(th)
|
makeCommonFileForMultiplePatchTest(th)
|
||||||
th.WriteF("/app/overlay/staging/deployment-patch1.yaml", c.patch1)
|
th.WriteF("/app/overlay/staging/deployment-patch1.yaml", c.patch1)
|
||||||
@@ -418,7 +420,7 @@ metadata:
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestMultiplePatchesBothWithPatchDeleteDirective(t *testing.T) {
|
func TestMultiplePatchesBothWithPatchDeleteDirective(t *testing.T) {
|
||||||
th := makeTestHarness(t)
|
th := kusttest_test.MakeHarness(t)
|
||||||
makeCommonFileForMultiplePatchTest(th)
|
makeCommonFileForMultiplePatchTest(th)
|
||||||
th.WriteF("/app/overlay/staging/deployment-patch1.yaml", `
|
th.WriteF("/app/overlay/staging/deployment-patch1.yaml", `
|
||||||
apiVersion: apps/v1beta2
|
apiVersion: apps/v1beta2
|
||||||
|
|||||||
@@ -5,10 +5,12 @@ package krusty_test
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
kusttest_test "sigs.k8s.io/kustomize/api/testutils/kusttest"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestNamespacedGenerator(t *testing.T) {
|
func TestNamespacedGenerator(t *testing.T) {
|
||||||
th := makeTestHarness(t)
|
th := kusttest_test.MakeHarness(t)
|
||||||
th.WriteK("/app", `
|
th.WriteK("/app", `
|
||||||
apiVersion: kustomize.config.k8s.io/v1beta1
|
apiVersion: kustomize.config.k8s.io/v1beta1
|
||||||
kind: Kustomization
|
kind: Kustomization
|
||||||
@@ -71,7 +73,7 @@ type: Opaque
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestNamespacedGeneratorWithOverlays(t *testing.T) {
|
func TestNamespacedGeneratorWithOverlays(t *testing.T) {
|
||||||
th := makeTestHarness(t)
|
th := kusttest_test.MakeHarness(t)
|
||||||
th.WriteK("/app/base", `
|
th.WriteK("/app/base", `
|
||||||
namespace: base
|
namespace: base
|
||||||
|
|
||||||
|
|||||||
@@ -6,10 +6,12 @@ package krusty_test
|
|||||||
import (
|
import (
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
kusttest_test "sigs.k8s.io/kustomize/api/testutils/kusttest"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestNamespacedSecrets(t *testing.T) {
|
func TestNamespacedSecrets(t *testing.T) {
|
||||||
th := makeTestHarness(t)
|
th := kusttest_test.MakeHarness(t)
|
||||||
th.WriteF("/app/secrets.yaml", `
|
th.WriteF("/app/secrets.yaml", `
|
||||||
apiVersion: v1
|
apiVersion: v1
|
||||||
kind: Secret
|
kind: Secret
|
||||||
@@ -93,7 +95,7 @@ rules:
|
|||||||
// PrefixSuffixTransformer and namereference transformers are
|
// PrefixSuffixTransformer and namereference transformers are
|
||||||
// able to deal with simultaneous change of namespace and name.
|
// able to deal with simultaneous change of namespace and name.
|
||||||
func TestNameAndNsTransformation(t *testing.T) {
|
func TestNameAndNsTransformation(t *testing.T) {
|
||||||
th := makeTestHarness(t)
|
th := kusttest_test.MakeHarness(t)
|
||||||
|
|
||||||
th.WriteK("/nameandns", `
|
th.WriteK("/nameandns", `
|
||||||
namePrefix: p1-
|
namePrefix: p1-
|
||||||
@@ -463,7 +465,7 @@ spec:
|
|||||||
// using the same name in different namespaces are treated as ambiguous if the namespace is
|
// using the same name in different namespaces are treated as ambiguous if the namespace is
|
||||||
// not specified
|
// not specified
|
||||||
func TestVariablesAmbiguous(t *testing.T) {
|
func TestVariablesAmbiguous(t *testing.T) {
|
||||||
th := makeTestHarness(t)
|
th := kusttest_test.MakeHarness(t)
|
||||||
th.WriteK("/namespaceNeedInVar/myapp", namespaceNeedInVarMyApp)
|
th.WriteK("/namespaceNeedInVar/myapp", namespaceNeedInVarMyApp)
|
||||||
th.WriteF("/namespaceNeedInVar/myapp/elasticsearch-dev-service.yaml", namespaceNeedInVarDevResources)
|
th.WriteF("/namespaceNeedInVar/myapp/elasticsearch-dev-service.yaml", namespaceNeedInVarDevResources)
|
||||||
th.WriteF("/namespaceNeedInVar/myapp/elasticsearch-test-service.yaml", namespaceNeedInVarTestResources)
|
th.WriteF("/namespaceNeedInVar/myapp/elasticsearch-test-service.yaml", namespaceNeedInVarTestResources)
|
||||||
@@ -520,7 +522,7 @@ vars:
|
|||||||
// to TestVariablesAmbiguous problem. It requires to separate the variables
|
// to TestVariablesAmbiguous problem. It requires to separate the variables
|
||||||
// and resources into multiple kustomization context/folders instead of one.
|
// and resources into multiple kustomization context/folders instead of one.
|
||||||
func TestVariablesAmbiguousWorkaround(t *testing.T) {
|
func TestVariablesAmbiguousWorkaround(t *testing.T) {
|
||||||
th := makeTestHarness(t)
|
th := kusttest_test.MakeHarness(t)
|
||||||
th.WriteK("/namespaceNeedInVar/dev", namespaceNeedInVarDevFolder)
|
th.WriteK("/namespaceNeedInVar/dev", namespaceNeedInVarDevFolder)
|
||||||
th.WriteF("/namespaceNeedInVar/dev/elasticsearch-dev-service.yaml", namespaceNeedInVarDevResources)
|
th.WriteF("/namespaceNeedInVar/dev/elasticsearch-dev-service.yaml", namespaceNeedInVarDevResources)
|
||||||
th.WriteK("/namespaceNeedInVar/test", namespaceNeedInVarTestFolder)
|
th.WriteK("/namespaceNeedInVar/test", namespaceNeedInVarTestFolder)
|
||||||
@@ -576,7 +578,7 @@ vars:
|
|||||||
// TestVariablesDisambiguatedWithNamespace demonstrates that adding the namespace
|
// TestVariablesDisambiguatedWithNamespace demonstrates that adding the namespace
|
||||||
// to the variable declarations allows to disambiguate the variables.
|
// to the variable declarations allows to disambiguate the variables.
|
||||||
func TestVariablesDisambiguatedWithNamespace(t *testing.T) {
|
func TestVariablesDisambiguatedWithNamespace(t *testing.T) {
|
||||||
th := makeTestHarness(t)
|
th := kusttest_test.MakeHarness(t)
|
||||||
th.WriteK("/namespaceNeedInVar/myapp", namespaceNeedInVarMyAppWithNamespace)
|
th.WriteK("/namespaceNeedInVar/myapp", namespaceNeedInVarMyAppWithNamespace)
|
||||||
th.WriteF("/namespaceNeedInVar/myapp/elasticsearch-dev-service.yaml", namespaceNeedInVarDevResources)
|
th.WriteF("/namespaceNeedInVar/myapp/elasticsearch-dev-service.yaml", namespaceNeedInVarDevResources)
|
||||||
th.WriteF("/namespaceNeedInVar/myapp/elasticsearch-test-service.yaml", namespaceNeedInVarTestResources)
|
th.WriteF("/namespaceNeedInVar/myapp/elasticsearch-test-service.yaml", namespaceNeedInVarTestResources)
|
||||||
|
|||||||
@@ -5,10 +5,12 @@ package krusty_test
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
kusttest_test "sigs.k8s.io/kustomize/api/testutils/kusttest"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestNullValues(t *testing.T) {
|
func TestNullValues(t *testing.T) {
|
||||||
th := makeTestHarness(t)
|
th := kusttest_test.MakeHarness(t)
|
||||||
th.WriteF("/app/deployment.yaml", `
|
th.WriteF("/app/deployment.yaml", `
|
||||||
apiVersion: apps/v1
|
apiVersion: apps/v1
|
||||||
kind: Deployment
|
kind: Deployment
|
||||||
|
|||||||
@@ -25,17 +25,17 @@ func TestPluginEnvironment(t *testing.T) {
|
|||||||
"someteam.example.com", "v1", "PrintPluginEnv")
|
"someteam.example.com", "v1", "PrintPluginEnv")
|
||||||
|
|
||||||
confirmBehavior(
|
confirmBehavior(
|
||||||
makeTestHarnessWithFs(t, filesys.MakeFsInMemory()),
|
kusttest_test.MakeHarnessWithFs(t, filesys.MakeFsInMemory()),
|
||||||
filesys.Separator)
|
filesys.Separator)
|
||||||
|
|
||||||
dir := makeTmpDir(t)
|
dir := makeTmpDir(t)
|
||||||
defer os.RemoveAll(dir)
|
defer os.RemoveAll(dir)
|
||||||
confirmBehavior(
|
confirmBehavior(
|
||||||
makeTestHarnessWithFs(t, filesys.MakeFsOnDisk()),
|
kusttest_test.MakeHarnessWithFs(t, filesys.MakeFsOnDisk()),
|
||||||
dir)
|
dir)
|
||||||
}
|
}
|
||||||
|
|
||||||
func confirmBehavior(th testingHarness, dir string) {
|
func confirmBehavior(th kusttest_test.Harness, dir string) {
|
||||||
th.WriteK(dir, `
|
th.WriteK(dir, `
|
||||||
generators:
|
generators:
|
||||||
- config.yaml
|
- config.yaml
|
||||||
|
|||||||
@@ -5,10 +5,12 @@ package krusty_test
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
kusttest_test "sigs.k8s.io/kustomize/api/testutils/kusttest"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestPruneConfigMap(t *testing.T) {
|
func TestPruneConfigMap(t *testing.T) {
|
||||||
th := makeTestHarness(t)
|
th := kusttest_test.MakeHarness(t)
|
||||||
th.WriteK("/app/base", `
|
th.WriteK("/app/base", `
|
||||||
resources:
|
resources:
|
||||||
- deployment.yaml
|
- deployment.yaml
|
||||||
|
|||||||
@@ -6,9 +6,11 @@ package krusty_test
|
|||||||
import (
|
import (
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
kusttest_test "sigs.k8s.io/kustomize/api/testutils/kusttest"
|
||||||
)
|
)
|
||||||
|
|
||||||
func writeBase(th testingHarness) {
|
func writeBase(th kusttest_test.Harness) {
|
||||||
th.WriteK("/app/base", `
|
th.WriteK("/app/base", `
|
||||||
resources:
|
resources:
|
||||||
- serviceaccount.yaml
|
- serviceaccount.yaml
|
||||||
@@ -62,7 +64,7 @@ rules:
|
|||||||
`)
|
`)
|
||||||
}
|
}
|
||||||
|
|
||||||
func writeMidOverlays(th testingHarness) {
|
func writeMidOverlays(th kusttest_test.Harness) {
|
||||||
// Mid-level overlays
|
// Mid-level overlays
|
||||||
th.WriteK("/app/overlays/a", `
|
th.WriteK("/app/overlays/a", `
|
||||||
resources:
|
resources:
|
||||||
@@ -78,7 +80,7 @@ nameSuffix: -suffixB
|
|||||||
`)
|
`)
|
||||||
}
|
}
|
||||||
|
|
||||||
func writeTopOverlay(th testingHarness) {
|
func writeTopOverlay(th kusttest_test.Harness) {
|
||||||
// Top overlay, combining the mid-level overlays
|
// Top overlay, combining the mid-level overlays
|
||||||
th.WriteK("/app/combined", `
|
th.WriteK("/app/combined", `
|
||||||
resources:
|
resources:
|
||||||
@@ -89,7 +91,7 @@ resources:
|
|||||||
|
|
||||||
func TestBase(t *testing.T) {
|
func TestBase(t *testing.T) {
|
||||||
//th := kusttest_test.NewKustTestHarness(t, "/app/base")
|
//th := kusttest_test.NewKustTestHarness(t, "/app/base")
|
||||||
th := makeTestHarness(t)
|
th := kusttest_test.MakeHarness(t)
|
||||||
writeBase(th)
|
writeBase(th)
|
||||||
m := th.Run("/app/base", th.MakeDefaultOptions())
|
m := th.Run("/app/base", th.MakeDefaultOptions())
|
||||||
th.AssertActualEqualsExpected(m, `
|
th.AssertActualEqualsExpected(m, `
|
||||||
@@ -139,7 +141,7 @@ rules:
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestMidLevelA(t *testing.T) {
|
func TestMidLevelA(t *testing.T) {
|
||||||
th := makeTestHarness(t)
|
th := kusttest_test.MakeHarness(t)
|
||||||
writeBase(th)
|
writeBase(th)
|
||||||
writeMidOverlays(th)
|
writeMidOverlays(th)
|
||||||
m := th.Run("/app/overlays/a", th.MakeDefaultOptions())
|
m := th.Run("/app/overlays/a", th.MakeDefaultOptions())
|
||||||
@@ -190,7 +192,7 @@ rules:
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestMidLevelB(t *testing.T) {
|
func TestMidLevelB(t *testing.T) {
|
||||||
th := makeTestHarness(t)
|
th := kusttest_test.MakeHarness(t)
|
||||||
writeBase(th)
|
writeBase(th)
|
||||||
writeMidOverlays(th)
|
writeMidOverlays(th)
|
||||||
m := th.Run("/app/overlays/b", th.MakeDefaultOptions())
|
m := th.Run("/app/overlays/b", th.MakeDefaultOptions())
|
||||||
@@ -241,7 +243,7 @@ rules:
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestMultibasesNoConflict(t *testing.T) {
|
func TestMultibasesNoConflict(t *testing.T) {
|
||||||
th := makeTestHarness(t)
|
th := kusttest_test.MakeHarness(t)
|
||||||
writeBase(th)
|
writeBase(th)
|
||||||
writeMidOverlays(th)
|
writeMidOverlays(th)
|
||||||
writeTopOverlay(th)
|
writeTopOverlay(th)
|
||||||
@@ -336,7 +338,7 @@ rules:
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestMultibasesWithConflict(t *testing.T) {
|
func TestMultibasesWithConflict(t *testing.T) {
|
||||||
th := makeTestHarness(t)
|
th := kusttest_test.MakeHarness(t)
|
||||||
//th := kusttest_test.NewKustTestHarness(t, "/app/combined")
|
//th := kusttest_test.NewKustTestHarness(t, "/app/combined")
|
||||||
writeBase(th)
|
writeBase(th)
|
||||||
writeMidOverlays(th)
|
writeMidOverlays(th)
|
||||||
|
|||||||
@@ -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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -10,7 +10,7 @@ import (
|
|||||||
"sigs.k8s.io/kustomize/api/types"
|
"sigs.k8s.io/kustomize/api/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
func writeDeployment(th testingHarness, path string) {
|
func writeDeployment(th kusttest_test.Harness, path string) {
|
||||||
th.WriteF(path, `
|
th.WriteF(path, `
|
||||||
apiVersion: apps/v1
|
apiVersion: apps/v1
|
||||||
kind: Deployment
|
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, `
|
th.WriteF(path, `
|
||||||
apiVersion: someteam.example.com/v1
|
apiVersion: someteam.example.com/v1
|
||||||
kind: StringPrefixer
|
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, `
|
th.WriteF(path, `
|
||||||
apiVersion: someteam.example.com/v1
|
apiVersion: someteam.example.com/v1
|
||||||
kind: DatePrefixer
|
kind: DatePrefixer
|
||||||
@@ -55,7 +55,7 @@ func TestOrderedTransformers(t *testing.T) {
|
|||||||
|
|
||||||
tc.BuildGoPlugin(
|
tc.BuildGoPlugin(
|
||||||
"someteam.example.com", "v1", "DatePrefixer")
|
"someteam.example.com", "v1", "DatePrefixer")
|
||||||
th := makeTestHarness(t)
|
th := kusttest_test.MakeHarness(t)
|
||||||
th.WriteK("/app", `
|
th.WriteK("/app", `
|
||||||
resources:
|
resources:
|
||||||
- deployment.yaml
|
- deployment.yaml
|
||||||
@@ -95,7 +95,7 @@ func TestPluginsNotEnabled(t *testing.T) {
|
|||||||
tc.BuildGoPlugin(
|
tc.BuildGoPlugin(
|
||||||
"someteam.example.com", "v1", "StringPrefixer")
|
"someteam.example.com", "v1", "StringPrefixer")
|
||||||
|
|
||||||
th := makeTestHarness(t)
|
th := kusttest_test.MakeHarness(t)
|
||||||
th.WriteK("/app", `
|
th.WriteK("/app", `
|
||||||
transformers:
|
transformers:
|
||||||
- stringPrefixer.yaml
|
- stringPrefixer.yaml
|
||||||
@@ -117,7 +117,7 @@ func TestSedTransformer(t *testing.T) {
|
|||||||
tc.PrepExecPlugin(
|
tc.PrepExecPlugin(
|
||||||
"someteam.example.com", "v1", "SedTransformer")
|
"someteam.example.com", "v1", "SedTransformer")
|
||||||
|
|
||||||
th := makeTestHarness(t)
|
th := kusttest_test.MakeHarness(t)
|
||||||
th.WriteK("/app", `
|
th.WriteK("/app", `
|
||||||
resources:
|
resources:
|
||||||
- configmap.yaml
|
- configmap.yaml
|
||||||
@@ -185,7 +185,7 @@ func TestTransformedTransformers(t *testing.T) {
|
|||||||
tc.BuildGoPlugin(
|
tc.BuildGoPlugin(
|
||||||
"someteam.example.com", "v1", "DatePrefixer")
|
"someteam.example.com", "v1", "DatePrefixer")
|
||||||
|
|
||||||
th := makeTestHarness(t)
|
th := kusttest_test.MakeHarness(t)
|
||||||
|
|
||||||
th.WriteK("/app/base", `
|
th.WriteK("/app/base", `
|
||||||
resources:
|
resources:
|
||||||
|
|||||||
@@ -5,9 +5,11 @@ package krusty_test
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
kusttest_test "sigs.k8s.io/kustomize/api/testutils/kusttest"
|
||||||
)
|
)
|
||||||
|
|
||||||
func makeStatefulSetKustomization(th testingHarness) {
|
func makeStatefulSetKustomization(th kusttest_test.Harness) {
|
||||||
th.WriteK("/app", `
|
th.WriteK("/app", `
|
||||||
commonLabels:
|
commonLabels:
|
||||||
notIn: arrays
|
notIn: arrays
|
||||||
@@ -90,7 +92,7 @@ spec:
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestTransformersNoCreateArrays(t *testing.T) {
|
func TestTransformersNoCreateArrays(t *testing.T) {
|
||||||
th := makeTestHarness(t)
|
th := kusttest_test.MakeHarness(t)
|
||||||
makeStatefulSetKustomization(th)
|
makeStatefulSetKustomization(th)
|
||||||
m := th.Run("/app", th.MakeDefaultOptions())
|
m := th.Run("/app", th.MakeDefaultOptions())
|
||||||
th.AssertActualEqualsExpected(m, `
|
th.AssertActualEqualsExpected(m, `
|
||||||
|
|||||||
@@ -5,9 +5,11 @@ package krusty_test
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
kusttest_test "sigs.k8s.io/kustomize/api/testutils/kusttest"
|
||||||
)
|
)
|
||||||
|
|
||||||
func makeTransfomersImageBase(th testingHarness) {
|
func makeTransfomersImageBase(th kusttest_test.Harness) {
|
||||||
th.WriteK("/app/base", `
|
th.WriteK("/app/base", `
|
||||||
resources:
|
resources:
|
||||||
- deploy1.yaml
|
- deploy1.yaml
|
||||||
@@ -92,7 +94,7 @@ spec3:
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestIssue1281_JsonPatchAndImageTag(t *testing.T) {
|
func TestIssue1281_JsonPatchAndImageTag(t *testing.T) {
|
||||||
th := makeTestHarness(t)
|
th := kusttest_test.MakeHarness(t)
|
||||||
th.WriteK("/app", `
|
th.WriteK("/app", `
|
||||||
resources:
|
resources:
|
||||||
- deployment.yaml
|
- deployment.yaml
|
||||||
@@ -172,7 +174,7 @@ spec:
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestTransfomersImageDefaultConfig(t *testing.T) {
|
func TestTransfomersImageDefaultConfig(t *testing.T) {
|
||||||
th := makeTestHarness(t)
|
th := kusttest_test.MakeHarness(t)
|
||||||
makeTransfomersImageBase(th)
|
makeTransfomersImageBase(th)
|
||||||
m := th.Run("/app/base", th.MakeDefaultOptions())
|
m := th.Run("/app/base", th.MakeDefaultOptions())
|
||||||
th.AssertActualEqualsExpected(m, `
|
th.AssertActualEqualsExpected(m, `
|
||||||
@@ -233,7 +235,7 @@ spec3:
|
|||||||
`)
|
`)
|
||||||
}
|
}
|
||||||
|
|
||||||
func makeTransfomersImageCustomBase(th testingHarness) {
|
func makeTransfomersImageCustomBase(th kusttest_test.Harness) {
|
||||||
th.WriteK("/app/base", `
|
th.WriteK("/app/base", `
|
||||||
resources:
|
resources:
|
||||||
- custom.yaml
|
- custom.yaml
|
||||||
@@ -306,7 +308,7 @@ images:
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestTransfomersImageCustomConfig(t *testing.T) {
|
func TestTransfomersImageCustomConfig(t *testing.T) {
|
||||||
th := makeTestHarness(t)
|
th := kusttest_test.MakeHarness(t)
|
||||||
makeTransfomersImageCustomBase(th)
|
makeTransfomersImageCustomBase(th)
|
||||||
m := th.Run("/app/base", th.MakeDefaultOptions())
|
m := th.Run("/app/base", th.MakeDefaultOptions())
|
||||||
th.AssertActualEqualsExpected(m, `
|
th.AssertActualEqualsExpected(m, `
|
||||||
@@ -346,7 +348,7 @@ spec3:
|
|||||||
`)
|
`)
|
||||||
}
|
}
|
||||||
|
|
||||||
func makeTransfomersImageKnativeBase(th testingHarness) {
|
func makeTransfomersImageKnativeBase(th kusttest_test.Harness) {
|
||||||
th.WriteK("/app/base", `
|
th.WriteK("/app/base", `
|
||||||
resources:
|
resources:
|
||||||
- knative.yaml
|
- knative.yaml
|
||||||
@@ -378,7 +380,7 @@ images:
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestTransfomersImageKnativeConfig(t *testing.T) {
|
func TestTransfomersImageKnativeConfig(t *testing.T) {
|
||||||
th := makeTestHarness(t)
|
th := kusttest_test.MakeHarness(t)
|
||||||
makeTransfomersImageKnativeBase(th)
|
makeTransfomersImageKnativeBase(th)
|
||||||
m := th.Run("/app/base", th.MakeDefaultOptions())
|
m := th.Run("/app/base", th.MakeDefaultOptions())
|
||||||
th.AssertActualEqualsExpected(m, `
|
th.AssertActualEqualsExpected(m, `
|
||||||
|
|||||||
@@ -6,10 +6,12 @@ package krusty_test
|
|||||||
import (
|
import (
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
kusttest_test "sigs.k8s.io/kustomize/api/testutils/kusttest"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestBasicVariableRef(t *testing.T) {
|
func TestBasicVariableRef(t *testing.T) {
|
||||||
th := makeTestHarness(t)
|
th := kusttest_test.MakeHarness(t)
|
||||||
th.WriteK("/app", `
|
th.WriteK("/app", `
|
||||||
namePrefix: base-
|
namePrefix: base-
|
||||||
resources:
|
resources:
|
||||||
@@ -60,7 +62,7 @@ spec:
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestBasicVarCollision(t *testing.T) {
|
func TestBasicVarCollision(t *testing.T) {
|
||||||
th := makeTestHarness(t)
|
th := kusttest_test.MakeHarness(t)
|
||||||
th.WriteK("/app/base1", `
|
th.WriteK("/app/base1", `
|
||||||
namePrefix: base1-
|
namePrefix: base1-
|
||||||
resources:
|
resources:
|
||||||
@@ -136,7 +138,7 @@ resources:
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestVarPropagatesUp(t *testing.T) {
|
func TestVarPropagatesUp(t *testing.T) {
|
||||||
th := makeTestHarness(t)
|
th := kusttest_test.MakeHarness(t)
|
||||||
th.WriteK("/app/base1", `
|
th.WriteK("/app/base1", `
|
||||||
namePrefix: base1-
|
namePrefix: base1-
|
||||||
resources:
|
resources:
|
||||||
@@ -279,7 +281,7 @@ spec:
|
|||||||
// are global. So if a base with a variable is included
|
// are global. So if a base with a variable is included
|
||||||
// twice, it's a collision, so it's denied.
|
// twice, it's a collision, so it's denied.
|
||||||
func TestBug506(t *testing.T) {
|
func TestBug506(t *testing.T) {
|
||||||
th := makeTestHarness(t)
|
th := kusttest_test.MakeHarness(t)
|
||||||
th.WriteK("/app/base", `
|
th.WriteK("/app/base", `
|
||||||
namePrefix: base-
|
namePrefix: base-
|
||||||
resources:
|
resources:
|
||||||
@@ -359,7 +361,7 @@ resources:
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestVarRefBig(t *testing.T) {
|
func TestVarRefBig(t *testing.T) {
|
||||||
th := makeTestHarness(t)
|
th := kusttest_test.MakeHarness(t)
|
||||||
th.WriteK("/app/base", `
|
th.WriteK("/app/base", `
|
||||||
namePrefix: base-
|
namePrefix: base-
|
||||||
resources:
|
resources:
|
||||||
@@ -925,7 +927,7 @@ metadata:
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestVariableRefIngress(t *testing.T) {
|
func TestVariableRefIngress(t *testing.T) {
|
||||||
th := makeTestHarness(t)
|
th := kusttest_test.MakeHarness(t)
|
||||||
th.WriteK("/app/base", `
|
th.WriteK("/app/base", `
|
||||||
resources:
|
resources:
|
||||||
- service.yaml
|
- service.yaml
|
||||||
@@ -1064,7 +1066,7 @@ spec:
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestVariableRefMountPath(t *testing.T) {
|
func TestVariableRefMountPath(t *testing.T) {
|
||||||
th := makeTestHarness(t)
|
th := kusttest_test.MakeHarness(t)
|
||||||
th.WriteK("/app/base", `
|
th.WriteK("/app/base", `
|
||||||
resources:
|
resources:
|
||||||
- deployment.yaml
|
- deployment.yaml
|
||||||
@@ -1136,7 +1138,7 @@ metadata:
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestVariableRefMaps(t *testing.T) {
|
func TestVariableRefMaps(t *testing.T) {
|
||||||
th := makeTestHarness(t)
|
th := kusttest_test.MakeHarness(t)
|
||||||
th.WriteK("/app/base", `
|
th.WriteK("/app/base", `
|
||||||
resources:
|
resources:
|
||||||
- deployment.yaml
|
- deployment.yaml
|
||||||
@@ -1192,7 +1194,7 @@ metadata:
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestVaribaleRefDifferentPrefix(t *testing.T) {
|
func TestVaribaleRefDifferentPrefix(t *testing.T) {
|
||||||
th := makeTestHarness(t)
|
th := kusttest_test.MakeHarness(t)
|
||||||
th.WriteK("/app/base", `
|
th.WriteK("/app/base", `
|
||||||
namePrefix: base-
|
namePrefix: base-
|
||||||
resources:
|
resources:
|
||||||
|
|||||||
126
api/testutils/kusttest/harness.go
Normal file
126
api/testutils/kusttest/harness.go
Normal file
@@ -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)
|
||||||
|
}
|
||||||
104
api/testutils/kusttest/harnessenhanced.go
Normal file
104
api/testutils/kusttest/harnessenhanced.go
Normal file
@@ -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
|
||||||
|
}
|
||||||
104
api/testutils/kusttest/hasgett.go
Normal file
104
api/testutils/kusttest/hasgett.go
Normal file
@@ -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, "")
|
||||||
|
}
|
||||||
@@ -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")
|
|
||||||
}
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
for f in $(find ./ -name '*.go'); do
|
for f in $(find $1 -name '*.go'); do
|
||||||
echo $f
|
echo $f
|
||||||
# go run go.coder.com/go-tools/cmd/goimports
|
# go run go.coder.com/go-tools/cmd/goimports
|
||||||
~/gopath/bin/goimports -w $f
|
~/gopath/bin/goimports -w $f
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ func TestAnnotationsTransformer(t *testing.T) {
|
|||||||
tc.BuildGoPlugin(
|
tc.BuildGoPlugin(
|
||||||
"builtin", "", "AnnotationsTransformer")
|
"builtin", "", "AnnotationsTransformer")
|
||||||
|
|
||||||
th := kusttest_test.NewKustTestHarnessAllowPlugins(t, "/app")
|
th := kusttest_test.MakeHarnessEnhanced(t, "/app")
|
||||||
|
|
||||||
rm := th.LoadAndRunTransformer(`
|
rm := th.LoadAndRunTransformer(`
|
||||||
apiVersion: builtin
|
apiVersion: builtin
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ func TestConfigMapGenerator(t *testing.T) {
|
|||||||
tc.BuildGoPlugin(
|
tc.BuildGoPlugin(
|
||||||
"builtin", "", "ConfigMapGenerator")
|
"builtin", "", "ConfigMapGenerator")
|
||||||
|
|
||||||
th := kusttest_test.NewKustTestHarnessAllowPlugins(t, "/app")
|
th := kusttest_test.MakeHarnessEnhanced(t, "/app")
|
||||||
|
|
||||||
th.WriteF("/app/devops.env", `
|
th.WriteF("/app/devops.env", `
|
||||||
SERVICE_PORT=32
|
SERVICE_PORT=32
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ func TestHashTransformer(t *testing.T) {
|
|||||||
tc.BuildGoPlugin(
|
tc.BuildGoPlugin(
|
||||||
"builtin", "", "HashTransformer")
|
"builtin", "", "HashTransformer")
|
||||||
|
|
||||||
th := kusttest_test.NewKustTestHarnessAllowPlugins(t, "/app")
|
th := kusttest_test.MakeHarnessEnhanced(t, "/app")
|
||||||
|
|
||||||
rm := th.LoadAndRunTransformer(`
|
rm := th.LoadAndRunTransformer(`
|
||||||
apiVersion: builtin
|
apiVersion: builtin
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ func TestImageTagTransformerNewTag(t *testing.T) {
|
|||||||
tc.BuildGoPlugin(
|
tc.BuildGoPlugin(
|
||||||
"builtin", "", "ImageTagTransformer")
|
"builtin", "", "ImageTagTransformer")
|
||||||
|
|
||||||
th := kusttest_test.NewKustTestHarnessAllowPlugins(t, "/app")
|
th := kusttest_test.MakeHarnessEnhanced(t, "/app")
|
||||||
|
|
||||||
rm := th.LoadAndRunTransformer(`
|
rm := th.LoadAndRunTransformer(`
|
||||||
apiVersion: builtin
|
apiVersion: builtin
|
||||||
@@ -87,7 +87,7 @@ func TestImageTagTransformerNewImage(t *testing.T) {
|
|||||||
tc.BuildGoPlugin(
|
tc.BuildGoPlugin(
|
||||||
"builtin", "", "ImageTagTransformer")
|
"builtin", "", "ImageTagTransformer")
|
||||||
|
|
||||||
th := kusttest_test.NewKustTestHarnessAllowPlugins(t, "/app")
|
th := kusttest_test.MakeHarnessEnhanced(t, "/app")
|
||||||
|
|
||||||
rm := th.LoadAndRunTransformer(`
|
rm := th.LoadAndRunTransformer(`
|
||||||
apiVersion: builtin
|
apiVersion: builtin
|
||||||
@@ -159,7 +159,7 @@ func TestImageTagTransformerNewImageAndTag(t *testing.T) {
|
|||||||
tc.BuildGoPlugin(
|
tc.BuildGoPlugin(
|
||||||
"builtin", "", "ImageTagTransformer")
|
"builtin", "", "ImageTagTransformer")
|
||||||
|
|
||||||
th := kusttest_test.NewKustTestHarnessAllowPlugins(t, "/app")
|
th := kusttest_test.MakeHarnessEnhanced(t, "/app")
|
||||||
|
|
||||||
rm := th.LoadAndRunTransformer(`
|
rm := th.LoadAndRunTransformer(`
|
||||||
apiVersion: builtin
|
apiVersion: builtin
|
||||||
@@ -232,7 +232,7 @@ func TestImageTagTransformerNewDigest(t *testing.T) {
|
|||||||
tc.BuildGoPlugin(
|
tc.BuildGoPlugin(
|
||||||
"builtin", "", "ImageTagTransformer")
|
"builtin", "", "ImageTagTransformer")
|
||||||
|
|
||||||
th := kusttest_test.NewKustTestHarnessAllowPlugins(t, "/app")
|
th := kusttest_test.MakeHarnessEnhanced(t, "/app")
|
||||||
|
|
||||||
rm := th.LoadAndRunTransformer(`
|
rm := th.LoadAndRunTransformer(`
|
||||||
apiVersion: builtin
|
apiVersion: builtin
|
||||||
@@ -304,7 +304,7 @@ func TestImageTagTransformerNewImageAndDigest(t *testing.T) {
|
|||||||
tc.BuildGoPlugin(
|
tc.BuildGoPlugin(
|
||||||
"builtin", "", "ImageTagTransformer")
|
"builtin", "", "ImageTagTransformer")
|
||||||
|
|
||||||
th := kusttest_test.NewKustTestHarnessAllowPlugins(t, "/app")
|
th := kusttest_test.MakeHarnessEnhanced(t, "/app")
|
||||||
|
|
||||||
rm := th.LoadAndRunTransformer(`
|
rm := th.LoadAndRunTransformer(`
|
||||||
apiVersion: builtin
|
apiVersion: builtin
|
||||||
@@ -376,7 +376,7 @@ func TestImageTagTransformerEmptyContainers(t *testing.T) {
|
|||||||
tc.BuildGoPlugin(
|
tc.BuildGoPlugin(
|
||||||
"builtin", "", "ImageTagTransformer")
|
"builtin", "", "ImageTagTransformer")
|
||||||
|
|
||||||
th := kusttest_test.NewKustTestHarnessAllowPlugins(t, "/app")
|
th := kusttest_test.MakeHarnessEnhanced(t, "/app")
|
||||||
|
|
||||||
rm := th.LoadAndRunTransformer(`
|
rm := th.LoadAndRunTransformer(`
|
||||||
apiVersion: builtin
|
apiVersion: builtin
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ func TestInventoryTransformerCollect(t *testing.T) {
|
|||||||
tc.BuildGoPlugin(
|
tc.BuildGoPlugin(
|
||||||
"builtin", "", "InventoryTransformer")
|
"builtin", "", "InventoryTransformer")
|
||||||
|
|
||||||
th := kusttest_test.NewKustTestHarnessAllowPlugins(t, "/app")
|
th := kusttest_test.MakeHarnessEnhanced(t, "/app")
|
||||||
|
|
||||||
rm := th.LoadAndRunTransformer(`
|
rm := th.LoadAndRunTransformer(`
|
||||||
apiVersion: builtin
|
apiVersion: builtin
|
||||||
@@ -85,7 +85,7 @@ func TestInventoryTransformerIgnore(t *testing.T) {
|
|||||||
tc.BuildGoPlugin(
|
tc.BuildGoPlugin(
|
||||||
"builtin", "", "InventoryTransformer")
|
"builtin", "", "InventoryTransformer")
|
||||||
|
|
||||||
th := kusttest_test.NewKustTestHarnessAllowPlugins(t, "/app")
|
th := kusttest_test.MakeHarnessEnhanced(t, "/app")
|
||||||
|
|
||||||
rm := th.LoadAndRunTransformer(`
|
rm := th.LoadAndRunTransformer(`
|
||||||
apiVersion: builtin
|
apiVersion: builtin
|
||||||
@@ -106,7 +106,7 @@ func TestInventoryTransformerDefaultPolicy(t *testing.T) {
|
|||||||
tc.BuildGoPlugin(
|
tc.BuildGoPlugin(
|
||||||
"builtin", "", "InventoryTransformer")
|
"builtin", "", "InventoryTransformer")
|
||||||
|
|
||||||
th := kusttest_test.NewKustTestHarnessAllowPlugins(t, "/app")
|
th := kusttest_test.MakeHarnessEnhanced(t, "/app")
|
||||||
|
|
||||||
rm := th.LoadAndRunTransformer(`
|
rm := th.LoadAndRunTransformer(`
|
||||||
apiVersion: builtin
|
apiVersion: builtin
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ func TestLabelTransformer(t *testing.T) {
|
|||||||
tc.BuildGoPlugin(
|
tc.BuildGoPlugin(
|
||||||
"builtin", "", "LabelTransformer")
|
"builtin", "", "LabelTransformer")
|
||||||
|
|
||||||
th := kusttest_test.NewKustTestHarnessAllowPlugins(t, "/app")
|
th := kusttest_test.MakeHarnessEnhanced(t, "/app")
|
||||||
|
|
||||||
rm := th.LoadAndRunTransformer(`
|
rm := th.LoadAndRunTransformer(`
|
||||||
apiVersion: builtin
|
apiVersion: builtin
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ func TestLegacyOrderTransformer(t *testing.T) {
|
|||||||
tc.BuildGoPlugin(
|
tc.BuildGoPlugin(
|
||||||
"builtin", "", "LegacyOrderTransformer")
|
"builtin", "", "LegacyOrderTransformer")
|
||||||
|
|
||||||
th := kusttest_test.NewKustTestHarnessAllowPlugins(t, "/app")
|
th := kusttest_test.MakeHarnessEnhanced(t, "/app")
|
||||||
rm := th.LoadAndRunTransformer(`
|
rm := th.LoadAndRunTransformer(`
|
||||||
apiVersion: builtin
|
apiVersion: builtin
|
||||||
kind: LegacyOrderTransformer
|
kind: LegacyOrderTransformer
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ func TestNamespaceTransformer1(t *testing.T) {
|
|||||||
tc.BuildGoPlugin(
|
tc.BuildGoPlugin(
|
||||||
"builtin", "", "NamespaceTransformer")
|
"builtin", "", "NamespaceTransformer")
|
||||||
|
|
||||||
th := kusttest_test.NewKustTestHarnessAllowPlugins(t, "/app")
|
th := kusttest_test.MakeHarnessEnhanced(t, "/app")
|
||||||
|
|
||||||
rm := th.LoadAndRunTransformer(`
|
rm := th.LoadAndRunTransformer(`
|
||||||
apiVersion: builtin
|
apiVersion: builtin
|
||||||
@@ -195,7 +195,7 @@ func TestNamespaceTransformerClusterLevelKinds(t *testing.T) {
|
|||||||
tc.BuildGoPlugin(
|
tc.BuildGoPlugin(
|
||||||
"builtin", "", "NamespaceTransformer")
|
"builtin", "", "NamespaceTransformer")
|
||||||
|
|
||||||
th := kusttest_test.NewKustTestHarnessAllowPlugins(t, "/app")
|
th := kusttest_test.MakeHarnessEnhanced(t, "/app")
|
||||||
|
|
||||||
const noChangeExpected = `
|
const noChangeExpected = `
|
||||||
apiVersion: v1
|
apiVersion: v1
|
||||||
@@ -246,7 +246,7 @@ func TestNamespaceTransformerObjectConflict(t *testing.T) {
|
|||||||
tc.BuildGoPlugin(
|
tc.BuildGoPlugin(
|
||||||
"builtin", "", "NamespaceTransformer")
|
"builtin", "", "NamespaceTransformer")
|
||||||
|
|
||||||
th := kusttest_test.NewKustTestHarnessAllowPlugins(t, "/app")
|
th := kusttest_test.MakeHarnessEnhanced(t, "/app")
|
||||||
|
|
||||||
err := th.ErrorFromLoadAndRunTransformer(`
|
err := th.ErrorFromLoadAndRunTransformer(`
|
||||||
apiVersion: builtin
|
apiVersion: builtin
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ func TestPatchJson6902TransformerMissingFile(t *testing.T) {
|
|||||||
tc.BuildGoPlugin(
|
tc.BuildGoPlugin(
|
||||||
"builtin", "", "PatchJson6902Transformer")
|
"builtin", "", "PatchJson6902Transformer")
|
||||||
|
|
||||||
th := kusttest_test.NewKustTestHarnessAllowPlugins(t, "/app")
|
th := kusttest_test.MakeHarnessEnhanced(t, "/app")
|
||||||
|
|
||||||
_, err := th.RunTransformer(`
|
_, err := th.RunTransformer(`
|
||||||
apiVersion: builtin
|
apiVersion: builtin
|
||||||
@@ -63,7 +63,7 @@ func TestBadPatchJson6902Transformer(t *testing.T) {
|
|||||||
tc.BuildGoPlugin(
|
tc.BuildGoPlugin(
|
||||||
"builtin", "", "PatchJson6902Transformer")
|
"builtin", "", "PatchJson6902Transformer")
|
||||||
|
|
||||||
th := kusttest_test.NewKustTestHarnessAllowPlugins(t, "/app")
|
th := kusttest_test.MakeHarnessEnhanced(t, "/app")
|
||||||
|
|
||||||
_, err := th.RunTransformer(`
|
_, err := th.RunTransformer(`
|
||||||
apiVersion: builtin
|
apiVersion: builtin
|
||||||
@@ -92,7 +92,7 @@ func TestBothEmptyJson6902Transformer(t *testing.T) {
|
|||||||
tc.BuildGoPlugin(
|
tc.BuildGoPlugin(
|
||||||
"builtin", "", "PatchJson6902Transformer")
|
"builtin", "", "PatchJson6902Transformer")
|
||||||
|
|
||||||
th := kusttest_test.NewKustTestHarnessAllowPlugins(t, "/app")
|
th := kusttest_test.MakeHarnessEnhanced(t, "/app")
|
||||||
|
|
||||||
_, err := th.RunTransformer(`
|
_, err := th.RunTransformer(`
|
||||||
apiVersion: builtin
|
apiVersion: builtin
|
||||||
@@ -120,7 +120,7 @@ func TestBothSpecifiedJson6902Transformer(t *testing.T) {
|
|||||||
tc.BuildGoPlugin(
|
tc.BuildGoPlugin(
|
||||||
"builtin", "", "PatchJson6902Transformer")
|
"builtin", "", "PatchJson6902Transformer")
|
||||||
|
|
||||||
th := kusttest_test.NewKustTestHarnessAllowPlugins(t, "/app")
|
th := kusttest_test.MakeHarnessEnhanced(t, "/app")
|
||||||
|
|
||||||
th.WriteF("/app/jsonpatch.json", `[
|
th.WriteF("/app/jsonpatch.json", `[
|
||||||
{"op": "replace", "path": "/spec/template/spec/containers/0/name", "value": "my-nginx"},
|
{"op": "replace", "path": "/spec/template/spec/containers/0/name", "value": "my-nginx"},
|
||||||
@@ -156,7 +156,7 @@ func TestPatchJson6902TransformerFromJsonFile(t *testing.T) {
|
|||||||
tc.BuildGoPlugin(
|
tc.BuildGoPlugin(
|
||||||
"builtin", "", "PatchJson6902Transformer")
|
"builtin", "", "PatchJson6902Transformer")
|
||||||
|
|
||||||
th := kusttest_test.NewKustTestHarnessAllowPlugins(t, "/app")
|
th := kusttest_test.MakeHarnessEnhanced(t, "/app")
|
||||||
|
|
||||||
th.WriteF("/app/jsonpatch.json", `[
|
th.WriteF("/app/jsonpatch.json", `[
|
||||||
{"op": "replace", "path": "/spec/template/spec/containers/0/name", "value": "my-nginx"},
|
{"op": "replace", "path": "/spec/template/spec/containers/0/name", "value": "my-nginx"},
|
||||||
@@ -206,7 +206,7 @@ func TestPatchJson6902TransformerFromYamlFile(t *testing.T) {
|
|||||||
tc.BuildGoPlugin(
|
tc.BuildGoPlugin(
|
||||||
"builtin", "", "PatchJson6902Transformer")
|
"builtin", "", "PatchJson6902Transformer")
|
||||||
|
|
||||||
th := kusttest_test.NewKustTestHarnessAllowPlugins(t, "/app")
|
th := kusttest_test.MakeHarnessEnhanced(t, "/app")
|
||||||
|
|
||||||
th.WriteF("/app/jsonpatch.json", `
|
th.WriteF("/app/jsonpatch.json", `
|
||||||
- op: add
|
- op: add
|
||||||
@@ -256,7 +256,7 @@ func TestPatchJson6902TransformerWithInlineJSON(t *testing.T) {
|
|||||||
tc.BuildGoPlugin(
|
tc.BuildGoPlugin(
|
||||||
"builtin", "", "PatchJson6902Transformer")
|
"builtin", "", "PatchJson6902Transformer")
|
||||||
|
|
||||||
th := kusttest_test.NewKustTestHarnessAllowPlugins(t, "/app")
|
th := kusttest_test.MakeHarnessEnhanced(t, "/app")
|
||||||
|
|
||||||
rm := th.LoadAndRunTransformer(`
|
rm := th.LoadAndRunTransformer(`
|
||||||
apiVersion: builtin
|
apiVersion: builtin
|
||||||
@@ -297,7 +297,7 @@ func TestPatchJson6902TransformerWithInlineYAML(t *testing.T) {
|
|||||||
tc.BuildGoPlugin(
|
tc.BuildGoPlugin(
|
||||||
"builtin", "", "PatchJson6902Transformer")
|
"builtin", "", "PatchJson6902Transformer")
|
||||||
|
|
||||||
th := kusttest_test.NewKustTestHarnessAllowPlugins(t, "/app")
|
th := kusttest_test.MakeHarnessEnhanced(t, "/app")
|
||||||
|
|
||||||
rm := th.LoadAndRunTransformer(`
|
rm := th.LoadAndRunTransformer(`
|
||||||
apiVersion: builtin
|
apiVersion: builtin
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ func TestPatchStrategicMergeTransformerMissingFile(t *testing.T) {
|
|||||||
|
|
||||||
tc.BuildGoPlugin(
|
tc.BuildGoPlugin(
|
||||||
"builtin", "", "PatchStrategicMergeTransformer")
|
"builtin", "", "PatchStrategicMergeTransformer")
|
||||||
th := kusttest_test.NewKustTestHarnessAllowPlugins(t, "/app")
|
th := kusttest_test.MakeHarnessEnhanced(t, "/app")
|
||||||
|
|
||||||
_, err := th.RunTransformer(`
|
_, err := th.RunTransformer(`
|
||||||
apiVersion: builtin
|
apiVersion: builtin
|
||||||
@@ -91,7 +91,7 @@ func TestBadPatchStrategicMergeTransformer(t *testing.T) {
|
|||||||
tc.BuildGoPlugin(
|
tc.BuildGoPlugin(
|
||||||
"builtin", "", "PatchStrategicMergeTransformer")
|
"builtin", "", "PatchStrategicMergeTransformer")
|
||||||
|
|
||||||
th := kusttest_test.NewKustTestHarnessAllowPlugins(t, "/app")
|
th := kusttest_test.MakeHarnessEnhanced(t, "/app")
|
||||||
|
|
||||||
_, err := th.RunTransformer(`
|
_, err := th.RunTransformer(`
|
||||||
apiVersion: builtin
|
apiVersion: builtin
|
||||||
@@ -116,7 +116,7 @@ func TestBothEmptyPatchStrategicMergeTransformer(t *testing.T) {
|
|||||||
tc.BuildGoPlugin(
|
tc.BuildGoPlugin(
|
||||||
"builtin", "", "PatchStrategicMergeTransformer")
|
"builtin", "", "PatchStrategicMergeTransformer")
|
||||||
|
|
||||||
th := kusttest_test.NewKustTestHarnessAllowPlugins(t, "/app")
|
th := kusttest_test.MakeHarnessEnhanced(t, "/app")
|
||||||
|
|
||||||
_, err := th.RunTransformer(`
|
_, err := th.RunTransformer(`
|
||||||
apiVersion: builtin
|
apiVersion: builtin
|
||||||
@@ -139,7 +139,7 @@ func TestPatchStrategicMergeTransformerFromFiles(t *testing.T) {
|
|||||||
tc.BuildGoPlugin(
|
tc.BuildGoPlugin(
|
||||||
"builtin", "", "PatchStrategicMergeTransformer")
|
"builtin", "", "PatchStrategicMergeTransformer")
|
||||||
|
|
||||||
th := kusttest_test.NewKustTestHarnessAllowPlugins(t, "/app")
|
th := kusttest_test.MakeHarnessEnhanced(t, "/app")
|
||||||
|
|
||||||
th.WriteF("/app/patch.yaml", `
|
th.WriteF("/app/patch.yaml", `
|
||||||
apiVersion: apps/v1
|
apiVersion: apps/v1
|
||||||
@@ -189,7 +189,7 @@ func TestPatchStrategicMergeTransformerWithInlineJSON(t *testing.T) {
|
|||||||
tc.BuildGoPlugin(
|
tc.BuildGoPlugin(
|
||||||
"builtin", "", "PatchStrategicMergeTransformer")
|
"builtin", "", "PatchStrategicMergeTransformer")
|
||||||
|
|
||||||
th := kusttest_test.NewKustTestHarnessAllowPlugins(t, "/app")
|
th := kusttest_test.MakeHarnessEnhanced(t, "/app")
|
||||||
|
|
||||||
rm := th.LoadAndRunTransformer(`
|
rm := th.LoadAndRunTransformer(`
|
||||||
apiVersion: builtin
|
apiVersion: builtin
|
||||||
@@ -224,7 +224,7 @@ func TestPatchStrategicMergeTransformerWithInlineYAML(t *testing.T) {
|
|||||||
tc.BuildGoPlugin(
|
tc.BuildGoPlugin(
|
||||||
"builtin", "", "PatchStrategicMergeTransformer")
|
"builtin", "", "PatchStrategicMergeTransformer")
|
||||||
|
|
||||||
th := kusttest_test.NewKustTestHarnessAllowPlugins(t, "/app")
|
th := kusttest_test.MakeHarnessEnhanced(t, "/app")
|
||||||
|
|
||||||
rm := th.LoadAndRunTransformer(`
|
rm := th.LoadAndRunTransformer(`
|
||||||
apiVersion: builtin
|
apiVersion: builtin
|
||||||
@@ -276,7 +276,7 @@ func TestPatchStrategicMergeTransformerMultiplePatches(t *testing.T) {
|
|||||||
tc.BuildGoPlugin(
|
tc.BuildGoPlugin(
|
||||||
"builtin", "", "PatchStrategicMergeTransformer")
|
"builtin", "", "PatchStrategicMergeTransformer")
|
||||||
|
|
||||||
th := kusttest_test.NewKustTestHarnessAllowPlugins(t, "/app")
|
th := kusttest_test.MakeHarnessEnhanced(t, "/app")
|
||||||
|
|
||||||
th.WriteF("/app/patch1.yaml", `
|
th.WriteF("/app/patch1.yaml", `
|
||||||
apiVersion: apps/v1
|
apiVersion: apps/v1
|
||||||
@@ -353,7 +353,7 @@ func TestStrategicMergeTransformerMultiplePatchesWithConflicts(t *testing.T) {
|
|||||||
tc.BuildGoPlugin(
|
tc.BuildGoPlugin(
|
||||||
"builtin", "", "PatchStrategicMergeTransformer")
|
"builtin", "", "PatchStrategicMergeTransformer")
|
||||||
|
|
||||||
th := kusttest_test.NewKustTestHarnessAllowPlugins(t, "/app")
|
th := kusttest_test.MakeHarnessEnhanced(t, "/app")
|
||||||
|
|
||||||
th.WriteF("/app/patch1.yaml", `
|
th.WriteF("/app/patch1.yaml", `
|
||||||
apiVersion: apps/v1
|
apiVersion: apps/v1
|
||||||
@@ -414,7 +414,7 @@ func TestStrategicMergeTransformerWrongNamespace(t *testing.T) {
|
|||||||
tc.BuildGoPlugin(
|
tc.BuildGoPlugin(
|
||||||
"builtin", "", "PatchStrategicMergeTransformer")
|
"builtin", "", "PatchStrategicMergeTransformer")
|
||||||
|
|
||||||
th := kusttest_test.NewKustTestHarnessAllowPlugins(t, "/app")
|
th := kusttest_test.MakeHarnessEnhanced(t, "/app")
|
||||||
|
|
||||||
th.WriteF("/app/patch.yaml", `
|
th.WriteF("/app/patch.yaml", `
|
||||||
apiVersion: apps/v1
|
apiVersion: apps/v1
|
||||||
@@ -457,7 +457,7 @@ func TestStrategicMergeTransformerNoSchema(t *testing.T) {
|
|||||||
tc.BuildGoPlugin(
|
tc.BuildGoPlugin(
|
||||||
"builtin", "", "PatchStrategicMergeTransformer")
|
"builtin", "", "PatchStrategicMergeTransformer")
|
||||||
|
|
||||||
th := kusttest_test.NewKustTestHarnessAllowPlugins(t, "/app")
|
th := kusttest_test.MakeHarnessEnhanced(t, "/app")
|
||||||
|
|
||||||
th.WriteF("/app/patch.yaml", `
|
th.WriteF("/app/patch.yaml", `
|
||||||
apiVersion: example.com/v1
|
apiVersion: example.com/v1
|
||||||
@@ -497,7 +497,7 @@ func TestStrategicMergeTransformerNoSchemaMultiPatches(t *testing.T) {
|
|||||||
tc.BuildGoPlugin(
|
tc.BuildGoPlugin(
|
||||||
"builtin", "", "PatchStrategicMergeTransformer")
|
"builtin", "", "PatchStrategicMergeTransformer")
|
||||||
|
|
||||||
th := kusttest_test.NewKustTestHarnessAllowPlugins(t, "/app")
|
th := kusttest_test.MakeHarnessEnhanced(t, "/app")
|
||||||
|
|
||||||
th.WriteF("/app/patch1.yaml", `
|
th.WriteF("/app/patch1.yaml", `
|
||||||
apiVersion: example.com/v1
|
apiVersion: example.com/v1
|
||||||
@@ -553,7 +553,7 @@ func TestStrategicMergeTransformerNoSchemaMultiPatchesWithConflict(t *testing.T)
|
|||||||
tc.BuildGoPlugin(
|
tc.BuildGoPlugin(
|
||||||
"builtin", "", "PatchStrategicMergeTransformer")
|
"builtin", "", "PatchStrategicMergeTransformer")
|
||||||
|
|
||||||
th := kusttest_test.NewKustTestHarnessAllowPlugins(t, "/app")
|
th := kusttest_test.MakeHarnessEnhanced(t, "/app")
|
||||||
|
|
||||||
th.WriteF("/app/patch1.yaml", `
|
th.WriteF("/app/patch1.yaml", `
|
||||||
apiVersion: example.com/v1
|
apiVersion: example.com/v1
|
||||||
@@ -889,7 +889,7 @@ func TestSinglePatch(t *testing.T) {
|
|||||||
"builtin", "", "PatchStrategicMergeTransformer")
|
"builtin", "", "PatchStrategicMergeTransformer")
|
||||||
|
|
||||||
for _, test := range tests {
|
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)
|
th.WriteF(fmt.Sprintf("/%s/patch%d.yaml", test.name, 0), test.patch)
|
||||||
|
|
||||||
if test.errorExpected {
|
if test.errorExpected {
|
||||||
@@ -992,7 +992,7 @@ func TestMultiplePatches(t *testing.T) {
|
|||||||
"builtin", "", "PatchStrategicMergeTransformer")
|
"builtin", "", "PatchStrategicMergeTransformer")
|
||||||
|
|
||||||
for _, test := range tests {
|
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 {
|
for idx, patch := range test.patch {
|
||||||
th.WriteF(fmt.Sprintf("/%s/patch%d.yaml", test.name, idx), patch)
|
th.WriteF(fmt.Sprintf("/%s/patch%d.yaml", test.name, idx), patch)
|
||||||
}
|
}
|
||||||
@@ -1123,7 +1123,7 @@ func TestMultiplePatchesWithConflict(t *testing.T) {
|
|||||||
"builtin", "", "PatchStrategicMergeTransformer")
|
"builtin", "", "PatchStrategicMergeTransformer")
|
||||||
|
|
||||||
for _, test := range tests {
|
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 {
|
for idx, patch := range test.patch {
|
||||||
th.WriteF(fmt.Sprintf("/%s/patch%d.yaml", test.name, idx), patch)
|
th.WriteF(fmt.Sprintf("/%s/patch%d.yaml", test.name, idx), patch)
|
||||||
}
|
}
|
||||||
@@ -1232,7 +1232,7 @@ func TestMultipleNamespaces(t *testing.T) {
|
|||||||
"builtin", "", "PatchStrategicMergeTransformer")
|
"builtin", "", "PatchStrategicMergeTransformer")
|
||||||
|
|
||||||
for _, test := range tests {
|
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 {
|
for idx, patch := range test.patch {
|
||||||
th.WriteF(fmt.Sprintf("/%s/patch%d.yaml", test.name, idx), patch)
|
th.WriteF(fmt.Sprintf("/%s/patch%d.yaml", test.name, idx), patch)
|
||||||
}
|
}
|
||||||
@@ -1254,7 +1254,7 @@ func TestPatchStrategicMergeTransformerPatchDelete(t *testing.T) {
|
|||||||
tc.BuildGoPlugin(
|
tc.BuildGoPlugin(
|
||||||
"builtin", "", "PatchStrategicMergeTransformer")
|
"builtin", "", "PatchStrategicMergeTransformer")
|
||||||
|
|
||||||
th := kusttest_test.NewKustTestHarnessAllowPlugins(t, "/app")
|
th := kusttest_test.MakeHarnessEnhanced(t, "/app")
|
||||||
|
|
||||||
th.WriteF("/app/patch.yaml", `
|
th.WriteF("/app/patch.yaml", `
|
||||||
apiVersion: apps/v1
|
apiVersion: apps/v1
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ func TestPatchTransformerMissingFile(t *testing.T) {
|
|||||||
|
|
||||||
tc.BuildGoPlugin(
|
tc.BuildGoPlugin(
|
||||||
"builtin", "", "PatchTransformer")
|
"builtin", "", "PatchTransformer")
|
||||||
th := kusttest_test.NewKustTestHarnessAllowPlugins(t, "/app")
|
th := kusttest_test.MakeHarnessEnhanced(t, "/app")
|
||||||
|
|
||||||
_, err := th.RunTransformer(`
|
_, err := th.RunTransformer(`
|
||||||
apiVersion: builtin
|
apiVersion: builtin
|
||||||
@@ -94,7 +94,7 @@ func TestPatchTransformerBadPatch(t *testing.T) {
|
|||||||
|
|
||||||
tc.BuildGoPlugin(
|
tc.BuildGoPlugin(
|
||||||
"builtin", "", "PatchTransformer")
|
"builtin", "", "PatchTransformer")
|
||||||
th := kusttest_test.NewKustTestHarnessAllowPlugins(t, "/app")
|
th := kusttest_test.MakeHarnessEnhanced(t, "/app")
|
||||||
|
|
||||||
_, err := th.RunTransformer(`
|
_, err := th.RunTransformer(`
|
||||||
apiVersion: builtin
|
apiVersion: builtin
|
||||||
@@ -118,7 +118,7 @@ func TestPatchTransformerMissingSelector(t *testing.T) {
|
|||||||
|
|
||||||
tc.BuildGoPlugin(
|
tc.BuildGoPlugin(
|
||||||
"builtin", "", "PatchTransformer")
|
"builtin", "", "PatchTransformer")
|
||||||
th := kusttest_test.NewKustTestHarnessAllowPlugins(t, "/app")
|
th := kusttest_test.MakeHarnessEnhanced(t, "/app")
|
||||||
|
|
||||||
_, err := th.RunTransformer(`
|
_, err := th.RunTransformer(`
|
||||||
apiVersion: builtin
|
apiVersion: builtin
|
||||||
@@ -143,7 +143,7 @@ func TestPatchTransformerBothEmptyPathAndPatch(t *testing.T) {
|
|||||||
tc.BuildGoPlugin(
|
tc.BuildGoPlugin(
|
||||||
"builtin", "", "PatchTransformer")
|
"builtin", "", "PatchTransformer")
|
||||||
|
|
||||||
th := kusttest_test.NewKustTestHarnessAllowPlugins(t, "/app")
|
th := kusttest_test.MakeHarnessEnhanced(t, "/app")
|
||||||
|
|
||||||
_, err := th.RunTransformer(`
|
_, err := th.RunTransformer(`
|
||||||
apiVersion: builtin
|
apiVersion: builtin
|
||||||
@@ -166,7 +166,7 @@ func TestPatchTransformerBothNonEmptyPathAndPatch(t *testing.T) {
|
|||||||
tc.BuildGoPlugin(
|
tc.BuildGoPlugin(
|
||||||
"builtin", "", "PatchTransformer")
|
"builtin", "", "PatchTransformer")
|
||||||
|
|
||||||
th := kusttest_test.NewKustTestHarnessAllowPlugins(t, "/app")
|
th := kusttest_test.MakeHarnessEnhanced(t, "/app")
|
||||||
|
|
||||||
_, err := th.RunTransformer(`
|
_, err := th.RunTransformer(`
|
||||||
apiVersion: builtin
|
apiVersion: builtin
|
||||||
@@ -191,7 +191,7 @@ func TestPatchTransformerFromFiles(t *testing.T) {
|
|||||||
tc.BuildGoPlugin(
|
tc.BuildGoPlugin(
|
||||||
"builtin", "", "PatchTransformer")
|
"builtin", "", "PatchTransformer")
|
||||||
|
|
||||||
th := kusttest_test.NewKustTestHarnessAllowPlugins(t, "/app")
|
th := kusttest_test.MakeHarnessEnhanced(t, "/app")
|
||||||
|
|
||||||
th.WriteF("/app/patch.yaml", `
|
th.WriteF("/app/patch.yaml", `
|
||||||
apiVersion: apps/v1
|
apiVersion: apps/v1
|
||||||
@@ -273,7 +273,7 @@ func TestPatchTransformerWithInline(t *testing.T) {
|
|||||||
tc.BuildGoPlugin(
|
tc.BuildGoPlugin(
|
||||||
"builtin", "", "PatchTransformer")
|
"builtin", "", "PatchTransformer")
|
||||||
|
|
||||||
th := kusttest_test.NewKustTestHarnessAllowPlugins(t, "/app")
|
th := kusttest_test.MakeHarnessEnhanced(t, "/app")
|
||||||
|
|
||||||
rm := th.LoadAndRunTransformer(`
|
rm := th.LoadAndRunTransformer(`
|
||||||
apiVersion: builtin
|
apiVersion: builtin
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ func TestPrefixSuffixTransformer(t *testing.T) {
|
|||||||
tc.BuildGoPlugin(
|
tc.BuildGoPlugin(
|
||||||
"builtin", "", "PrefixSuffixTransformer")
|
"builtin", "", "PrefixSuffixTransformer")
|
||||||
|
|
||||||
th := kusttest_test.NewKustTestHarnessAllowPlugins(t, "/app")
|
th := kusttest_test.MakeHarnessEnhanced(t, "/app")
|
||||||
rm := th.LoadAndRunTransformer(`
|
rm := th.LoadAndRunTransformer(`
|
||||||
apiVersion: builtin
|
apiVersion: builtin
|
||||||
kind: PrefixSuffixTransformer
|
kind: PrefixSuffixTransformer
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ func TestReplicaCountTransformer(t *testing.T) {
|
|||||||
tc.BuildGoPlugin(
|
tc.BuildGoPlugin(
|
||||||
"builtin", "", "ReplicaCountTransformer")
|
"builtin", "", "ReplicaCountTransformer")
|
||||||
|
|
||||||
th := kusttest_test.NewKustTestHarnessAllowPlugins(t, "/app")
|
th := kusttest_test.MakeHarnessEnhanced(t, "/app")
|
||||||
|
|
||||||
rm := th.LoadAndRunTransformer(`
|
rm := th.LoadAndRunTransformer(`
|
||||||
apiVersion: builtin
|
apiVersion: builtin
|
||||||
@@ -158,7 +158,7 @@ func TestMatchesCurrentID(t *testing.T) {
|
|||||||
tc.BuildGoPlugin("builtin", "", "PrefixSuffixTransformer")
|
tc.BuildGoPlugin("builtin", "", "PrefixSuffixTransformer")
|
||||||
tc.BuildGoPlugin("builtin", "", "ReplicaCountTransformer")
|
tc.BuildGoPlugin("builtin", "", "ReplicaCountTransformer")
|
||||||
|
|
||||||
th := kusttest_test.NewKustTestHarnessAllowPlugins(t, "/app")
|
th := kusttest_test.MakeHarnessEnhanced(t, "/app")
|
||||||
|
|
||||||
rm := th.LoadAndRunTransformer(`
|
rm := th.LoadAndRunTransformer(`
|
||||||
apiVersion: builtin
|
apiVersion: builtin
|
||||||
@@ -203,7 +203,7 @@ func TestNoMatch(t *testing.T) {
|
|||||||
|
|
||||||
tc.BuildGoPlugin("builtin", "", "ReplicaCountTransformer")
|
tc.BuildGoPlugin("builtin", "", "ReplicaCountTransformer")
|
||||||
|
|
||||||
th := kusttest_test.NewKustTestHarnessAllowPlugins(t, "/app")
|
th := kusttest_test.MakeHarnessEnhanced(t, "/app")
|
||||||
|
|
||||||
err := th.ErrorFromLoadAndRunTransformer(`
|
err := th.ErrorFromLoadAndRunTransformer(`
|
||||||
apiVersion: builtin
|
apiVersion: builtin
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ func TestSecretGenerator(t *testing.T) {
|
|||||||
tc.BuildGoPlugin(
|
tc.BuildGoPlugin(
|
||||||
"builtin", "", "SecretGenerator")
|
"builtin", "", "SecretGenerator")
|
||||||
|
|
||||||
th := kusttest_test.NewKustTestHarnessAllowPlugins(t, "/app")
|
th := kusttest_test.MakeHarnessEnhanced(t, "/app")
|
||||||
|
|
||||||
th.WriteF("/app/a.env", `
|
th.WriteF("/app/a.env", `
|
||||||
ROUTER_PASSWORD=admin
|
ROUTER_PASSWORD=admin
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ func TestBashedConfigMapPlugin(t *testing.T) {
|
|||||||
tc.PrepExecPlugin(
|
tc.PrepExecPlugin(
|
||||||
"someteam.example.com", "v1", "BashedConfigMap")
|
"someteam.example.com", "v1", "BashedConfigMap")
|
||||||
|
|
||||||
th := kusttest_test.NewKustTestHarnessAllowPlugins(t, "/app")
|
th := kusttest_test.MakeHarnessEnhanced(t, "/app")
|
||||||
|
|
||||||
m := th.LoadAndRunGenerator(`
|
m := th.LoadAndRunGenerator(`
|
||||||
apiVersion: someteam.example.com/v1
|
apiVersion: someteam.example.com/v1
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ func TestChartInflator(t *testing.T) {
|
|||||||
tc.PrepExecPlugin(
|
tc.PrepExecPlugin(
|
||||||
"someteam.example.com", "v1", "ChartInflator")
|
"someteam.example.com", "v1", "ChartInflator")
|
||||||
|
|
||||||
th := kusttest_test.NewKustTestHarnessAllowPlugins(t, "/app")
|
th := kusttest_test.MakeHarnessEnhanced(t, "/app")
|
||||||
|
|
||||||
m := th.LoadAndRunGenerator(`
|
m := th.LoadAndRunGenerator(`
|
||||||
apiVersion: someteam.example.com/v1
|
apiVersion: someteam.example.com/v1
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ func TestDatePrefixerPlugin(t *testing.T) {
|
|||||||
|
|
||||||
tc.BuildGoPlugin(
|
tc.BuildGoPlugin(
|
||||||
"someteam.example.com", "v1", "DatePrefixer")
|
"someteam.example.com", "v1", "DatePrefixer")
|
||||||
th := kusttest_test.NewKustTestHarnessAllowPlugins(t, "/app")
|
th := kusttest_test.MakeHarnessEnhanced(t, "/app")
|
||||||
|
|
||||||
m := th.LoadAndRunTransformer(`
|
m := th.LoadAndRunTransformer(`
|
||||||
apiVersion: someteam.example.com/v1
|
apiVersion: someteam.example.com/v1
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ func TestGoGetter(t *testing.T) {
|
|||||||
tc.PrepExecPlugin(
|
tc.PrepExecPlugin(
|
||||||
"someteam.example.com", "v1", "GoGetter")
|
"someteam.example.com", "v1", "GoGetter")
|
||||||
|
|
||||||
th := kusttest_test.NewKustTestHarnessAllowPlugins(t, "/app")
|
th := kusttest_test.MakeHarnessEnhanced(t, "/app")
|
||||||
|
|
||||||
m := th.LoadAndRunGenerator(`
|
m := th.LoadAndRunGenerator(`
|
||||||
apiVersion: someteam.example.com/v1
|
apiVersion: someteam.example.com/v1
|
||||||
@@ -50,7 +50,7 @@ func TestGoGetterUrl(t *testing.T) {
|
|||||||
tc.PrepExecPlugin(
|
tc.PrepExecPlugin(
|
||||||
"someteam.example.com", "v1", "GoGetter")
|
"someteam.example.com", "v1", "GoGetter")
|
||||||
|
|
||||||
th := kusttest_test.NewKustTestHarnessAllowPlugins(t, "/app")
|
th := kusttest_test.MakeHarnessEnhanced(t, "/app")
|
||||||
|
|
||||||
m := th.LoadAndRunGenerator(`
|
m := th.LoadAndRunGenerator(`
|
||||||
apiVersion: someteam.example.com/v1
|
apiVersion: someteam.example.com/v1
|
||||||
@@ -79,7 +79,7 @@ func TestGoGetterCommand(t *testing.T) {
|
|||||||
tc.PrepExecPlugin(
|
tc.PrepExecPlugin(
|
||||||
"someteam.example.com", "v1", "GoGetter")
|
"someteam.example.com", "v1", "GoGetter")
|
||||||
|
|
||||||
th := kusttest_test.NewKustTestHarnessAllowPlugins(t, "/app")
|
th := kusttest_test.MakeHarnessEnhanced(t, "/app")
|
||||||
|
|
||||||
m := th.LoadAndRunGenerator(`
|
m := th.LoadAndRunGenerator(`
|
||||||
apiVersion: someteam.example.com/v1
|
apiVersion: someteam.example.com/v1
|
||||||
@@ -108,7 +108,7 @@ func TestGoGetterSubPath(t *testing.T) {
|
|||||||
tc.PrepExecPlugin(
|
tc.PrepExecPlugin(
|
||||||
"someteam.example.com", "v1", "GoGetter")
|
"someteam.example.com", "v1", "GoGetter")
|
||||||
|
|
||||||
th := kusttest_test.NewKustTestHarnessAllowPlugins(t, "/app")
|
th := kusttest_test.MakeHarnessEnhanced(t, "/app")
|
||||||
|
|
||||||
m := th.LoadAndRunGenerator(`
|
m := th.LoadAndRunGenerator(`
|
||||||
apiVersion: someteam.example.com/v1
|
apiVersion: someteam.example.com/v1
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ func TestPrintPluginEnvPlugin(t *testing.T) {
|
|||||||
tc.PrepExecPlugin(
|
tc.PrepExecPlugin(
|
||||||
"someteam.example.com", "v1", "PrintPluginEnv")
|
"someteam.example.com", "v1", "PrintPluginEnv")
|
||||||
|
|
||||||
th := kusttest_test.NewKustTestHarnessAllowPlugins(t, "/theAppRoot")
|
th := kusttest_test.MakeHarnessEnhanced(t, "/theAppRoot")
|
||||||
|
|
||||||
m := th.LoadAndRunGenerator(`
|
m := th.LoadAndRunGenerator(`
|
||||||
apiVersion: someteam.example.com/v1
|
apiVersion: someteam.example.com/v1
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ func TestSecretsFromDatabasePlugin(t *testing.T) {
|
|||||||
tc.BuildGoPlugin(
|
tc.BuildGoPlugin(
|
||||||
"someteam.example.com", "v1", "SecretsFromDatabase")
|
"someteam.example.com", "v1", "SecretsFromDatabase")
|
||||||
|
|
||||||
th := kusttest_test.NewKustTestHarnessAllowPlugins(t, "/app")
|
th := kusttest_test.MakeHarnessEnhanced(t, "/app")
|
||||||
|
|
||||||
m := th.LoadAndRunGenerator(`
|
m := th.LoadAndRunGenerator(`
|
||||||
apiVersion: someteam.example.com/v1
|
apiVersion: someteam.example.com/v1
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ func TestSedTransformer(t *testing.T) {
|
|||||||
defer tc.Reset()
|
defer tc.Reset()
|
||||||
|
|
||||||
tc.PrepExecPlugin("someteam.example.com", "v1", "SedTransformer")
|
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", `
|
th.WriteF("/app/sed-input.txt", `
|
||||||
s/$FRUIT/orange/g
|
s/$FRUIT/orange/g
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ func TestSomeServiceGeneratorPlugin(t *testing.T) {
|
|||||||
tc.BuildGoPlugin(
|
tc.BuildGoPlugin(
|
||||||
"someteam.example.com", "v1", "SomeServiceGenerator")
|
"someteam.example.com", "v1", "SomeServiceGenerator")
|
||||||
|
|
||||||
th := kusttest_test.NewKustTestHarnessAllowPlugins(t, "/app")
|
th := kusttest_test.MakeHarnessEnhanced(t, "/app")
|
||||||
|
|
||||||
m := th.LoadAndRunGenerator(`
|
m := th.LoadAndRunGenerator(`
|
||||||
apiVersion: someteam.example.com/v1
|
apiVersion: someteam.example.com/v1
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ func TestStringPrefixerPlugin(t *testing.T) {
|
|||||||
|
|
||||||
tc.BuildGoPlugin(
|
tc.BuildGoPlugin(
|
||||||
"someteam.example.com", "v1", "StringPrefixer")
|
"someteam.example.com", "v1", "StringPrefixer")
|
||||||
th := kusttest_test.NewKustTestHarnessAllowPlugins(t, "/app")
|
th := kusttest_test.MakeHarnessEnhanced(t, "/app")
|
||||||
|
|
||||||
m := th.LoadAndRunTransformer(`
|
m := th.LoadAndRunTransformer(`
|
||||||
apiVersion: someteam.example.com/v1
|
apiVersion: someteam.example.com/v1
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ func TestValidatorHappy(t *testing.T) {
|
|||||||
defer tc.Reset()
|
defer tc.Reset()
|
||||||
|
|
||||||
tc.PrepExecPlugin("someteam.example.com", "v1", "Validator")
|
tc.PrepExecPlugin("someteam.example.com", "v1", "Validator")
|
||||||
th := kusttest_test.NewKustTestHarnessAllowPlugins(t, "/app")
|
th := kusttest_test.MakeHarnessEnhanced(t, "/app")
|
||||||
|
|
||||||
rm := th.LoadAndRunTransformer(`
|
rm := th.LoadAndRunTransformer(`
|
||||||
apiVersion: someteam.example.com/v1
|
apiVersion: someteam.example.com/v1
|
||||||
@@ -52,7 +52,7 @@ func TestValidatorUnHappy(t *testing.T) {
|
|||||||
defer tc.Reset()
|
defer tc.Reset()
|
||||||
|
|
||||||
tc.PrepExecPlugin("someteam.example.com", "v1", "Validator")
|
tc.PrepExecPlugin("someteam.example.com", "v1", "Validator")
|
||||||
th := kusttest_test.NewKustTestHarnessAllowPlugins(t, "/app")
|
th := kusttest_test.MakeHarnessEnhanced(t, "/app")
|
||||||
|
|
||||||
err := th.ErrorFromLoadAndRunTransformer(`
|
err := th.ErrorFromLoadAndRunTransformer(`
|
||||||
apiVersion: someteam.example.com/v1
|
apiVersion: someteam.example.com/v1
|
||||||
|
|||||||
Reference in New Issue
Block a user