Debian Codegraph @

plugin/builtin/labeltransformer/LabelTransformer_test.go

raw
1 // Copyright 2019 The Kubernetes Authors.
2 // SPDX-License-Identifier: Apache-2.0
3
4 package main_test
5
6 import (
7 "testing"
8
9 kusttest_test "sigs.k8s.io/kustomize/api/testutils/kusttest"
10 )
11
12 func TestLabelTransformer(t *testing.T) {
13 th := kusttest_test.MakeEnhancedHarness(t).
14 PrepBuiltin("LabelTransformer")
15 defer th.Reset()
16
17 rm := th.LoadAndRunTransformer(`
18 apiVersion: builtin
19 kind: LabelTransformer
20 metadata:
21 name: notImportantHere
22 labels:
23 app: myApp
24 quotedBoolean: "true"
25 quotedFruit: "peach"
26 unquotedBoolean: true
27 env: production
28 fieldSpecs:
29 - path: spec/selector
30 create: true
31 version: v1
32 kind: Service
33 - path: metadata/labels
34 create: true
35 - path: spec/selector/matchLabels
36 create: true
37 kind: Deployment
38 - path: spec/template/metadata/labels
39 create: true
40 kind: Deployment
41 `, `
42 apiVersion: v1
43 kind: Service
44 metadata:
45 name: myService
46 spec:
47 ports:
48 - port: 7002
49 ---
50 apiVersion: apps/v1
51 kind: Deployment
52 metadata:
53 name: mungebot
54 labels:
55 app: mungebot
56 spec:
57 replicas: 1
58 template:
59 metadata:
60 labels:
61 app: mungebot
62 spec:
63 containers:
64 - name: nginx
65 image: nginx
66 `)
67
68 th.AssertActualEqualsExpectedNoIdAnnotations(rm, `
69 apiVersion: v1
70 kind: Service
71 metadata:
72 labels:
73 app: myApp
74 env: production
75 quotedBoolean: "true"
76 quotedFruit: peach
77 unquotedBoolean: "true"
78 name: myService
79 spec:
80 ports:
81 - port: 7002
82 selector:
83 app: myApp
84 env: production
85 quotedBoolean: "true"
86 quotedFruit: peach
87 unquotedBoolean: "true"
88 ---
89 apiVersion: apps/v1
90 kind: Deployment
91 metadata:
92 labels:
93 app: myApp
94 env: production
95 quotedBoolean: "true"
96 quotedFruit: peach
97 unquotedBoolean: "true"
98 name: mungebot
99 spec:
100 replicas: 1
101 selector:
102 matchLabels:
103 app: myApp
104 env: production
105 quotedBoolean: "true"
106 quotedFruit: peach
107 unquotedBoolean: "true"
108 template:
109 metadata:
110 labels:
111 app: myApp
112 env: production
113 quotedBoolean: "true"
114 quotedFruit: peach
115 unquotedBoolean: "true"
116 spec:
117 containers:
118 - image: nginx
119 name: nginx
120 `)
121 }