mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-14 02:20:53 +00:00
add tests for *List kinds and empty lists
This commit is contained in:
@@ -42,6 +42,15 @@ func TestSliceFromBytes(t *testing.T) {
|
|||||||
testConfigMap.Map(),
|
testConfigMap.Map(),
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
testConfigMapList := factory.FromMap(
|
||||||
|
map[string]interface{}{
|
||||||
|
"apiVersion": "v1",
|
||||||
|
"kind": "ConfigMapList",
|
||||||
|
"items": []interface{}{
|
||||||
|
testConfigMap.Map(),
|
||||||
|
testConfigMap.Map(),
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
@@ -151,6 +160,24 @@ items:
|
|||||||
expectedOut: []ifc.Kunstructured{testList},
|
expectedOut: []ifc.Kunstructured{testList},
|
||||||
expectedErr: false,
|
expectedErr: false,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "ConfigMapList",
|
||||||
|
input: []byte(`
|
||||||
|
apiVersion: v1
|
||||||
|
kind: ConfigMapList
|
||||||
|
items:
|
||||||
|
- apiVersion: v1
|
||||||
|
kind: ConfigMap
|
||||||
|
metadata:
|
||||||
|
name: winnie
|
||||||
|
- apiVersion: v1
|
||||||
|
kind: ConfigMap
|
||||||
|
metadata:
|
||||||
|
name: winnie
|
||||||
|
`),
|
||||||
|
expectedOut: []ifc.Kunstructured{testConfigMapList},
|
||||||
|
expectedErr: false,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ items:
|
|||||||
patchList2 := patch.StrategicMerge("patch5.yaml")
|
patchList2 := patch.StrategicMerge("patch5.yaml")
|
||||||
patch5 := `
|
patch5 := `
|
||||||
apiVersion: v1
|
apiVersion: v1
|
||||||
kind: List
|
kind: DeploymentList
|
||||||
items:
|
items:
|
||||||
- apiVersion: apps/v1
|
- apiVersion: apps/v1
|
||||||
kind: Deployment
|
kind: Deployment
|
||||||
@@ -87,6 +87,12 @@ items:
|
|||||||
name: deployment-b
|
name: deployment-b
|
||||||
spec:
|
spec:
|
||||||
<<: *hostAliases
|
<<: *hostAliases
|
||||||
|
`
|
||||||
|
patchList3 := patch.StrategicMerge("patch6.yaml")
|
||||||
|
patch6 := `
|
||||||
|
apiVersion: v1
|
||||||
|
kind: List
|
||||||
|
items:
|
||||||
`
|
`
|
||||||
testDeploymentSpec := map[string]interface{}{
|
testDeploymentSpec := map[string]interface{}{
|
||||||
"template": map[string]interface{}{
|
"template": map[string]interface{}{
|
||||||
@@ -126,6 +132,7 @@ items:
|
|||||||
l.AddFile("/"+string(patchBad), []byte(patch3))
|
l.AddFile("/"+string(patchBad), []byte(patch3))
|
||||||
l.AddFile("/"+string(patchList), []byte(patch4))
|
l.AddFile("/"+string(patchList), []byte(patch4))
|
||||||
l.AddFile("/"+string(patchList2), []byte(patch5))
|
l.AddFile("/"+string(patchList2), []byte(patch5))
|
||||||
|
l.AddFile("/"+string(patchList3), []byte(patch6))
|
||||||
|
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
@@ -163,6 +170,12 @@ items:
|
|||||||
expectedOut: []*Resource{testDeploymentA, testDeploymentB},
|
expectedOut: []*Resource{testDeploymentA, testDeploymentB},
|
||||||
expectedErr: false,
|
expectedErr: false,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "listWithNoEntries",
|
||||||
|
input: []patch.StrategicMerge{patchList3},
|
||||||
|
expectedOut: []*Resource{},
|
||||||
|
expectedErr: false,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
rs, err := factory.SliceFromPatches(l, test.input)
|
rs, err := factory.SliceFromPatches(l, test.input)
|
||||||
|
|||||||
Reference in New Issue
Block a user