Allow replicas to find modified names.

Also allows to test for modified resmaps instead of directly loading
them.
This commit is contained in:
Damien Robichaud
2019-07-26 13:52:16 -07:00
parent 95f3303493
commit 02f6b3ec98
5 changed files with 123 additions and 5 deletions

View File

@@ -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)
}
}