From adedca09f21b1c0a3d9f35346cd7c64ef6cbc28e Mon Sep 17 00:00:00 2001 From: brianpursley Date: Mon, 2 Aug 2021 20:36:28 -0400 Subject: [PATCH] Add unit tests for current behavior of three way merge --- kyaml/yaml/merge3/element_test.go | 175 ++++++++++++++++++++++++++++++ 1 file changed, 175 insertions(+) diff --git a/kyaml/yaml/merge3/element_test.go b/kyaml/yaml/merge3/element_test.go index 80efe5907..c3257dddb 100644 --- a/kyaml/yaml/merge3/element_test.go +++ b/kyaml/yaml/merge3/element_test.go @@ -1476,6 +1476,181 @@ spec: protocol: TCP `}, + // + // Test Case + // + { + description: `Add single container port and add another container port after an existing container port`, + origin: ` +apiVersion: apps/v1 +kind: Deployment +metadata: + name: test-deployment +spec: + template: + spec: + containers: + - image: test-image + name: test-deployment + ports: + - containerPort: 8001 + name: A + protocol: TCP + - containerPort: 8002 + name: B + protocol: TCP +`, + update: ` +apiVersion: apps/v1 +kind: Deployment +metadata: + name: test-deployment +spec: + template: + spec: + containers: + - image: test-image + name: test-deployment + ports: + - containerPort: 8004 + name: D + protocol: TCP +`, + local: ` +apiVersion: apps/v1 +kind: Deployment +metadata: + name: test-deployment +spec: + template: + spec: + containers: + - image: test-image + name: test-deployment + ports: + - containerPort: 8001 + name: A + protocol: TCP + - containerPort: 8003 + name: C + protocol: TCP +`, + // This test records current behavior, but this behavior might be undesirable. + // If so, feel free to change the test to pass with some improved algorithm. + expected: ` +apiVersion: apps/v1 +kind: Deployment +metadata: + name: test-deployment +spec: + template: + spec: + containers: + - image: test-image + name: test-deployment + ports: + - containerPort: 8003 + name: C + protocol: TCP + - containerPort: 8004 + name: D + protocol: TCP +`}, + + // + // Test Case + // + { + description: `Add new container port after existing container ports and add another container port between existing container ports`, + origin: ` +apiVersion: apps/v1 +kind: Deployment +metadata: + name: test-deployment +spec: + template: + spec: + containers: + - image: test-image + name: test-deployment + ports: + - containerPort: 8001 + name: A + protocol: TCP + - containerPort: 8002 + name: B + protocol: TCP +`, + update: ` +apiVersion: apps/v1 +kind: Deployment +metadata: + name: test-deployment +spec: + template: + spec: + containers: + - image: test-image + name: test-deployment + ports: + - containerPort: 8001 + name: A + protocol: TCP + - containerPort: 8002 + name: B + protocol: TCP + - containerPort: 8004 + name: D + protocol: TCP +`, + local: ` +apiVersion: apps/v1 +kind: Deployment +metadata: + name: test-deployment +spec: + template: + spec: + containers: + - image: test-image + name: test-deployment + ports: + - containerPort: 8001 + name: A + protocol: TCP + - containerPort: 8003 + name: C + protocol: TCP + - containerPort: 8002 + name: B + protocol: TCP +`, + expected: ` +apiVersion: apps/v1 +kind: Deployment +metadata: + name: test-deployment +spec: + template: + spec: + containers: + - image: test-image + name: test-deployment + ports: + - containerPort: 8001 + name: A + protocol: TCP + - containerPort: 8003 + name: C + protocol: TCP + - containerPort: 8002 + name: B + protocol: TCP + - containerPort: 8004 + name: D + protocol: TCP +`}, + { description: `Retain local protocol`, origin: `