Files
kustomize/kyaml/yaml/merge2/element_test.go
Phillip Wittrock 98431f6a00 fix kyaml issue where dropping Style created issues
dropping the node style creates a compatibility issue where quotes around "on" are dropped
because yaml.v3 interprets it as a string.

other yaml parsers interpret on as a bool value, and parse it as a bool rather than string.

fix: retain the original style so it is kept as quoted.

- fmt: don't drop the styles
- merge2: keep the style when merging elements
- setting a field: if changing the value of a scalar field, retain its style by default
2019-12-19 20:25:31 -08:00

255 lines
3.0 KiB
Go

// Copyright 2019 The Kubernetes Authors.
// SPDX-License-Identifier: Apache-2.0
package merge2_test
var elementTestCases = []testCase{
{`merge Element -- keep field in dest`,
`
kind: Deployment
items:
- name: foo
image: foo:v1
`,
`
kind: Deployment
items:
- name: foo
image: foo:v0
command: ['run.sh']
`,
`
kind: Deployment
items:
- name: foo
image: foo:v1
command: ['run.sh']
`,
},
{`merge Element -- add field to dest`,
`
kind: Deployment
items:
- name: foo
image: foo:v1
command: ['run.sh']
`,
`
kind: Deployment
items:
- name: foo
image: foo:v0
`,
`
kind: Deployment
items:
- name: foo
image: foo:v1
command: ['run.sh']
`,
},
{`merge Element -- add list, empty in dest`,
`
kind: Deployment
items:
- name: foo
image: foo:v1
command: ['run.sh']
`,
`
kind: Deployment
items: []
`,
`
kind: Deployment
items:
- name: foo
image: foo:v1
command: ['run.sh']
`,
},
{`merge Element -- add list, missing from dest`,
`
kind: Deployment
items:
- name: foo
image: foo:v1
command: ['run.sh']
`,
`
kind: Deployment
`,
`
kind: Deployment
items:
- name: foo
image: foo:v1
command: ['run.sh']
`,
},
{`merge Element -- add Element first`,
`
kind: Deployment
items:
- name: bar
image: bar:v1
command: ['run2.sh']
- name: foo
image: foo:v1
`,
`
kind: Deployment
items:
- name: foo
image: foo:v0
`,
`
kind: Deployment
items:
- name: foo
image: foo:v1
- name: bar
image: bar:v1
command: ['run2.sh']
`,
},
{`merge Element -- add Element second`,
`
kind: Deployment
items:
- name: foo
image: foo:v1
- name: bar
image: bar:v1
command: ['run2.sh']
`,
`
kind: Deployment
items:
- name: foo
image: foo:v0
`,
`
kind: Deployment
items:
- name: foo
image: foo:v1
- name: bar
image: bar:v1
command: ['run2.sh']
`,
},
//
// Test Case
//
{`keep list -- list missing from src`,
`
kind: Deployment
`,
`
kind: Deployment
items:
- name: foo
image: foo:v1
- name: bar
image: bar:v1
command: ['run2.sh']
`,
`
kind: Deployment
items:
- name: foo
image: foo:v1
- name: bar
image: bar:v1
command: ['run2.sh']
`,
},
//
// Test Case
//
{`keep Element -- element missing in src`,
`
kind: Deployment
items:
- name: foo
image: foo:v1
`,
`
kind: Deployment
items:
- name: foo
image: foo:v0
- name: bar
image: bar:v1
command: ['run2.sh']
`,
`
kind: Deployment
items:
- name: foo
image: foo:v1
- name: bar
image: bar:v1
command: ['run2.sh']
`,
},
//
// Test Case
//
{`keep element -- empty list in src`,
`
kind: Deployment
items: {}
`,
`
kind: Deployment
items:
- name: foo
image: foo:v1
- name: bar
image: bar:v1
command: ['run2.sh']
`,
`
kind: Deployment
items:
- name: foo
image: foo:v1
- name: bar
image: bar:v1
command: ['run2.sh']
`,
},
//
// Test Case
//
{`remove Element -- null in src`,
`
kind: Deployment
items: null
`,
`
kind: Deployment
items:
- name: foo
image: foo:v1
- name: bar
image: bar:v1
command: ['run2.sh']
`,
`
kind: Deployment
`,
},
}