Make kusttestharness shareable.

This commit is contained in:
Jeffrey Regan
2019-05-07 14:18:35 -07:00
parent 8c5d4128e0
commit bcc7412ef2
23 changed files with 389 additions and 343 deletions

View File

@@ -18,11 +18,13 @@ package target_test
import (
"testing"
"sigs.k8s.io/kustomize/pkg/kusttest"
)
func TestSimpleBase(t *testing.T) {
th := NewKustTestHarness(t, "/app/base")
th.writeK("/app/base", `
th := kusttest_test.NewKustTestHarness(t, "/app/base")
th.WriteK("/app/base", `
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
namePrefix: team-foo-
@@ -37,7 +39,7 @@ resources:
- networkpolicy.yaml
- service.yaml
`)
th.writeF("/app/base/service.yaml", `
th.WriteF("/app/base/service.yaml", `
apiVersion: v1
kind: Service
metadata:
@@ -50,7 +52,7 @@ spec:
selector:
app: nginx
`)
th.writeF("/app/base/networkpolicy.yaml", `
th.WriteF("/app/base/networkpolicy.yaml", `
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
@@ -65,7 +67,7 @@ spec:
matchLabels:
app: nginx
`)
th.writeF("/app/base/deployment.yaml", `
th.WriteF("/app/base/deployment.yaml", `
apiVersion: apps/v1beta2
kind: Deployment
metadata:
@@ -82,11 +84,11 @@ spec:
- name: nginx
image: nginx
`)
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
kind: Service
metadata:
@@ -161,8 +163,8 @@ spec:
`)
}
func makeBaseWithGenerators(th *KustTestHarness) {
th.writeK("/app", `
func makeBaseWithGenerators(th *kusttest_test.KustTestHarness) {
th.WriteK("/app", `
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
namePrefix: team-foo-
@@ -185,7 +187,7 @@ secretGenerator:
- username=admin
- password=somepw
`)
th.writeF("/app/deployment.yaml", `
th.WriteF("/app/deployment.yaml", `
apiVersion: apps/v1beta2
kind: Deployment
metadata:
@@ -211,7 +213,7 @@ spec:
name: configmap-in-base
name: configmap-in-base
`)
th.writeF("/app/service.yaml", `
th.WriteF("/app/service.yaml", `
apiVersion: v1
kind: Service
metadata:
@@ -227,13 +229,13 @@ spec:
}
func TestBaseWithGeneratorsAlone(t *testing.T) {
th := NewKustTestHarness(t, "/app")
th := kusttest_test.NewKustTestHarness(t, "/app")
makeBaseWithGenerators(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:
foo: bar
@@ -321,9 +323,9 @@ spec:
}
func TestMergeAndReplaceGenerators(t *testing.T) {
th := NewKustTestHarness(t, "/overlay")
th := kusttest_test.NewKustTestHarness(t, "/overlay")
makeBaseWithGenerators(th)
th.writeF("/overlay/deployment.yaml", `
th.WriteF("/overlay/deployment.yaml", `
apiVersion: apps/v1beta2
kind: Deployment
metadata:
@@ -340,7 +342,7 @@ spec:
name: configmap-in-overlay
name: configmap-in-overlay
`)
th.writeK("/overlay", `
th.WriteK("/overlay", `
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
namePrefix: staging-
@@ -365,11 +367,11 @@ secretGenerator:
literals:
- proxy=haproxy
`)
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:
foo: override-bar