Debian Codegraph @

kyaml/yaml/merge3/list_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 listTestCases = []testCase{
7 // List Field Test Cases
8
9 //
10 // Test Case
11 //
12 {
13 description: `Replace list`,
14 origin: `
15 list:
16 - 1
17 - 2
18 - 3`,
19 update: `
20 list:
21 - 2
22 - 3
23 - 4`,
24 local: `
25 list:
26 - 1
27 - 2
28 - 3`,
29 expected: `
30 list:
31 - 2
32 - 3
33 - 4`},
34
35 //
36 // Test Case
37 //
38 {
39 description: `Add an updated list`,
40 origin: `
41 apiVersion: apps/v1
42 list: # old value
43 - 1
44 - 2
45 - 3
46 `,
47 update: `
48 apiVersion: apps/v1
49 list: # new value
50 - 2
51 - 3
52 - 4
53 `,
54 local: `
55 apiVersion: apps/v1`,
56 expected: `
57 apiVersion: apps/v1
58 list: # new value
59 - 2
60 - 3
61 - 4
62 `},
63
64 //
65 // Test Case
66 //
67 {
68 description: `Update comment`,
69 origin: `
70 list: # comment
71 - 1
72 - 2
73 - 3`,
74 update: `
75 list: # updated comment
76 - 2
77 - 3
78 - 4`,
79 local: `
80 list: # comment
81 - 1
82 - 2
83 - 3`,
84 expected: `
85 list: # updated comment
86 - 2
87 - 3
88 - 4`},
89
90 //
91 // Test Case
92 //
93 {
94 description: `Don't update local modified comment`,
95 origin: `
96 list: # origin comment
97 - 1
98 - 2
99 - 3`,
100 update: `
101 list: # updated comment
102 - 2
103 - 3
104 - 4`,
105 local: `
106 list: # local comment
107 - 1
108 - 2
109 - 3`,
110 expected: `
111 list: # local comment
112 - 2
113 - 3
114 - 4`},
115
116 //
117 // Test Case
118 //
119 {
120 description: `Don't add local deleted comment`,
121 origin: `
122 list: # origin comment
123 - 1
124 - 2
125 - 3`,
126 update: `
127 list: # updated comment
128 - 2
129 - 3
130 - 4`,
131 local: `
132 list:
133 - 1
134 - 2
135 - 3`,
136 expected: `
137 list:
138 - 2
139 - 3
140 - 4`},
141
142 {
143 description: `Add update with comment`,
144 origin: `
145 apiVersion: apps/v1
146 `,
147 update: `
148 list: # updated comment
149 - 2
150 - 3
151 - 4`,
152 local: `
153 apiVersion: apps/v1`,
154 expected: `
155 list: # updated comment
156 - 2
157 - 3
158 - 4`},
159
160 //
161 // Test Case
162 //
163 {
164 description: `Add keep an omitted field`,
165 origin: `
166 apiVersion: apps/v1
167 kind: Deployment`,
168 update: `
169 apiVersion: apps/v1
170 kind: StatefulSet`,
171 local: `
172 apiVersion: apps/v1
173 list: # not present in sources
174 - 2
175 - 3
176 - 4
177 `,
178 expected: `
179 apiVersion: apps/v1
180 list: # not present in sources
181 - 2
182 - 3
183 - 4
184 kind: StatefulSet
185 `},
186
187 //
188 // Test Case
189 //
190 // TODO(#36): consider making this an error
191 {
192 description: `Change an updated field`,
193 origin: `
194 apiVersion: apps/v1
195 list: # old value
196 - 1
197 - 2
198 - 3`,
199 update: `
200 apiVersion: apps/v1
201 list: # new value
202 - 2
203 - 3
204 - 4`,
205 local: `
206 apiVersion: apps/v1
207 list: # conflicting value
208 - a
209 - b
210 - c`,
211 expected: `
212 apiVersion: apps/v1
213 list: # conflicting value
214 - 2
215 - 3
216 - 4
217 `},
218
219 //
220 // Test Case
221 //
222 {
223 description: `Ignore a field -- set`,
224 origin: `
225 apiVersion: apps/v1
226 list: # ignore value
227 - 1
228 - 2
229 - 3
230 `,
231 update: `
232 apiVersion: apps/v1
233 list: # ignore value
234 - 1
235 - 2
236 - 3`,
237 local: `
238 apiVersion: apps/v1
239 list: # local comment
240 - 2
241 - 3
242 - 4
243 `,
244 expected: `
245 apiVersion: apps/v1
246 list: # local comment
247 - 2
248 - 3
249 - 4
250 `},
251
252 //
253 // Test Case
254 //
255 {
256 description: `Ignore a field -- empty`,
257 origin: `
258 apiVersion: apps/v1
259 list: # ignore value
260 - 1
261 - 2
262 - 3`,
263 update: `
264 apiVersion: apps/v1
265 list: # ignore value
266 - 1
267 - 2
268 - 3`,
269 local: `
270 apiVersion: apps/v1
271 `,
272 expected: `
273 apiVersion: apps/v1
274 `},
275
276 //
277 // Test Case
278 //
279 {
280 description: `Explicitly clear a field`,
281 origin: `
282 apiVersion: apps/v1`,
283 update: `
284 apiVersion: apps/v1
285 list: null # clear`,
286 local: `
287 apiVersion: apps/v1
288 list: # value to clear
289 - 1
290 - 2
291 - 3`,
292 expected: `
293 apiVersion: apps/v1`},
294
295 //
296 // Test Case
297 //
298 {
299 description: `Implicitly clear a field`,
300 origin: `
301 apiVersion: apps/v1
302 list: # clear value
303 - 1
304 - 2
305 - 3`,
306 update: `
307 apiVersion: apps/v1`,
308 local: `
309 apiVersion: apps/v1
310 list: # old value
311 - 1
312 - 2
313 - 3`,
314 expected: `
315 apiVersion: apps/v1`},
316
317 //
318 // Test Case
319 //
320 // TODO(#36): consider making this an error
321 {
322 description: `Implicitly clear a changed field`,
323 origin: `
324 apiVersion: apps/v1
325 list: # old value
326 - 1
327 - 2
328 - 3`,
329 update: `
330 apiVersion: apps/v1`,
331 local: `
332 apiVersion: apps/v1
333 list: # old value
334 - a
335 - b
336 - c`,
337 expected: `
338 apiVersion: apps/v1`},
339 }