mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-14 10:30:59 +00:00
Move another test.
This commit is contained in:
97
api/krusty/customconfigofbuiltinplugin_test.go
Normal file
97
api/krusty/customconfigofbuiltinplugin_test.go
Normal file
@@ -0,0 +1,97 @@
|
||||
// Copyright 2019 The Kubernetes Authors.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package krusty_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
kusttest_test "sigs.k8s.io/kustomize/api/testutils/kusttest"
|
||||
)
|
||||
|
||||
// Demo custom configuration of a builtin transformation.
|
||||
// This is a NamePrefixer that touches Deployments
|
||||
// and Services exclusively.
|
||||
func TestCustomNamePrefixer(t *testing.T) {
|
||||
tc := kusttest_test.NewPluginTestEnv(t).Set()
|
||||
defer tc.Reset()
|
||||
|
||||
tc.BuildGoPlugin(
|
||||
"builtin", "", "PrefixSuffixTransformer")
|
||||
|
||||
th := makeTestHarness(t)
|
||||
th.WriteK("/app", `
|
||||
resources:
|
||||
- deployment.yaml
|
||||
- role.yaml
|
||||
- service.yaml
|
||||
transformers:
|
||||
- prefixer.yaml
|
||||
`)
|
||||
th.WriteF("/app/prefixer.yaml", `
|
||||
apiVersion: builtin
|
||||
kind: PrefixSuffixTransformer
|
||||
metadata:
|
||||
name: customPrefixer
|
||||
prefix: zzz-
|
||||
fieldSpecs:
|
||||
- kind: Deployment
|
||||
path: metadata/name
|
||||
- kind: Service
|
||||
path: metadata/name
|
||||
`)
|
||||
th.WriteF("/app/deployment.yaml", `
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: myDeployment
|
||||
spec:
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
backend: awesome
|
||||
spec:
|
||||
containers:
|
||||
- name: whatever
|
||||
image: whatever
|
||||
`)
|
||||
th.WriteF("/app/role.yaml", `
|
||||
apiVersion: v1
|
||||
kind: Role
|
||||
metadata:
|
||||
name: myRole
|
||||
`)
|
||||
th.WriteF("/app/service.yaml", `
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: myService
|
||||
`)
|
||||
|
||||
m := th.Run("/app", th.MakeDefaultOptions())
|
||||
th.AssertActualEqualsExpected(m, `
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: zzz-myDeployment
|
||||
spec:
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
backend: awesome
|
||||
spec:
|
||||
containers:
|
||||
- image: whatever
|
||||
name: whatever
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: Role
|
||||
metadata:
|
||||
name: myRole
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: zzz-myService
|
||||
`)
|
||||
}
|
||||
Reference in New Issue
Block a user