fix: patch additions honor source key style

When a patch appends a new node, it should honor the key style from the
patch. Prior to this commit, no style was applied, leading to problems
when the key value could be interpreted as a different type based on its
content. For example, "9110" needs quoting to ensure it is seen as a
string in yaml.
This commit is contained in:
Ed Overton
2023-06-08 17:21:46 -04:00
parent 336bc14e1a
commit 691b7d1df3
5 changed files with 216 additions and 5 deletions

View File

@@ -417,6 +417,47 @@ spec:
protocol: TCP
- port: 30901
targetPort: 30901
`,
mergeOptions: yaml.MergeOptions{
ListIncreaseDirection: yaml.MergeOptionsListAppend,
},
},
//
// Test Case
//
{description: `Verify key style behavior`,
source: `
kind: Deployment
spec:
source-and-dest: source-and-dest
source-only: source-only
"source-only-key-double-quoted": source-only
source-and-dest-key-style-diff-1: source-and-dest
'source-and-dest-key-style-diff-2': source-and-dest
"source-and-dest-key-style-diff-3": source-and-dest
`,
dest: `
kind: Deployment
spec:
source-and-dest: source-and-dest
'source-and-dest-key-style-diff-1': source-and-dest
"source-and-dest-key-style-diff-2": source-and-dest
source-and-dest-key-style-diff-3: source-and-dest
dest-only: dest-only
'dest-only-key-single-quoted': dest-only
`,
expected: `
kind: Deployment
spec:
source-and-dest: source-and-dest
'source-and-dest-key-style-diff-1': source-and-dest
"source-and-dest-key-style-diff-2": source-and-dest
source-and-dest-key-style-diff-3: source-and-dest
dest-only: dest-only
'dest-only-key-single-quoted': dest-only
source-only: source-only
"source-only-key-double-quoted": source-only
`,
mergeOptions: yaml.MergeOptions{
ListIncreaseDirection: yaml.MergeOptionsListAppend,