...
1
2
3
4 package krusty_test
5
6 import (
7 "testing"
8
9 kusttest_test "sigs.k8s.io/kustomize/api/testutils/kusttest"
10 )
11
12 func TestNamespacedGenerator(t *testing.T) {
13 th := kusttest_test.MakeHarness(t)
14 th.WriteK(".", `
15 configMapGenerator:
16 - name: the-non-default-namespace-map
17 namespace: non-default
18 literals:
19 - altGreeting=Good Morning from non-default namespace!
20 - enableRisky="false"
21 - name: the-map
22 literals:
23 - altGreeting=Good Morning from default namespace!
24 - enableRisky="false"
25
26 secretGenerator:
27 - name: the-non-default-namespace-secret
28 namespace: non-default
29 literals:
30 - password.txt=verySecret
31 - name: the-secret
32 literals:
33 - password.txt=anotherSecret
34 `)
35 m := th.Run(".", th.MakeDefaultOptions())
36 th.AssertActualEqualsExpected(m, `
37 apiVersion: v1
38 data:
39 altGreeting: Good Morning from non-default namespace!
40 enableRisky: "false"
41 kind: ConfigMap
42 metadata:
43 name: the-non-default-namespace-map-64b2md8tth
44 namespace: non-default
45 ---
46 apiVersion: v1
47 data:
48 altGreeting: Good Morning from default namespace!
49 enableRisky: "false"
50 kind: ConfigMap
51 metadata:
52 name: the-map-tg7t5hk8bk
53 ---
54 apiVersion: v1
55 data:
56 password.txt: dmVyeVNlY3JldA==
57 kind: Secret
58 metadata:
59 name: the-non-default-namespace-secret-8tc9gdd76t
60 namespace: non-default
61 type: Opaque
62 ---
63 apiVersion: v1
64 data:
65 password.txt: YW5vdGhlclNlY3JldA==
66 kind: Secret
67 metadata:
68 name: the-secret-6557m7fcg8
69 type: Opaque
70 `)
71 }
72
73 func TestNamespacedGeneratorWithOverlays(t *testing.T) {
74 th := kusttest_test.MakeHarness(t)
75 th.WriteK("base", `
76 namespace: base
77
78 configMapGenerator:
79 - name: testCase
80 literals:
81 - base=apple
82 `)
83 th.WriteK("overlay", `
84 resources:
85 - ../base
86
87 namespace: overlay
88
89 configMapGenerator:
90 - name: testCase
91 behavior: merge
92 literals:
93 - overlay=peach
94 `)
95 m := th.Run("overlay", th.MakeDefaultOptions())
96 th.AssertActualEqualsExpected(m, `
97 apiVersion: v1
98 data:
99 base: apple
100 overlay: peach
101 kind: ConfigMap
102 metadata:
103 name: testCase-gmfch8gkbt
104 namespace: overlay
105 `)
106 }
107
View as plain text