mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-12 01:14:22 +00:00
Allow replicas to find modified names.
Also allows to test for modified resmaps instead of directly loading them.
This commit is contained in:
@@ -151,3 +151,85 @@ spec:
|
||||
app: app
|
||||
`)
|
||||
}
|
||||
|
||||
func TestMatchesCurrentID(t *testing.T) {
|
||||
tc := plugins_test.NewEnvForTest(t).Set()
|
||||
defer tc.Reset()
|
||||
|
||||
tc.BuildGoPlugin("builtin", "", "PrefixSuffixTransformer")
|
||||
tc.BuildGoPlugin("builtin", "", "ReplicaCountTransformer")
|
||||
|
||||
th := kusttest_test.NewKustTestPluginHarness(t, "/app")
|
||||
|
||||
rm := th.LoadAndRunTransformer(`
|
||||
apiVersion: builtin
|
||||
kind: PrefixSuffixTransformer
|
||||
metadata:
|
||||
name: notImportantHere
|
||||
suffix: -test
|
||||
fieldSpecs:
|
||||
- path: metadata/name
|
||||
`, `
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: deployment`)
|
||||
|
||||
rm, _ = th.RunTransformerFromResMap(`
|
||||
apiVersion: builtin
|
||||
kind: ReplicaCountTransformer
|
||||
metadata:
|
||||
name: notImportantHere
|
||||
|
||||
replica:
|
||||
name: deployment-test
|
||||
count: 23
|
||||
fieldSpecs:
|
||||
- path: spec/replicas
|
||||
create: true
|
||||
kind: Deployment`, rm)
|
||||
th.AssertActualEqualsExpected(rm, `
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: deployment-test
|
||||
spec:
|
||||
replicas: 23
|
||||
`)
|
||||
}
|
||||
|
||||
func TestNoMatch(t *testing.T) {
|
||||
tc := plugins_test.NewEnvForTest(t).Set()
|
||||
defer tc.Reset()
|
||||
|
||||
tc.BuildGoPlugin("builtin", "", "ReplicaCountTransformer")
|
||||
|
||||
th := kusttest_test.NewKustTestPluginHarness(t, "/app")
|
||||
|
||||
err := th.ErrorFromLoadAndRunTransformer(`
|
||||
apiVersion: builtin
|
||||
kind: ReplicaCountTransformer
|
||||
metadata:
|
||||
name: notImportantHere
|
||||
replica:
|
||||
name: service
|
||||
count: 3
|
||||
fieldSpecs:
|
||||
- path: spec/replicas
|
||||
create: true
|
||||
kind: Deployment
|
||||
`, `
|
||||
kind: Service
|
||||
metadata:
|
||||
name: service
|
||||
spec:
|
||||
`)
|
||||
|
||||
if err == nil {
|
||||
t.Fatalf("No match should return an error")
|
||||
}
|
||||
if err.Error() !=
|
||||
"Resource with name service does not match a config with the following GVK [~G_~V_Deployment]" {
|
||||
t.Fatalf("Unexpected error: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user