mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-12 01:14:22 +00:00
kyaml: initial support for yaml and resource manipulation
This commit is contained in:
265
kyaml/yaml/merge2/element_test.go
Normal file
265
kyaml/yaml/merge2/element_test.go
Normal file
@@ -0,0 +1,265 @@
|
||||
// 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
|
||||
`,
|
||||
},
|
||||
}
|
||||
Reference in New Issue
Block a user