1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2025-03-31 03:45:17 +00:00

Added real test for adding anchor

This commit is contained in:
Denis Belyshev 2019-06-18 15:02:41 +03:00
parent faf1309a55
commit 41a932bc10

View file

@ -477,31 +477,62 @@ func TestApplyOverlay_AddingAnchor(t *testing.T) {
func TestApplyOverlay_AddingAnchorInsideListElement(t *testing.T) {
overlayRaw := []byte(`
{
"list" : [
{
"(entity)": "*able",
"+(event)": "process"
"spec": {
"template": {
"spec": {
"containers": [
{
"(image)": "*:latest",
"+(imagePullPolicy)": "IfNotPresent"
}
]
}
}
]
}
}`)
resourceRaw := []byte(`
{
"list" : [
{
"entity": "movable"
},
{
"entity": "collisionable",
"event": "skip"
},
{
"entity": "any",
"event": "delete"
},
{
"entity": "none"
{
"apiVersion":"apps/v1",
"kind":"Deployment",
"metadata":{
"name":"nginx-deployment",
"labels":{
"app":"nginx"
}
]
},
"spec":{
"replicas":1,
"selector":{
"matchLabels":{
"app":"nginx"
}
},
"template":{
"metadata":{
"labels":{
"app":"nginx"
}
},
"spec":{
"containers":[
{
"image":"nginx:latest"
},
{
"image":"ghost:latest",
"imagePullPolicy":"Always"
},
{
"image":"debian:10"
},
{
"image":"ubuntu:18.04",
"imagePullPolicy":"Always"
}
]
}
}
}
}`)
var resource, overlay interface{}
@ -516,25 +547,49 @@ func TestApplyOverlay_AddingAnchorInsideListElement(t *testing.T) {
doc, err := ApplyPatches(resourceRaw, patches)
assert.NilError(t, err)
expectedResult := []byte(`
{
"list":[
{
"entity":"movable",
"event":"process"
},
{
"entity":"collisionable",
"event":"skip"
},
{
"entity":"any",
"event":"delete"
},
{
"entity":"none"
}
]
}`)
{
"apiVersion":"apps/v1",
"kind":"Deployment",
"metadata":{
"name":"nginx-deployment",
"labels":{
"app":"nginx"
}
},
"spec":{
"replicas":1,
"selector":{
"matchLabels":{
"app":"nginx"
}
},
"template":{
"metadata":{
"labels":{
"app":"nginx"
}
},
"spec":{
"containers":[
{
"image":"nginx:latest",
"imagePullPolicy":"IfNotPresent"
},
{
"image":"ghost:latest",
"imagePullPolicy":"Always"
},
{
"image":"debian:10"
},
{
"image":"ubuntu:18.04",
"imagePullPolicy":"Always"
}
]
}
}
}
}`)
compareJsonAsMap(t, expectedResult, doc)
}