Skip to content

Commit

Permalink
add testting for patch transformers
Browse files Browse the repository at this point in the history
  • Loading branch information
Liujingfang1 committed Jul 26, 2019
1 parent 95f3303 commit b4038a6
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ spec:
`)
}

func TestPatchJson6902TransformerWithInline(t *testing.T) {
func TestPatchJson6902TransformerWithInlineJSON(t *testing.T) {
tc := plugins_test.NewEnvForTest(t).Set()
defer tc.Reset()

Expand Down Expand Up @@ -290,3 +290,47 @@ spec:
dnsPolicy: ClusterFirst
`)
}

func TestPatchJson6902TransformerWithInlineYAML(t *testing.T) {
tc := plugins_test.NewEnvForTest(t).Set()
defer tc.Reset()

tc.BuildGoPlugin(
"builtin", "", "PatchJson6902Transformer")

th := kusttest_test.NewKustTestPluginHarness(t, "/app")

rm := th.LoadAndRunTransformer(`
apiVersion: builtin
kind: PatchJson6902Transformer
metadata:
name: notImportantHere
target:
group: apps
version: v1
kind: Deployment
name: myDeploy
jsonOp: |-
- op: add
path: /spec/template/spec/dnsPolicy
value: ClusterFirst
`, target)

th.AssertActualEqualsExpected(rm, `
apiVersion: apps/v1
kind: Deployment
metadata:
name: myDeploy
spec:
replica: 2
template:
metadata:
labels:
old-label: old-value
spec:
containers:
- image: nginx
name: nginx
dnsPolicy: ClusterFirst
`)
}
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ spec:
`)
}

func TestPatchStrategicMergeTransformerWithInline(t *testing.T) {
func TestPatchStrategicMergeTransformerWithInlineJSON(t *testing.T) {
tc := plugins_test.NewEnvForTest(t).Set()
defer tc.Reset()

Expand Down Expand Up @@ -216,6 +216,58 @@ spec:
`)
}

func TestPatchStrategicMergeTransformerWithInlineYAML(t *testing.T) {
tc := plugins_test.NewEnvForTest(t).Set()
defer tc.Reset()

tc.BuildGoPlugin(
"builtin", "", "PatchStrategicMergeTransformer")

th := kusttest_test.NewKustTestPluginHarness(t, "/app")

rm := th.LoadAndRunTransformer(`
apiVersion: builtin
kind: PatchStrategicMergeTransformer
metadata:
name: notImportantHere
patches: |-
apiVersion: apps/v1
metadata:
name: myDeploy
kind: Deployment
spec:
replica: 3
---
apiVersion: apps/v1
metadata:
name: myDeploy
kind: Deployment
spec:
template:
spec:
containers:
- name: nginx
image: nginx:latest
`, target)

th.AssertActualEqualsExpected(rm, `
apiVersion: apps/v1
kind: Deployment
metadata:
name: myDeploy
spec:
replica: 3
template:
metadata:
labels:
old-label: old-value
spec:
containers:
- image: nginx:latest
name: nginx
`)
}

func TestPatchStrategicMergeTransformerMultiplePatches(t *testing.T) {
tc := plugins_test.NewEnvForTest(t).Set()
defer tc.Reset()
Expand Down

0 comments on commit b4038a6

Please sign in to comment.