From 6788af083b1eb9840cf3305c8ab1ef276f1e2d6a Mon Sep 17 00:00:00 2001 From: Natasha Sarkar Date: Mon, 9 Nov 2020 11:35:37 -0800 Subject: [PATCH] updated tests for multiple merge keys --- .../patchstrategicmerge_test.go | 15 ++-- .../patchtransformer/PatchTransformer_test.go | 78 ++++++++++++++++++- 2 files changed, 85 insertions(+), 8 deletions(-) diff --git a/api/filters/patchstrategicmerge/patchstrategicmerge_test.go b/api/filters/patchstrategicmerge/patchstrategicmerge_test.go index 6c69968c7..81456e9bb 100644 --- a/api/filters/patchstrategicmerge/patchstrategicmerge_test.go +++ b/api/filters/patchstrategicmerge/patchstrategicmerge_test.go @@ -372,9 +372,6 @@ spec: image: test `, }, - // the following tests document broken behavior and - // will be fixed - // ref: #3111, #3159 "list map keys - add a port, no names": { input: ` apiVersion: apps/v1 @@ -424,6 +421,8 @@ spec: protocol: UDP - containerPort: 80 protocol: UDP + - containerPort: 8080 + protocol: TCP `, }, "list map keys - add name to port": { @@ -472,6 +471,9 @@ spec: - image: test-image name: test-deployment ports: + - containerPort: 8080 + protocol: UDP + name: UDP-name-patch - containerPort: 8080 protocol: TCP `, @@ -524,15 +526,14 @@ spec: - image: test-image name: test-deployment ports: + - containerPort: 8080 + protocol: UDP + name: UDP-name-patch - containerPort: 8080 protocol: TCP name: TCP-name-original `, }, - - // the following tests document behavior - // that should not be affected by - // changes due to #3111, #3159 "list map keys - add a port, no protocol": { input: ` apiVersion: apps/v1 diff --git a/plugin/builtin/patchtransformer/PatchTransformer_test.go b/plugin/builtin/patchtransformer/PatchTransformer_test.go index aab64751e..8d9bf41fc 100644 --- a/plugin/builtin/patchtransformer/PatchTransformer_test.go +++ b/plugin/builtin/patchtransformer/PatchTransformer_test.go @@ -508,6 +508,82 @@ spec: `) } +func TestPatchTransformerWithInlineYamlRegexTarget(t *testing.T) { + th := kusttest_test.MakeEnhancedHarness(t). + PrepBuiltin("PatchTransformer") + defer th.Reset() + + th.RunTransformerAndCheckResult(` +apiVersion: builtin +kind: PatchTransformer +metadata: + name: notImportantHere +target: + name: .*Deploy + kind: Deployment|MyKind + group: \w{4} + version: v\d +patch: |- + apiVersion: apps/v1 + metadata: + name: myDeploy + kind: Deployment + spec: + replica: 77 +`, someDeploymentResources, ` +apiVersion: apps/v1 +kind: Deployment +metadata: + labels: + old-label: old-value + name: myDeploy +spec: + replica: 77 + template: + metadata: + labels: + old-label: old-value + spec: + containers: + - image: nginx + name: nginx +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + labels: + new-label: new-value + name: yourDeploy +spec: + replica: 77 + template: + metadata: + labels: + new-label: new-value + spec: + containers: + - image: nginx:1.7.9 + name: nginx +--- +apiVersion: apps/v1 +kind: MyKind +metadata: + label: + old-label: old-value + name: myDeploy +spec: + replica: 77 + template: + metadata: + labels: + old-label: old-value + spec: + containers: + - image: nginx + name: nginx +`) +} + func TestPatchTransformerWithPatchDelete(t *testing.T) { th := kusttest_test.MakeEnhancedHarness(t). PrepBuiltin("PatchTransformer") @@ -747,7 +823,7 @@ spec: name: test-deployment ports: - containerPort: 8080 - name: disappearing-act + name: take-over-the-world protocol: TCP `) }