1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2025-03-06 16:06:56 +00:00
kyverno/pkg/background/generate/validate_test.go

83 lines
1.6 KiB
Go
Raw Normal View History

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)
}