mirror of
https://github.com/kyverno/kyverno.git
synced 2025-03-06 16:06:56 +00:00
* added validate logic for generate Signed-off-by: NoSkillGirl <singhpooja240393@gmail.com> * format fix Signed-off-by: NoSkillGirl <singhpooja240393@gmail.com> * gofmt fix Signed-off-by: NoSkillGirl <singhpooja240393@gmail.com> * added test cases Signed-off-by: NoSkillGirl <singhpooja240393@gmail.com>
82 lines
1.6 KiB
Go
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)
|
|
}
|