1
2
3
4 package types_test
5
6 import (
7 "reflect"
8 "testing"
9
10 . "sigs.k8s.io/kustomize/api/types"
11 )
12
13 func TestMergeGlobalOptionsIntoLocal(t *testing.T) {
14 tests := []struct {
15 name string
16 local *GeneratorOptions
17 global *GeneratorOptions
18 expected *GeneratorOptions
19 }{
20 {
21 name: "everything nil",
22 local: nil,
23 global: nil,
24 expected: nil,
25 },
26 {
27 name: "nil global",
28 local: &GeneratorOptions{
29 Labels: map[string]string{"pet": "dog"},
30 Annotations: map[string]string{"fruit": "apple"},
31 },
32 global: nil,
33 expected: &GeneratorOptions{
34 Labels: map[string]string{"pet": "dog"},
35 Annotations: map[string]string{"fruit": "apple"},
36 DisableNameSuffixHash: false,
37 Immutable: false,
38 },
39 },
40 {
41 name: "nil local",
42 local: nil,
43 global: &GeneratorOptions{
44 Labels: map[string]string{"pet": "dog"},
45 Annotations: map[string]string{"fruit": "apple"},
46 },
47 expected: &GeneratorOptions{
48 Labels: map[string]string{"pet": "dog"},
49 Annotations: map[string]string{"fruit": "apple"},
50 DisableNameSuffixHash: false,
51 Immutable: false,
52 },
53 },
54 {
55 name: "global doesn't damage local",
56 local: &GeneratorOptions{
57 Labels: map[string]string{"pet": "dog"},
58 Annotations: map[string]string{
59 "fruit": "apple"},
60 },
61 global: &GeneratorOptions{
62 Labels: map[string]string{
63 "pet": "cat",
64 "simpson": "homer",
65 },
66 Annotations: map[string]string{
67 "fruit": "peach",
68 "tesla": "Y",
69 },
70 },
71 expected: &GeneratorOptions{
72 Labels: map[string]string{
73 "pet": "dog",
74 "simpson": "homer",
75 },
76 Annotations: map[string]string{
77 "fruit": "apple",
78 "tesla": "Y",
79 },
80 DisableNameSuffixHash: false,
81 Immutable: false,
82 },
83 },
84 {
85 name: "global disable trumps local",
86 local: &GeneratorOptions{
87 DisableNameSuffixHash: false,
88 Immutable: false,
89 },
90 global: &GeneratorOptions{
91 DisableNameSuffixHash: true,
92 Immutable: true,
93 },
94 expected: &GeneratorOptions{
95 DisableNameSuffixHash: true,
96 Immutable: true,
97 },
98 },
99 {
100 name: "local disable works",
101 local: &GeneratorOptions{
102 DisableNameSuffixHash: true,
103 Immutable: true,
104 },
105 global: &GeneratorOptions{
106 DisableNameSuffixHash: false,
107 Immutable: false,
108 },
109 expected: &GeneratorOptions{
110 DisableNameSuffixHash: true,
111 Immutable: true,
112 },
113 },
114 {
115 name: "everyone wants disable",
116 local: &GeneratorOptions{
117 DisableNameSuffixHash: true,
118 Immutable: true,
119 },
120 global: &GeneratorOptions{
121 DisableNameSuffixHash: true,
122 Immutable: true,
123 },
124 expected: &GeneratorOptions{
125 DisableNameSuffixHash: true,
126 Immutable: true,
127 },
128 },
129 }
130 for _, tc := range tests {
131 actual := MergeGlobalOptionsIntoLocal(tc.local, tc.global)
132 if !reflect.DeepEqual(tc.expected, actual) {
133 t.Fatalf("%s annotations: Expected '%v', got '%v'",
134 tc.name, tc.expected, *actual)
135 }
136 }
137 }
138
View as plain text