forked from mattbaird/jsonpatch
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjsonpatch_array_at_root_test.go
More file actions
64 lines (57 loc) · 1.2 KB
/
Copy pathjsonpatch_array_at_root_test.go
File metadata and controls
64 lines (57 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package jsonpatch
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestJSONPatchCreate_ObjectRoot(t *testing.T) {
cases := map[string]struct {
a string
b string
}{
"object": {
`{"asdf":"qwerty"}`,
`{"asdf":"zzz"}`,
},
"object with array": {
`{"items":[{"asdf":"qwerty"}]}`,
`{"items":[{"asdf":"bla"},{"asdf":"zzz"}]}`,
},
}
collections := Collections{
Arrays: []Path{"$.items"},
}
for name, tc := range cases {
t.Run(name, func(t *testing.T) {
_, err := CreatePatch([]byte(tc.a), []byte(tc.b), collections, nil, PatchStrategyExactMatch)
assert.NoError(t, err)
})
}
}
func TestJSONPatchCreate_ArrayRoot(t *testing.T) {
cases := map[string]struct {
a string
b string
}{
"array": {
`[{"asdf":"qwerty"}]`,
`[{"asdf":"bla"},{"asdf":"zzz"}]`,
},
"from empty array": {
`[]`,
`[{"asdf":"bla"},{"asdf":"zzz"}]`,
},
"to empty array": {
`[{"asdf":"bla"},{"asdf":"zzz"}]`,
`[]`,
},
}
collections := Collections{
Arrays: []Path{"$"},
}
for name, tc := range cases {
t.Run(name, func(t *testing.T) {
_, err := CreatePatch([]byte(tc.a), []byte(tc.b), collections, nil, PatchStrategyExactMatch)
assert.NoError(t, err)
})
}
}