mirror of
https://github.com/kyverno/kyverno.git
synced 2025-03-06 07:57:07 +00:00
* refact generate controller Signed-off-by: prateekpandey14 <prateek.pandey@nirmata.com> * rename the dir to background Signed-off-by: prateekpandey14 <prateek.pandey@nirmata.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)
|
|
}
|