mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-29 17:41:13 +00:00
Make kusttestharness shareable.
This commit is contained in:
@@ -18,10 +18,12 @@ package target_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"sigs.k8s.io/kustomize/pkg/kusttest"
|
||||
)
|
||||
|
||||
func writeBaseWithCrd(th *KustTestHarness) {
|
||||
th.writeK("/app/base", `
|
||||
func writeBaseWithCrd(th *kusttest_test.KustTestHarness) {
|
||||
th.WriteK("/app/base", `
|
||||
apiVersion: kustomize.config.k8s.io/v1beta1
|
||||
kind: Kustomization
|
||||
crds:
|
||||
@@ -34,7 +36,7 @@ resources:
|
||||
|
||||
namePrefix: x-
|
||||
`)
|
||||
th.writeF("/app/base/bee.yaml", `
|
||||
th.WriteF("/app/base/bee.yaml", `
|
||||
apiVersion: v1beta1
|
||||
kind: Bee
|
||||
metadata:
|
||||
@@ -42,7 +44,7 @@ metadata:
|
||||
spec:
|
||||
action: fly
|
||||
`)
|
||||
th.writeF("/app/base/mykind.yaml", `
|
||||
th.WriteF("/app/base/mykind.yaml", `
|
||||
apiVersion: jingfang.example.com/v1beta1
|
||||
kind: MyKind
|
||||
metadata:
|
||||
@@ -53,7 +55,7 @@ spec:
|
||||
beeRef:
|
||||
name: bee
|
||||
`)
|
||||
th.writeF("/app/base/secret.yaml", `
|
||||
th.WriteF("/app/base/secret.yaml", `
|
||||
apiVersion: v1
|
||||
kind: Secret
|
||||
metadata:
|
||||
@@ -61,7 +63,7 @@ metadata:
|
||||
data:
|
||||
PATH: yellowBrickRoad
|
||||
`)
|
||||
th.writeF("/app/base/mycrd.json", `
|
||||
th.WriteF("/app/base/mycrd.json", `
|
||||
{
|
||||
"github.com/example/pkg/apis/jingfang/v1beta1.Bee": {
|
||||
"Schema": {
|
||||
@@ -236,13 +238,13 @@ data:
|
||||
}
|
||||
|
||||
func TestCrdBase(t *testing.T) {
|
||||
th := NewKustTestHarness(t, "/app/base")
|
||||
th := kusttest_test.NewKustTestHarness(t, "/app/base")
|
||||
writeBaseWithCrd(th)
|
||||
m, err := th.makeKustTarget().MakeCustomizedResMap()
|
||||
m, err := th.MakeKustTarget().MakeCustomizedResMap()
|
||||
if err != nil {
|
||||
t.Fatalf("Err: %v", err)
|
||||
}
|
||||
th.assertActualEqualsExpected(m, `
|
||||
th.AssertActualEqualsExpected(m, `
|
||||
apiVersion: v1
|
||||
data:
|
||||
PATH: yellowBrickRoad
|
||||
@@ -270,9 +272,9 @@ spec:
|
||||
}
|
||||
|
||||
func TestCrdWithOverlay(t *testing.T) {
|
||||
th := NewKustTestHarness(t, "/app/overlay")
|
||||
th := kusttest_test.NewKustTestHarness(t, "/app/overlay")
|
||||
writeBaseWithCrd(th)
|
||||
th.writeK("/app/overlay", `
|
||||
th.WriteK("/app/overlay", `
|
||||
apiVersion: kustomize.config.k8s.io/v1beta1
|
||||
kind: Kustomization
|
||||
namePrefix: prod-
|
||||
@@ -281,7 +283,7 @@ bases:
|
||||
patchesStrategicMerge:
|
||||
- bee.yaml
|
||||
`)
|
||||
th.writeF("/app/overlay/bee.yaml", `
|
||||
th.WriteF("/app/overlay/bee.yaml", `
|
||||
apiVersion: v1beta1
|
||||
kind: Bee
|
||||
metadata:
|
||||
@@ -289,12 +291,12 @@ metadata:
|
||||
spec:
|
||||
action: makehoney
|
||||
`)
|
||||
m, err := th.makeKustTarget().MakeCustomizedResMap()
|
||||
m, err := th.MakeKustTarget().MakeCustomizedResMap()
|
||||
if err != nil {
|
||||
t.Fatalf("Err: %v", err)
|
||||
}
|
||||
// TODO(#669): Bee's name should be "prod-x-bee", not "prod-bee".
|
||||
th.assertActualEqualsExpected(m, `
|
||||
th.AssertActualEqualsExpected(m, `
|
||||
apiVersion: v1
|
||||
data:
|
||||
PATH: yellowBrickRoad
|
||||
@@ -322,8 +324,8 @@ spec:
|
||||
}
|
||||
|
||||
func TestCrdWithContainers(t *testing.T) {
|
||||
th := NewKustTestHarness(t, "/app/crd/containers")
|
||||
th.writeK("/app/crd/containers", `
|
||||
th := kusttest_test.NewKustTestHarness(t, "/app/crd/containers")
|
||||
th.WriteK("/app/crd/containers", `
|
||||
apiVersion: kustomize.config.k8s.io/v1beta1
|
||||
kind: Kustomization
|
||||
resources:
|
||||
@@ -334,7 +336,7 @@ images:
|
||||
newName: registry.gitlab.com/test
|
||||
newTag: latest
|
||||
`)
|
||||
th.writeF("/app/crd/containers/crd.yaml", `
|
||||
th.WriteF("/app/crd/containers/crd.yaml", `
|
||||
apiVersion: apiextensions.k8s.io/v1beta1
|
||||
kind: CustomResourceDefinition
|
||||
metadata:
|
||||
@@ -355,11 +357,11 @@ spec:
|
||||
containers:
|
||||
description: Containers allows injecting additional containers
|
||||
`)
|
||||
m, err := th.makeKustTarget().MakeCustomizedResMap()
|
||||
m, err := th.MakeKustTarget().MakeCustomizedResMap()
|
||||
if err != nil {
|
||||
t.Fatalf("Err: %v", err)
|
||||
}
|
||||
th.assertActualEqualsExpected(m, `
|
||||
th.AssertActualEqualsExpected(m, `
|
||||
apiVersion: apiextensions.k8s.io/v1beta1
|
||||
kind: CustomResourceDefinition
|
||||
metadata:
|
||||
|
||||
Reference in New Issue
Block a user