Skip to content

Commit

Permalink
add test with diamond shape
Browse files Browse the repository at this point in the history
  • Loading branch information
Liujingfang1 committed Nov 11, 2019
1 parent 06e10cc commit 3e4354d
Show file tree
Hide file tree
Showing 3 changed files with 177 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -282,4 +282,127 @@ kind: ConfigMap
metadata:
name: cm
`)
}
}

func TestReplacementTransformerWithDiamondShape(t *testing.T) {
tc := kusttest_test.NewPluginTestEnv(t).Set()
defer tc.Reset()

tc.BuildGoPlugin(
"someteam.example.com", "v1", "ReplacementTransformer")

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

th.WriteF("/app/base/deployment.yaml",
`
group: apps
apiVersion: v1
kind: Deployment
metadata:
name: deploy1
spec:
template:
spec:
containers:
- image: nginx:1.7.9
name: nginx
`)

th.WriteF("/app/base/kustomization.yaml",
`
resources:
- deployment.yaml
`)

th.WriteF("/app/a/kustomization.yaml",
`
nameprefix: a-
resources:
- ../base
transformers:
- replacement.yaml
`)

th.WriteF("/app/a/replacement.yaml",
`
apiVersion: someteam.example.com/v1
kind: ReplacementTransformer
metadata:
name: notImportantHere
replacements:
- source:
value: nginx:newtagA
target:
objref:
kind: Deployment
fieldrefs:
- spec.template.spec.containers[name=nginx].image
`)

th.WriteF("/app/b/kustomization.yaml",
`
nameprefix: b-
resources:
- ../base
transformers:
- replacement.yaml
`)

th.WriteF("/app/b/replacement.yaml",
`
apiVersion: someteam.example.com/v1
kind: ReplacementTransformer
metadata:
name: notImportantHere
replacements:
- source:
value: nginx:newtagB
target:
objref:
kind: Deployment
fieldrefs:
- spec.template.spec.containers[name=nginx].image
`)


th.WriteF("/app/combined/kustomization.yaml",
`
resources:
- ../a
- ../b
`)

m, err := th.MakeKustTarget().MakeCustomizedResMap()
if err != nil {
t.Fatalf("Err: %v", err)
}

th.AssertActualEqualsExpected(m, `
apiVersion: v1
group: apps
kind: Deployment
metadata:
name: a-deploy1
spec:
template:
spec:
containers:
- image: nginx:newtagA
name: nginx
---
apiVersion: v1
group: apps
kind: Deployment
metadata:
name: b-deploy1
spec:
template:
spec:
containers:
- image: nginx:newtagB
name: nginx
`)
}

4 changes: 0 additions & 4 deletions plugin/someteam.example.com/v1/replacementtransformer/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@ module sigs.k8s.io/kustomize/plugin/someteam.example.com/v1/replacementtransform
go 1.13

require (
github.com/emicklei/go-restful v2.9.6+incompatible // indirect
github.com/googleapis/gnostic v0.3.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
sigs.k8s.io/kustomize/api v0.0.1
sigs.k8s.io/kustomize/v3 v3.3.1
sigs.k8s.io/yaml v1.1.0
)

Expand Down
Loading

0 comments on commit 3e4354d

Please sign in to comment.