some transformer plugins

This commit is contained in:
jregan
2019-04-04 13:21:42 -07:00
parent 53f0deec8f
commit 440d036176
6 changed files with 281 additions and 1 deletions

View File

@@ -0,0 +1,119 @@
/*
Copyright 2019 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package target_test
import (
"sigs.k8s.io/kustomize/pkg/types"
"testing"
)
func writeDeployment(th *KustTestHarness, path string) {
th.writeF(path, `
apiVersion: apps/v1
kind: Deployment
metadata:
name: myDeployment
spec:
template:
metadata:
labels:
backend: awesome
spec:
containers:
- name: whatever
image: whatever
`)
}
func writeStringPrefixer(th *KustTestHarness, path string) {
th.writeF(path, `
apiVersion: strings.microwoosh.com/v1
kind: StringPrefixer
metadata:
name: myStringPrefixer
prefix: apple-
`)
}
func writeDatePrefixer(th *KustTestHarness, path string) {
th.writeF(path, `
apiVersion: team.dater.com/v1
kind: DatePrefixer
metadata:
name: myDatePrefixer
`)
}
func TestOrderedTransformers(t *testing.T) {
th := NewKustTestHarnessWithPluginConfig(
t, "/app", types.PluginConfig{GoEnabled: true})
th.writeK("/app", `
resources:
- deployment.yaml
transformers:
- stringPrefixer.yaml
`)
writeDeployment(th, "/app/deployment.yaml")
writeStringPrefixer(th, "/app/stringPrefixer.yaml")
writeDatePrefixer(th, "/app/datePrefixer.yaml")
m, err := th.makeKustTarget().MakeCustomizedResMap()
if err != nil {
t.Fatalf("Err: %v", err)
}
th.assertActualEqualsExpected(m, `
apiVersion: apps/v1
kind: Deployment
metadata:
name: apple-myDeployment
spec:
template:
metadata:
labels:
backend: awesome
spec:
containers:
- image: whatever
name: whatever
`)
}
func xTestTransformedTransformers(t *testing.T) {
th := NewKustTestHarnessWithPluginConfig(
t, "/app/overlay", types.PluginConfig{GoEnabled: true})
th.writeK("/app/base", `
resources:
- stringPrefixer.yaml
transformers:
- datePrefixer.yaml
`)
writeStringPrefixer(th, "/app/base/stringPrefixer.yaml")
writeDatePrefixer(th, "/app/base/datePrefixer.yaml")
th.writeK("/app/overlay", `
resources:
- deployment.yaml
transformers:
- ../base
`)
writeDeployment(th, "/app/overlay/deployment.yaml")
m, err := th.makeKustTarget().MakeCustomizedResMap()
if err != nil {
t.Fatalf("Err: %v", err)
}
th.assertActualEqualsExpected(m, `
HEY
`)
}