mirror of
https://github.com/kyverno/kyverno.git
synced 2025-03-10 09:56:55 +00:00
Implemented checking of incoming request to correspond the policy rule, added tests. Implemented generation of JSON patches according to patches in policy object, added tests. Implemented base version of Mutate function as a wrapper for all mutation functions.
38 lines
1,010 B
Go
38 lines
1,010 B
Go
package webhooks_test
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
func assertEq(t *testing.T, expected interface{}, actual interface{}) {
|
|
if expected != actual {
|
|
t.Errorf("%s != %s", expected, actual)
|
|
}
|
|
}
|
|
|
|
func assertNe(t *testing.T, expected interface{}, actual interface{}) {
|
|
if expected == actual {
|
|
t.Errorf("%s != %s", expected, actual)
|
|
}
|
|
}
|
|
|
|
func assertEqDataImpl(t *testing.T, expected, actual []byte, formatModifier string) {
|
|
if len(expected) != len(actual) {
|
|
t.Errorf("len(expected) != len(actual): %d != %d\n1:"+formatModifier+"\n2:"+formatModifier, len(expected), len(actual), expected, actual)
|
|
return
|
|
}
|
|
|
|
for idx, val := range actual {
|
|
if val != expected[idx] {
|
|
t.Errorf("Slices not equal at index %d:\n1:"+formatModifier+"\n2:"+formatModifier, idx, expected, actual)
|
|
}
|
|
}
|
|
}
|
|
|
|
func assertEqData(t *testing.T, expected, actual []byte) {
|
|
assertEqDataImpl(t, expected, actual, "%x")
|
|
}
|
|
|
|
func assertEqStringAndData(t *testing.T, str string, data []byte) {
|
|
assertEqDataImpl(t, []byte(str), data, "%s")
|
|
}
|