@@ -2335,6 +2335,112 @@ image:
2335
2335
assert .Error (t , err )
2336
2336
assert .Equal (t , "unexpected type ScalarNode for key attributes" , err .Error ())
2337
2337
})
2338
+
2339
+ t .Run ("Aliases, comments, and multiline strings are preserved" , func (t * testing.T ) {
2340
+ expected := `
2341
+ image:
2342
+ attributes:
2343
+ name: &repo repo-name
2344
+ tag: v2.0.0
2345
+ # this is a comment
2346
+ multiline: |
2347
+ one
2348
+ two
2349
+ three
2350
+ alias: *repo
2351
+ `
2352
+
2353
+ inputData := []byte (`
2354
+ image:
2355
+ attributes:
2356
+ name: &repo repo-name
2357
+ tag: v1.0.0
2358
+ # this is a comment
2359
+ multiline: |
2360
+ one
2361
+ two
2362
+ three
2363
+ alias: *repo
2364
+ ` )
2365
+ input := yaml.Node {}
2366
+ err := yaml .Unmarshal (inputData , & input )
2367
+ require .NoError (t , err )
2368
+
2369
+ key := "image.attributes.tag"
2370
+ value := "v2.0.0"
2371
+
2372
+ err = setHelmValue (& input , key , value )
2373
+ require .NoError (t , err )
2374
+
2375
+ output , err := yaml .Marshal (& input )
2376
+ require .NoError (t , err )
2377
+ assert .Equal (t , strings .TrimSpace (expected ), strings .TrimSpace (string (output )))
2378
+ })
2379
+
2380
+ t .Run ("Aliases to mappings are followed" , func (t * testing.T ) {
2381
+ expected := `
2382
+ global:
2383
+ attributes: &attrs
2384
+ name: &repo repo-name
2385
+ tag: v2.0.0
2386
+ image:
2387
+ attributes: *attrs
2388
+ `
2389
+
2390
+ inputData := []byte (`
2391
+ global:
2392
+ attributes: &attrs
2393
+ name: &repo repo-name
2394
+ tag: v1.0.0
2395
+ image:
2396
+ attributes: *attrs
2397
+ ` )
2398
+ input := yaml.Node {}
2399
+ err := yaml .Unmarshal (inputData , & input )
2400
+ require .NoError (t , err )
2401
+
2402
+ key := "image.attributes.tag"
2403
+ value := "v2.0.0"
2404
+
2405
+ err = setHelmValue (& input , key , value )
2406
+ require .NoError (t , err )
2407
+
2408
+ output , err := yaml .Marshal (& input )
2409
+ require .NoError (t , err )
2410
+ assert .Equal (t , strings .TrimSpace (expected ), strings .TrimSpace (string (output )))
2411
+ })
2412
+
2413
+ t .Run ("Aliases to scalars are followed" , func (t * testing.T ) {
2414
+ expected := `
2415
+ image:
2416
+ attributes:
2417
+ name: repo-name
2418
+ version: &ver v2.0.0
2419
+ tag: *ver
2420
+ `
2421
+
2422
+ inputData := []byte (`
2423
+ image:
2424
+ attributes:
2425
+ name: repo-name
2426
+ version: &ver v1.0.0
2427
+ tag: *ver
2428
+ ` )
2429
+ input := yaml.Node {}
2430
+ err := yaml .Unmarshal (inputData , & input )
2431
+ require .NoError (t , err )
2432
+
2433
+ key := "image.attributes.tag"
2434
+ value := "v2.0.0"
2435
+
2436
+ err = setHelmValue (& input , key , value )
2437
+ require .NoError (t , err )
2438
+
2439
+ output , err := yaml .Marshal (& input )
2440
+ require .NoError (t , err )
2441
+ assert .Equal (t , strings .TrimSpace (expected ), strings .TrimSpace (string (output )))
2442
+ })
2443
+
2338
2444
}
2339
2445
2340
2446
func Test_GetWriteBackConfig (t * testing.T ) {
0 commit comments