Skip to content

Commit fc2115d

Browse files
committed
Add more tests
1 parent 4c421a8 commit fc2115d

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

patch_test.go

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,10 +184,29 @@ var _ = Describe("JSONPatch", func() {
184184
// add
185185
testPatchWithExpected([]int{1, 2, 3}, []int{1, 3}, []int{1, 3, 2}, jsonpatch.IgnoreSliceOrder())
186186
testPatchWithExpected([]int{1, 2, 3}, []int{1, 2}, []int{1, 2, 3}, jsonpatch.IgnoreSliceOrder())
187+
// no change
188+
testPatchWithExpected([]int{3, 2, 1}, []int{1, 2, 3}, []int{1, 2, 3}, jsonpatch.IgnoreSliceOrder())
189+
testPatchWithExpected([]int{1, 2, 3}, []int{3, 2, 1}, []int{3, 2, 1}, jsonpatch.IgnoreSliceOrder())
187190
// remove
188191
testPatchWithExpected([]int{3, 1}, []int{1, 2, 3}, []int{1, 3}, jsonpatch.IgnoreSliceOrder())
189192
testPatchWithExpected([]int{3, 2}, []int{1, 2, 3}, []int{2, 3}, jsonpatch.IgnoreSliceOrder())
190193
})
194+
It("uint slice ignore order", func() {
195+
// add
196+
testPatchWithExpected([]uint{1, 2, 3}, []uint{1, 3}, []uint{1, 3, 2}, jsonpatch.IgnoreSliceOrder())
197+
testPatchWithExpected([]uint16{1, 2, 3}, []uint16{1, 2}, []uint16{1, 2, 3}, jsonpatch.IgnoreSliceOrder())
198+
// remove
199+
testPatchWithExpected([]uint32{3, 1}, []uint32{1, 2, 3}, []uint32{1, 3}, jsonpatch.IgnoreSliceOrder())
200+
testPatchWithExpected([]uint64{3, 2}, []uint64{1, 2, 3}, []uint64{2, 3}, jsonpatch.IgnoreSliceOrder())
201+
})
202+
It("bool slice ignore order", func() {
203+
// add
204+
testPatchWithExpected([]bool{true, false}, []bool{false}, []bool{false, true}, jsonpatch.IgnoreSliceOrder())
205+
testPatchWithExpected([]bool{true, false}, []bool{true}, []bool{true, false}, jsonpatch.IgnoreSliceOrder())
206+
// remove
207+
testPatchWithExpected([]bool{true}, []bool{false, true}, []bool{true}, jsonpatch.IgnoreSliceOrder())
208+
testPatchWithExpected([]bool{true}, []bool{true, false}, []bool{true}, jsonpatch.IgnoreSliceOrder())
209+
})
191210
It("ptr slice ignore order", func() {
192211
// add
193212
testPatchWithExpected(D{PtrSliceWithKey: []*B{{Str: "key1"}}}, D{}, D{PtrSliceWithKey: []*B{{Str: "key1"}}}, jsonpatch.IgnoreSliceOrderWithPattern([]jsonpatch.IgnorePattern{{"/ptrWithKey", "str"}}))
@@ -381,13 +400,15 @@ func testPatch(modified, current interface{}) {
381400

382401
bytes, changes, err := jsonpatch.CreateJSONPatch(modified, current)
383402
Ω(err).ShouldNot(HaveOccurred())
384-
if string(bytes) == "" {
403+
if bytes.Empty() {
385404
Ω(currentJSON).Should(MatchJSON(modifiedJSON))
386405
Ω(changes).Should(Equal(0))
406+
Ω(bytes.String()).Should(Equal(""))
387407

388408
return
389409
}
390410

411+
Ω(bytes.String()).ShouldNot(Equal(""))
391412
jsonPatch, err := jsonpatch2.DecodePatch(bytes)
392413
Ω(err).ShouldNot(HaveOccurred())
393414
patchedJSON, err := jsonPatch.Apply(currentJSON)
@@ -405,13 +426,15 @@ func testPatchWithExpected(modified, current, expected interface{}, options ...j
405426

406427
bytes, changes, err := jsonpatch.CreateJSONPatch(modified, current, options...)
407428
Ω(err).ShouldNot(HaveOccurred())
408-
if string(bytes) == "" {
429+
if bytes.Empty() {
409430
Ω(currentJSON).Should(MatchJSON(expectedJSON))
410431
Ω(changes).Should(Equal(0))
432+
Ω(bytes.String()).Should(Equal(""))
411433

412434
return
413435
}
414436

437+
Ω(bytes.String()).ShouldNot(Equal(""))
415438
jsonPatch, err := jsonpatch2.DecodePatch(bytes)
416439
Ω(err).ShouldNot(HaveOccurred())
417440
patchedJSON, err := jsonPatch.Apply(currentJSON)

0 commit comments

Comments
 (0)