Debian Codegraph @

kyaml/yaml/merge3/scalar_test.go

raw symbols SCIP
1 // Copyright 2019 The Kubernetes Authors.
2 // SPDX-License-Identifier: Apache-2.0
3
4 package merge3_test
5
6 var scalarTestCases = []testCase{
7 // Scalar Field Test Cases
8 //
9 // Test Case
10 //
11 {
12 description: `Set and updated a field`,
13 origin: `kind: Deployment`,
14 update: `kind: StatefulSet`,
15 local: `kind: Deployment`,
16 expected: `kind: StatefulSet`},
17
18 {
19 description: `Add an updated field`,
20 origin: `
21 apiVersion: apps/v1
22 kind: Deployment # old value`,
23 update: `
24 apiVersion: apps/v1
25 kind: StatefulSet # new value`,
26 local: `
27 apiVersion: apps/v1`,
28 expected: `
29 apiVersion: apps/v1
30 kind: StatefulSet # new value`},
31
32 //
33 // Test Case
34 //
35 {
36 description: `Ensure comments are added`,
37 origin: `
38 apiVersion: apps/v1
39 kind: Deployment
40 metadata:
41 name: nginx-deployment
42 annotations:
43 config.kubernetes.io/index: '0'
44 config.kubernetes.io/merge-source: 'dest'
45 config.kubernetes.io/path: 'temp.yaml'
46 spec:
47 replicas: 3`,
48 update: `
49 apiVersion: apps/v1
50 kind: Deployment
51 metadata:
52 name: nginx-deployment
53 annotations:
54 config.kubernetes.io/index: '0'
55 config.kubernetes.io/merge-source: 'updated'
56 config.kubernetes.io/path: 'temp.yaml'
57 spec:
58 replicas: 3 # {"$openapi":"replicas"}`,
59 local: `
60 apiVersion: apps/v1
61 kind: Deployment
62 metadata:
63 name: nginx-deployment
64 annotations:
65 config.kubernetes.io/index: '0'
66 config.kubernetes.io/merge-source: 'original'
67 config.kubernetes.io/path: 'temp.yaml'
68 spec:
69 replicas: 3
70 `,
71 expected: `
72 apiVersion: apps/v1
73 kind: Deployment
74 metadata:
75 name: nginx-deployment
76 annotations:
77 config.kubernetes.io/index: '0'
78 config.kubernetes.io/merge-source: 'updated'
79 config.kubernetes.io/path: 'temp.yaml'
80 spec:
81 replicas: 3 # {"$openapi":"replicas"}
82 `},
83
84 //
85 // Test Case
86 //
87 {
88 description: `Ensure comments are updated`,
89 origin: `
90 apiVersion: apps/v1
91 kind: Deployment
92 metadata:
93 name: nginx-deployment
94 annotations:
95 config.kubernetes.io/index: '0'
96 config.kubernetes.io/merge-source: 'dest'
97 config.kubernetes.io/path: 'temp.yaml'
98 spec:
99 replicas: 3 # {"$openapi":"replicas"}`,
100 update: `
101 apiVersion: apps/v1
102 kind: Deployment
103 metadata:
104 name: nginx-deployment
105 annotations:
106 config.kubernetes.io/index: '0'
107 config.kubernetes.io/merge-source: 'updated'
108 config.kubernetes.io/path: 'temp.yaml'
109 spec:
110 replicas: 3 # {"$openapi":"replicas_new"}`,
111 local: `
112 apiVersion: apps/v1
113 kind: Deployment
114 metadata:
115 name: nginx-deployment
116 annotations:
117 config.kubernetes.io/index: '0'
118 config.kubernetes.io/merge-source: 'original'
119 config.kubernetes.io/path: 'temp.yaml'
120 spec:
121 replicas: 3 # {"$openapi":"replicas"}
122 `,
123 expected: `
124 apiVersion: apps/v1
125 kind: Deployment
126 metadata:
127 name: nginx-deployment
128 annotations:
129 config.kubernetes.io/index: '0'
130 config.kubernetes.io/merge-source: 'updated'
131 config.kubernetes.io/path: 'temp.yaml'
132 spec:
133 replicas: 3 # {"$openapi":"replicas_new"}
134 `},
135
136 {
137 description: `Ensure deleted comments are not updated`,
138 origin: `
139 apiVersion: apps/v1
140 kind: Deployment
141 metadata:
142 name: nginx-deployment
143 annotations:
144 config.kubernetes.io/index: '0'
145 config.kubernetes.io/merge-source: 'dest'
146 config.kubernetes.io/path: 'temp.yaml'
147 spec:
148 replicas: 3 # {"$openapi":"replicas"}`,
149 update: `
150 apiVersion: apps/v1
151 kind: Deployment
152 metadata:
153 name: nginx-deployment
154 annotations:
155 config.kubernetes.io/index: '0'
156 config.kubernetes.io/merge-source: 'updated'
157 config.kubernetes.io/path: 'temp.yaml'
158 spec:
159 replicas: 3 # {"$openapi":"replicas"}`,
160 local: `
161 apiVersion: apps/v1
162 kind: Deployment
163 metadata:
164 name: nginx-deployment
165 annotations:
166 config.kubernetes.io/index: '0'
167 config.kubernetes.io/merge-source: 'original'
168 config.kubernetes.io/path: 'temp.yaml'
169 spec:
170 replicas: 4
171 `,
172 expected: `
173 apiVersion: apps/v1
174 kind: Deployment
175 metadata:
176 name: nginx-deployment
177 annotations:
178 config.kubernetes.io/index: '0'
179 config.kubernetes.io/merge-source: 'updated'
180 config.kubernetes.io/path: 'temp.yaml'
181 spec:
182 replicas: 4
183 `},
184
185 {
186 description: `Add keep an omitted field`,
187 origin: `
188 apiVersion: apps/v1
189 kind: Deployment`,
190 update: `
191 apiVersion: apps/v1
192 kind: StatefulSet`,
193 local: `
194 apiVersion: apps/v1
195 spec: foo # field not present in source
196 `,
197 expected: `
198 apiVersion: apps/v1
199 spec: foo # field not present in source
200 kind: StatefulSet
201 `},
202
203 //
204 // Test Case
205 //
206 // TODO(#36): consider making this an error
207 {
208 description: `Change an updated field`,
209 origin: `
210 apiVersion: apps/v1
211 kind: Deployment # old value`,
212 update: `
213 apiVersion: apps/v1
214 kind: StatefulSet # new value`,
215 local: `
216 apiVersion: apps/v1
217 kind: Service # conflicting value`,
218 expected: `
219 apiVersion: apps/v1
220 kind: StatefulSet # new value`},
221
222 {
223 description: `Ignore a field`,
224 origin: `
225 apiVersion: apps/v1
226 kind: Deployment # ignore this field`,
227 update: `
228 apiVersion: apps/v1
229 kind: Deployment # ignore this field`,
230 local: `
231 apiVersion: apps/v1`,
232 expected: `
233 apiVersion: apps/v1`},
234
235 {
236 description: `Explicitly clear a field`,
237 origin: `
238 apiVersion: apps/v1`,
239 update: `
240 apiVersion: apps/v1
241 kind: null # clear this value`,
242 local: `
243 apiVersion: apps/v1
244 kind: Deployment # value to be cleared`,
245 expected: `
246 apiVersion: apps/v1`},
247
248 {description: `Implicitly clear a field`,
249 origin: `
250 apiVersion: apps/v1
251 kind: Deployment # clear this field`,
252 update: `
253 apiVersion: apps/v1`,
254 local: `
255 apiVersion: apps/v1
256 kind: Deployment # clear this field`,
257 expected: `
258 apiVersion: apps/v1`},
259
260 //
261 // Test Case
262 //
263 // TODO(#36): consider making this an error
264 {
265 description: `Implicitly clear a changed field`,
266 origin: `
267 apiVersion: apps/v1
268 kind: Deployment`,
269 update: `
270 apiVersion: apps/v1`,
271 local: `
272 apiVersion: apps/v1
273 kind: StatefulSet`,
274 expected: `
275 apiVersion: apps/v1`},
276
277 //
278 // Test Case
279 //
280 {
281 description: `Merge an empty scalar value`,
282 origin: `
283 apiVersion: apps/v1
284 `,
285 update: `
286 apiVersion: apps/v1
287 kind: {}
288 `,
289 local: `
290 apiVersion: apps/v1
291 `,
292 expected: `
293 apiVersion: apps/v1
294 kind: {}
295 `},
296 }