1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2025-03-06 07:57:07 +00:00
kyverno/pkg/background/generate/validate_test.go
Prateek Pandey 9def86c49a
refactor generate controller (#3589)
* refact generate controller

Signed-off-by: prateekpandey14 <prateek.pandey@nirmata.com>

* rename the dir to background

Signed-off-by: prateekpandey14 <prateek.pandey@nirmata.com>
2022-04-13 12:45:04 +00:00

82 lines
1.6 KiB
Go

package generate
import (
"testing"
"github.com/go-logr/logr"
"gotest.tools/assert"
)
func TestValidatePass(t *testing.T) {
resource := map[string]interface{}{
"spec": map[string]interface{}{
"egress": map[string]interface{}{
"port": []interface{}{
map[string]interface{}{
"port": 5353,
"protocol": "UDP",
},
map[string]interface{}{
"port": 5353,
"protocol": "TCP",
},
},
},
},
}
pattern := map[string]interface{}{
"spec": map[string]interface{}{
"egress": map[string]interface{}{
"port": []interface{}{
map[string]interface{}{
"port": 5353,
"protocol": "UDP",
},
map[string]interface{}{
"port": 5353,
"protocol": "TCP",
},
},
},
},
}
var log logr.Logger
_, err := ValidateResourceWithPattern(log, resource, pattern)
assert.NilError(t, err)
}
func TestValidateFail(t *testing.T) {
resource := map[string]interface{}{
"spec": map[string]interface{}{
"egress": map[string]interface{}{
"port": []interface{}{
map[string]interface{}{
"port": 5353,
"protocol": "TCP",
},
},
},
},
}
pattern := map[string]interface{}{
"spec": map[string]interface{}{
"egress": map[string]interface{}{
"port": []interface{}{
map[string]interface{}{
"port": 5353,
"protocol": "UDP",
},
map[string]interface{}{
"port": 5353,
"protocol": "TCP",
},
},
},
},
}
var log logr.Logger
_, err := ValidateResourceWithPattern(log, resource, pattern)
assert.Assert(t, err != nil)
}