From f62af4ebf30b47ada156cccc213f6fbdf0744ba1 Mon Sep 17 00:00:00 2001 From: jregan Date: Sun, 30 Jun 2019 08:40:40 -0700 Subject: [PATCH] Define some constants in a test for later reuse. --- pkg/target/diamondcomposition_test.go | 99 +++++++++++++-------------- 1 file changed, 48 insertions(+), 51 deletions(-) diff --git a/pkg/target/diamondcomposition_test.go b/pkg/target/diamondcomposition_test.go index 0756d9cfb..bd0f014f3 100644 --- a/pkg/target/diamondcomposition_test.go +++ b/pkg/target/diamondcomposition_test.go @@ -10,6 +10,44 @@ import ( kusttest_test "sigs.k8s.io/kustomize/v3/pkg/kusttest" ) +const patchAddProbe = ` +apiVersion: apps/v1 +kind: Deployment +metadata: + name: my-deployment +spec: + template: + spec: + containers: + - name: my-deployment + livenessProbe: + httpGet: + path: /healthz + port: 8080 +` + +const patchDnsPolicy = ` +apiVersion: apps/v1 +kind: Deployment +metadata: + name: my-deployment +spec: + template: + spec: + dnsPolicy: ClusterFirst +` + +const patchRestartPolicy = ` +apiVersion: apps/v1 +kind: Deployment +metadata: + name: my-deployment +spec: + template: + spec: + restartPolicy: Always +` + // Here's a composite kustomization, that combines multiple overlays // (replicas, dns and metadata) which patch the same base resource. // @@ -47,77 +85,30 @@ func writeProbeOverlay(th *kusttest_test.KustTestHarness) { th.WriteK("/app/probe", ` resources: - ../base - patchesStrategicMerge: - dep-patch.yaml `) - - th.WriteF("/app/probe/dep-patch.yaml", ` -apiVersion: apps/v1 -kind: Deployment -metadata: - name: my-deployment -spec: - template: - spec: - containers: - - name: my-deployment - livenessProbe: - httpGet: - path: /healthz - port: 8080 -`) + th.WriteF("/app/probe/dep-patch.yaml", patchAddProbe) } func writeDNSOverlay(th *kusttest_test.KustTestHarness) { th.WriteK("/app/dns", ` resources: - ../base - patchesStrategicMerge: - dep-patch.yaml `) - - th.WriteF("/app/dns/dep-patch.yaml", ` -apiVersion: apps/v1 -kind: Deployment -metadata: - name: my-deployment -spec: - template: - spec: - dnsPolicy: ClusterFirst -`) + th.WriteF("/app/dns/dep-patch.yaml", patchDnsPolicy) } func writeRestartOverlay(th *kusttest_test.KustTestHarness) { th.WriteK("/app/restart", ` resources: - ../base - patchesStrategicMerge: - dep-patch.yaml `) - - th.WriteF("/app/restart/dep-patch.yaml", ` -apiVersion: apps/v1 -kind: Deployment -metadata: - name: my-deployment -spec: - template: - spec: - restartPolicy: Always -`) -} - -func writeComposite(th *kusttest_test.KustTestHarness) { - th.WriteK("/app/composite", ` -resources: -- ../probe -- ../dns -- ../restart -`) + th.WriteF("/app/restart/dep-patch.yaml", patchRestartPolicy) } func TestCompositeDiamond(t *testing.T) { @@ -126,7 +117,13 @@ func TestCompositeDiamond(t *testing.T) { writeProbeOverlay(th) writeDNSOverlay(th) writeRestartOverlay(th) - writeComposite(th) + + th.WriteK("/app/composite", ` +resources: +- ../probe +- ../dns +- ../restart +`) _, err := th.MakeKustTarget().MakeCustomizedResMap() if err == nil {