1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2025-03-10 09:56:55 +00:00
kyverno/pkg/utils/json/utils_test.go
Jim Bugwadia 531355adce
Release 1.7 (#4200)
* cherry-pick fix attestation checks https://github.com/kyverno/kyverno/pull/3999

Signed-off-by: Jim Bugwadia <jim@nirmata.com>

* remove TUF initialization from main (#4098)

Signed-off-by: Jim Bugwadia <jim@nirmata.com>

* fix imageVerify validation checks and conversion logic (#4038)

Signed-off-by: Jim Bugwadia <jim@nirmata.com>

Co-authored-by: Vyankatesh Kudtarkar <vyankateshkd@gmail.com>

* release event memory (#4138)

Signed-off-by: Jim Bugwadia <jim@nirmata.com>

Co-authored-by: Vyankatesh Kudtarkar <vyankateshkd@gmail.com>

* fix merge of image verify and mutate patches

Signed-off-by: Jim Bugwadia <jim@nirmata.com>

* fix patch join

Signed-off-by: Jim Bugwadia <jim@nirmata.com>

* handle embedded strings with spaces

Signed-off-by: Jim Bugwadia <jim@nirmata.com>

Co-authored-by: Prateek Pandey <prateek.pandey@nirmata.com>
Co-authored-by: Vyankatesh Kudtarkar <vyankateshkd@gmail.com>
2022-07-10 20:00:00 -07:00

49 lines
1.6 KiB
Go

package json
import (
"testing"
jsonpatch "github.com/evanphx/json-patch"
"gotest.tools/assert"
)
func Test_JoinPatches(t *testing.T) {
patches := JoinPatches()
assert.Assert(t, patches == nil, "invalid patch %#v", string(patches))
patches = JoinPatches([]byte(""))
assert.Assert(t, patches == nil, "invalid patch %#v", string(patches))
patches = JoinPatches([]byte(""), []byte(""), []byte(""), []byte(""))
assert.Assert(t, patches == nil, "invalid patch %#v", string(patches))
p1 := `{ "op": "replace", "path": "/baz", "value": "boo" }`
p2 := `{ "op": "add", "path": "/hello", "value": ["world"] }`
p1p2 := `[
{ "op": "replace", "path": "/baz", "value": "boo" },
{ "op": "add", "path": "/hello", "value": ["world"] }
]`
patches = JoinPatches([]byte(p1), []byte(p2))
_, err := jsonpatch.DecodePatch(patches)
assert.NilError(t, err, "failed to decode patch %s", string(patches))
if !jsonpatch.Equal([]byte(p1p2), patches) {
assert.Assert(t, false, "patches are not equal")
}
p3 := `{ "op": "remove", "path": "/foo" }`
p1p2p3 := `[
{ "op": "replace", "path": "/baz", "value": "boo" },
{ "op": "add", "path": "/hello", "value": ["world"] },
{ "op": "remove", "path": "/foo" }
]`
patches = JoinPatches([]byte(p1p2), []byte(p3))
assert.NilError(t, err, "failed to join patches %s", string(patches))
_, err = jsonpatch.DecodePatch(patches)
assert.NilError(t, err, "failed to decode patch %s", string(patches))
if !jsonpatch.Equal([]byte(p1p2p3), patches) {
assert.Assert(t, false, "patches are not equal %+v %+v", p1p2p3, string(patches))
}
}