mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-12 01:14:22 +00:00
convert tests to exercise openapi and inference
This commit is contained in:
@@ -6,142 +6,211 @@ package merge2_test
|
|||||||
var elementTestCases = []testCase{
|
var elementTestCases = []testCase{
|
||||||
{description: `merge Element -- keep field in dest`,
|
{description: `merge Element -- keep field in dest`,
|
||||||
source: `
|
source: `
|
||||||
|
apiVersion: apps/v1
|
||||||
kind: Deployment
|
kind: Deployment
|
||||||
items:
|
spec:
|
||||||
- name: foo
|
template:
|
||||||
image: foo:v1
|
spec:
|
||||||
|
containers:
|
||||||
|
- name: foo
|
||||||
|
image: foo:v1
|
||||||
`,
|
`,
|
||||||
dest: `
|
dest: `
|
||||||
|
apiVersion: apps/v1
|
||||||
kind: Deployment
|
kind: Deployment
|
||||||
items:
|
spec:
|
||||||
- name: foo
|
template:
|
||||||
image: foo:v0
|
spec:
|
||||||
command: ['run.sh']
|
containers:
|
||||||
|
- name: foo
|
||||||
|
image: foo:v0
|
||||||
|
command: ['run.sh']
|
||||||
`,
|
`,
|
||||||
expected: `
|
expected: `
|
||||||
|
apiVersion: apps/v1
|
||||||
kind: Deployment
|
kind: Deployment
|
||||||
items:
|
spec:
|
||||||
- name: foo
|
template:
|
||||||
image: foo:v1
|
spec:
|
||||||
command: ['run.sh']
|
containers:
|
||||||
|
- name: foo
|
||||||
|
image: foo:v1
|
||||||
|
command: ['run.sh']
|
||||||
`,
|
`,
|
||||||
},
|
},
|
||||||
|
|
||||||
{description: `merge Element -- add field to dest`,
|
{description: `merge Element -- add field to dest`,
|
||||||
source: `
|
source: `
|
||||||
|
apiVersion: apps/v1
|
||||||
kind: Deployment
|
kind: Deployment
|
||||||
items:
|
spec:
|
||||||
- name: foo
|
template:
|
||||||
image: foo:v1
|
spec:
|
||||||
command: ['run.sh']
|
containers:
|
||||||
|
- name: foo
|
||||||
|
image: foo:v1
|
||||||
|
command: ['run.sh']
|
||||||
`,
|
`,
|
||||||
dest: `
|
dest: `
|
||||||
|
apiVersion: apps/v1
|
||||||
kind: Deployment
|
kind: Deployment
|
||||||
items:
|
spec:
|
||||||
- name: foo
|
template:
|
||||||
image: foo:v0
|
spec:
|
||||||
|
containers:
|
||||||
|
- name: foo
|
||||||
|
image: foo:v0
|
||||||
`,
|
`,
|
||||||
expected: `
|
expected: `
|
||||||
|
apiVersion: apps/v1
|
||||||
kind: Deployment
|
kind: Deployment
|
||||||
items:
|
spec:
|
||||||
- name: foo
|
template:
|
||||||
image: foo:v1
|
spec:
|
||||||
command: ['run.sh']
|
containers:
|
||||||
|
- name: foo
|
||||||
|
image: foo:v1
|
||||||
|
command: ['run.sh']
|
||||||
`,
|
`,
|
||||||
},
|
},
|
||||||
|
|
||||||
{description: `merge Element -- add list, empty in dest`,
|
{description: `merge Element -- add list, empty in dest`,
|
||||||
source: `
|
source: `
|
||||||
|
apiVersion: apps/v1
|
||||||
kind: Deployment
|
kind: Deployment
|
||||||
items:
|
spec:
|
||||||
- name: foo
|
template:
|
||||||
image: foo:v1
|
spec:
|
||||||
command: ['run.sh']
|
containers:
|
||||||
|
- name: foo
|
||||||
|
image: foo:v1
|
||||||
|
command: ['run.sh']
|
||||||
`,
|
`,
|
||||||
dest: `
|
dest: `
|
||||||
|
apiVersion: apps/v1
|
||||||
kind: Deployment
|
kind: Deployment
|
||||||
items: []
|
spec:
|
||||||
|
template:
|
||||||
|
spec:
|
||||||
|
containers: []
|
||||||
`,
|
`,
|
||||||
expected: `
|
expected: `
|
||||||
|
apiVersion: apps/v1
|
||||||
kind: Deployment
|
kind: Deployment
|
||||||
items:
|
spec:
|
||||||
- name: foo
|
template:
|
||||||
image: foo:v1
|
spec:
|
||||||
command: ['run.sh']
|
containers:
|
||||||
|
- name: foo
|
||||||
|
image: foo:v1
|
||||||
|
command: ['run.sh']
|
||||||
`,
|
`,
|
||||||
},
|
},
|
||||||
|
|
||||||
{description: `merge Element -- add list, missing from dest`,
|
{description: `merge Element -- add list, missing from dest`,
|
||||||
source: `
|
source: `
|
||||||
|
apiVersion: apps/v1
|
||||||
kind: Deployment
|
kind: Deployment
|
||||||
items:
|
spec:
|
||||||
- name: foo
|
template:
|
||||||
image: foo:v1
|
spec:
|
||||||
command: ['run.sh']
|
containers:
|
||||||
|
- name: foo
|
||||||
|
image: foo:v1
|
||||||
|
command: ['run.sh']
|
||||||
`,
|
`,
|
||||||
dest: `
|
dest: `
|
||||||
|
apiVersion: apps/v1
|
||||||
kind: Deployment
|
kind: Deployment
|
||||||
`,
|
`,
|
||||||
expected: `
|
expected: `
|
||||||
|
apiVersion: apps/v1
|
||||||
kind: Deployment
|
kind: Deployment
|
||||||
items:
|
spec:
|
||||||
- name: foo
|
template:
|
||||||
image: foo:v1
|
spec:
|
||||||
command: ['run.sh']
|
containers:
|
||||||
|
- name: foo
|
||||||
|
image: foo:v1
|
||||||
|
command: ['run.sh']
|
||||||
`,
|
`,
|
||||||
},
|
},
|
||||||
|
|
||||||
{description: `merge Element -- add Element first`,
|
{description: `merge Element -- add Element first`,
|
||||||
source: `
|
source: `
|
||||||
|
apiVersion: apps/v1
|
||||||
kind: Deployment
|
kind: Deployment
|
||||||
items:
|
spec:
|
||||||
- name: bar
|
template:
|
||||||
image: bar:v1
|
spec:
|
||||||
command: ['run2.sh']
|
containers:
|
||||||
- name: foo
|
- name: bar
|
||||||
image: foo:v1
|
image: bar:v1
|
||||||
|
command: ['run2.sh']
|
||||||
|
- name: foo
|
||||||
|
image: foo:v1
|
||||||
`,
|
`,
|
||||||
dest: `
|
dest: `
|
||||||
|
apiVersion: apps/v1
|
||||||
kind: Deployment
|
kind: Deployment
|
||||||
items:
|
spec:
|
||||||
- name: foo
|
template:
|
||||||
image: foo:v0
|
spec:
|
||||||
|
containers:
|
||||||
|
- name: foo
|
||||||
|
image: foo:v0
|
||||||
`,
|
`,
|
||||||
expected: `
|
expected: `
|
||||||
|
apiVersion: apps/v1
|
||||||
kind: Deployment
|
kind: Deployment
|
||||||
items:
|
spec:
|
||||||
- name: foo
|
template:
|
||||||
image: foo:v1
|
spec:
|
||||||
- name: bar
|
containers:
|
||||||
image: bar:v1
|
- name: foo
|
||||||
command: ['run2.sh']
|
image: foo:v1
|
||||||
|
- name: bar
|
||||||
|
image: bar:v1
|
||||||
|
command: ['run2.sh']
|
||||||
`,
|
`,
|
||||||
},
|
},
|
||||||
|
|
||||||
{description: `merge Element -- add Element second`,
|
{description: `merge Element -- add Element second`,
|
||||||
source: `
|
source: `
|
||||||
|
apiVersion: apps/v1
|
||||||
kind: Deployment
|
kind: Deployment
|
||||||
items:
|
spec:
|
||||||
- name: foo
|
template:
|
||||||
image: foo:v1
|
spec:
|
||||||
- name: bar
|
containers:
|
||||||
image: bar:v1
|
- name: foo
|
||||||
command: ['run2.sh']
|
image: foo:v1
|
||||||
|
- name: bar
|
||||||
|
image: bar:v1
|
||||||
|
command: ['run2.sh']
|
||||||
`,
|
`,
|
||||||
dest: `
|
dest: `
|
||||||
|
apiVersion: apps/v1
|
||||||
kind: Deployment
|
kind: Deployment
|
||||||
items:
|
spec:
|
||||||
- name: foo
|
template:
|
||||||
image: foo:v0
|
spec:
|
||||||
|
containers:
|
||||||
|
- name: foo
|
||||||
|
image: foo:v0
|
||||||
`,
|
`,
|
||||||
expected: `
|
expected: `
|
||||||
|
apiVersion: apps/v1
|
||||||
kind: Deployment
|
kind: Deployment
|
||||||
items:
|
spec:
|
||||||
- name: foo
|
template:
|
||||||
image: foo:v1
|
spec:
|
||||||
- name: bar
|
containers:
|
||||||
image: bar:v1
|
- name: foo
|
||||||
command: ['run2.sh']
|
image: foo:v1
|
||||||
|
- name: bar
|
||||||
|
image: bar:v1
|
||||||
|
command: ['run2.sh']
|
||||||
`,
|
`,
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -150,25 +219,34 @@ items:
|
|||||||
//
|
//
|
||||||
{description: `keep list -- list missing from src`,
|
{description: `keep list -- list missing from src`,
|
||||||
source: `
|
source: `
|
||||||
|
apiVersion: apps/v1
|
||||||
kind: Deployment
|
kind: Deployment
|
||||||
`,
|
`,
|
||||||
dest: `
|
dest: `
|
||||||
|
apiVersion: apps/v1
|
||||||
kind: Deployment
|
kind: Deployment
|
||||||
items:
|
spec:
|
||||||
- name: foo
|
template:
|
||||||
image: foo:v1
|
spec:
|
||||||
- name: bar
|
containers:
|
||||||
image: bar:v1
|
- name: foo
|
||||||
command: ['run2.sh']
|
image: foo:v1
|
||||||
|
- name: bar
|
||||||
|
image: bar:v1
|
||||||
|
command: ['run2.sh']
|
||||||
`,
|
`,
|
||||||
expected: `
|
expected: `
|
||||||
|
apiVersion: apps/v1
|
||||||
kind: Deployment
|
kind: Deployment
|
||||||
items:
|
spec:
|
||||||
- name: foo
|
template:
|
||||||
image: foo:v1
|
spec:
|
||||||
- name: bar
|
containers:
|
||||||
image: bar:v1
|
- name: foo
|
||||||
command: ['run2.sh']
|
image: foo:v1
|
||||||
|
- name: bar
|
||||||
|
image: bar:v1
|
||||||
|
command: ['run2.sh']
|
||||||
`,
|
`,
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -177,28 +255,40 @@ items:
|
|||||||
//
|
//
|
||||||
{description: `keep Element -- element missing in src`,
|
{description: `keep Element -- element missing in src`,
|
||||||
source: `
|
source: `
|
||||||
|
apiVersion: apps/v1
|
||||||
kind: Deployment
|
kind: Deployment
|
||||||
items:
|
spec:
|
||||||
- name: foo
|
template:
|
||||||
image: foo:v1
|
spec:
|
||||||
|
containers:
|
||||||
|
- name: foo
|
||||||
|
image: foo:v1
|
||||||
`,
|
`,
|
||||||
dest: `
|
dest: `
|
||||||
|
apiVersion: apps/v1
|
||||||
kind: Deployment
|
kind: Deployment
|
||||||
items:
|
spec:
|
||||||
- name: foo
|
template:
|
||||||
image: foo:v0
|
spec:
|
||||||
- name: bar
|
containers:
|
||||||
image: bar:v1
|
- name: foo
|
||||||
command: ['run2.sh']
|
image: foo:v0
|
||||||
|
- name: bar
|
||||||
|
image: bar:v1
|
||||||
|
command: ['run2.sh']
|
||||||
`,
|
`,
|
||||||
expected: `
|
expected: `
|
||||||
|
apiVersion: apps/v1
|
||||||
kind: Deployment
|
kind: Deployment
|
||||||
items:
|
spec:
|
||||||
- name: foo
|
template:
|
||||||
image: foo:v1
|
spec:
|
||||||
- name: bar
|
containers:
|
||||||
image: bar:v1
|
- name: foo
|
||||||
command: ['run2.sh']
|
image: foo:v1
|
||||||
|
- name: bar
|
||||||
|
image: bar:v1
|
||||||
|
command: ['run2.sh']
|
||||||
`,
|
`,
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -207,26 +297,38 @@ items:
|
|||||||
//
|
//
|
||||||
{description: `keep element -- empty list in src`,
|
{description: `keep element -- empty list in src`,
|
||||||
source: `
|
source: `
|
||||||
|
apiVersion: apps/v1
|
||||||
kind: Deployment
|
kind: Deployment
|
||||||
items: {}
|
spec:
|
||||||
|
template:
|
||||||
|
spec:
|
||||||
|
containers: {}
|
||||||
`,
|
`,
|
||||||
dest: `
|
dest: `
|
||||||
|
apiVersion: apps/v1
|
||||||
kind: Deployment
|
kind: Deployment
|
||||||
items:
|
spec:
|
||||||
- name: foo
|
template:
|
||||||
image: foo:v1
|
spec:
|
||||||
- name: bar
|
containers:
|
||||||
image: bar:v1
|
- name: foo
|
||||||
command: ['run2.sh']
|
image: foo:v1
|
||||||
|
- name: bar
|
||||||
|
image: bar:v1
|
||||||
|
command: ['run2.sh']
|
||||||
`,
|
`,
|
||||||
expected: `
|
expected: `
|
||||||
|
apiVersion: apps/v1
|
||||||
kind: Deployment
|
kind: Deployment
|
||||||
items:
|
spec:
|
||||||
- name: foo
|
template:
|
||||||
image: foo:v1
|
spec:
|
||||||
- name: bar
|
containers:
|
||||||
image: bar:v1
|
- name: foo
|
||||||
command: ['run2.sh']
|
image: foo:v1
|
||||||
|
- name: bar
|
||||||
|
image: bar:v1
|
||||||
|
command: ['run2.sh']
|
||||||
`,
|
`,
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -235,46 +337,62 @@ items:
|
|||||||
//
|
//
|
||||||
{description: `remove Element -- null in src`,
|
{description: `remove Element -- null in src`,
|
||||||
source: `
|
source: `
|
||||||
|
apiVersion: apps/v1
|
||||||
kind: Deployment
|
kind: Deployment
|
||||||
items: null
|
spec:
|
||||||
|
template:
|
||||||
|
spec:
|
||||||
|
containers: null
|
||||||
`,
|
`,
|
||||||
dest: `
|
dest: `
|
||||||
|
apiVersion: apps/v1
|
||||||
kind: Deployment
|
kind: Deployment
|
||||||
items:
|
spec:
|
||||||
- name: foo
|
template:
|
||||||
image: foo:v1
|
spec:
|
||||||
- name: bar
|
containers:
|
||||||
image: bar:v1
|
- name: foo
|
||||||
command: ['run2.sh']
|
image: foo:v1
|
||||||
|
- name: bar
|
||||||
|
image: bar:v1
|
||||||
|
command: ['run2.sh']
|
||||||
`,
|
`,
|
||||||
expected: `
|
expected: `
|
||||||
|
apiVersion: apps/v1
|
||||||
kind: Deployment
|
kind: Deployment
|
||||||
|
spec:
|
||||||
|
template:
|
||||||
|
spec: {}
|
||||||
`,
|
`,
|
||||||
},
|
},
|
||||||
|
|
||||||
//
|
//
|
||||||
// Test Case
|
// Test Case
|
||||||
//
|
//
|
||||||
{description: `no infer merge keys no merge'`,
|
{description: `infer merge keys merge'`,
|
||||||
source: `
|
source: `
|
||||||
|
apiVersion: custom
|
||||||
kind: Deployment
|
kind: Deployment
|
||||||
containers:
|
containers:
|
||||||
- name: foo
|
- name: foo
|
||||||
command: ['run2.sh']
|
command: ['run2.sh']
|
||||||
`,
|
`,
|
||||||
dest: `
|
dest: `
|
||||||
|
apiVersion: custom
|
||||||
kind: Deployment
|
kind: Deployment
|
||||||
containers:
|
containers:
|
||||||
- name: foo
|
- name: foo
|
||||||
image: foo:bar
|
image: foo:bar
|
||||||
`,
|
`,
|
||||||
expected: `
|
expected: `
|
||||||
|
apiVersion: custom
|
||||||
kind: Deployment
|
kind: Deployment
|
||||||
containers:
|
containers:
|
||||||
- name: foo
|
- name: foo
|
||||||
|
image: foo:bar
|
||||||
command: ['run2.sh']
|
command: ['run2.sh']
|
||||||
`,
|
`,
|
||||||
noInfer: true,
|
infer: true,
|
||||||
},
|
},
|
||||||
|
|
||||||
//
|
//
|
||||||
@@ -282,8 +400,8 @@ containers:
|
|||||||
//
|
//
|
||||||
{description: `no infer merge keys merge using schema`,
|
{description: `no infer merge keys merge using schema`,
|
||||||
source: `
|
source: `
|
||||||
kind: Deployment
|
|
||||||
apiVersion: apps/v1
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
spec:
|
spec:
|
||||||
template:
|
template:
|
||||||
spec:
|
spec:
|
||||||
@@ -292,8 +410,8 @@ spec:
|
|||||||
command: ['run2.sh']
|
command: ['run2.sh']
|
||||||
`,
|
`,
|
||||||
dest: `
|
dest: `
|
||||||
kind: Deployment
|
|
||||||
apiVersion: apps/v1
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
spec:
|
spec:
|
||||||
template:
|
template:
|
||||||
spec:
|
spec:
|
||||||
@@ -302,8 +420,8 @@ spec:
|
|||||||
image: foo:bar
|
image: foo:bar
|
||||||
`,
|
`,
|
||||||
expected: `
|
expected: `
|
||||||
kind: Deployment
|
|
||||||
apiVersion: apps/v1
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
spec:
|
spec:
|
||||||
template:
|
template:
|
||||||
spec:
|
spec:
|
||||||
@@ -312,7 +430,7 @@ spec:
|
|||||||
image: foo:bar
|
image: foo:bar
|
||||||
command: ['run2.sh']
|
command: ['run2.sh']
|
||||||
`,
|
`,
|
||||||
noInfer: true,
|
infer: false,
|
||||||
},
|
},
|
||||||
|
|
||||||
//
|
//
|
||||||
@@ -320,24 +438,27 @@ spec:
|
|||||||
//
|
//
|
||||||
{description: `no infer merge keys merge using explicit schema as line comment'`,
|
{description: `no infer merge keys merge using explicit schema as line comment'`,
|
||||||
source: `
|
source: `
|
||||||
|
apiVersion: custom
|
||||||
kind: Deployment
|
kind: Deployment
|
||||||
containers:
|
containers:
|
||||||
- name: foo
|
- name: foo
|
||||||
command: ['run2.sh']
|
command: ['run2.sh']
|
||||||
`,
|
`,
|
||||||
dest: `
|
dest: `
|
||||||
|
apiVersion: custom
|
||||||
kind: Deployment
|
kind: Deployment
|
||||||
containers: # {"items":{"$ref": "#/definitions/io.k8s.api.core.v1.Container"},"type":"array","x-kubernetes-patch-merge-key":"name","x-kubernetes-patch-strategy": "merge"}
|
containers: # {"items":{"$ref": "#/definitions/io.k8s.api.core.v1.Container"},"type":"array","x-kubernetes-patch-merge-key":"name","x-kubernetes-patch-strategy": "merge"}
|
||||||
- name: foo # hell ow
|
- name: foo # hell ow
|
||||||
image: foo:bar
|
image: foo:bar
|
||||||
`,
|
`,
|
||||||
expected: `
|
expected: `
|
||||||
|
apiVersion: custom
|
||||||
kind: Deployment
|
kind: Deployment
|
||||||
containers: # {"items":{"$ref": "#/definitions/io.k8s.api.core.v1.Container"},"type":"array","x-kubernetes-patch-merge-key":"name","x-kubernetes-patch-strategy": "merge"}
|
containers: # {"items":{"$ref": "#/definitions/io.k8s.api.core.v1.Container"},"type":"array","x-kubernetes-patch-merge-key":"name","x-kubernetes-patch-strategy": "merge"}
|
||||||
- name: foo
|
- name: foo
|
||||||
image: foo:bar
|
image: foo:bar
|
||||||
command: ['run2.sh']
|
command: ['run2.sh']
|
||||||
`,
|
`,
|
||||||
noInfer: true,
|
infer: false,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ func TestMerge(t *testing.T) {
|
|||||||
for j := range testCases[i] {
|
for j := range testCases[i] {
|
||||||
tc := testCases[i][j]
|
tc := testCases[i][j]
|
||||||
t.Run(tc.description, func(t *testing.T) {
|
t.Run(tc.description, func(t *testing.T) {
|
||||||
actual, err := MergeStrings(tc.source, tc.dest, !tc.noInfer)
|
actual, err := MergeStrings(tc.source, tc.dest, tc.infer)
|
||||||
if !assert.NoError(t, err, tc.description) {
|
if !assert.NoError(t, err, tc.description) {
|
||||||
t.FailNow()
|
t.FailNow()
|
||||||
}
|
}
|
||||||
@@ -47,5 +47,5 @@ type testCase struct {
|
|||||||
source string
|
source string
|
||||||
dest string
|
dest string
|
||||||
expected string
|
expected string
|
||||||
noInfer bool
|
infer bool
|
||||||
}
|
}
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -18,7 +18,7 @@ func TestMerge(t *testing.T) {
|
|||||||
for j := range testCases[i] {
|
for j := range testCases[i] {
|
||||||
tc := testCases[i][j]
|
tc := testCases[i][j]
|
||||||
t.Run(tc.description, func(t *testing.T) {
|
t.Run(tc.description, func(t *testing.T) {
|
||||||
actual, err := MergeStrings(tc.local, tc.origin, tc.update, !tc.noInfer)
|
actual, err := MergeStrings(tc.local, tc.origin, tc.update, tc.infer)
|
||||||
if tc.err == nil {
|
if tc.err == nil {
|
||||||
if !assert.NoError(t, err, tc.description) {
|
if !assert.NoError(t, err, tc.description) {
|
||||||
t.FailNow()
|
t.FailNow()
|
||||||
@@ -47,5 +47,5 @@ type testCase struct {
|
|||||||
local string
|
local string
|
||||||
expected string
|
expected string
|
||||||
err error
|
err error
|
||||||
noInfer bool
|
infer bool
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user