@@ -55,22 +55,29 @@ type E struct {
55
55
}
56
56
57
57
type F struct {
58
+ Str string `json:"a~bc//2a"`
59
+ Int int `json:"a/b"`
60
+ Bool bool `json:"x~~e"`
61
+ }
62
+
63
+ type G struct {
58
64
A * A `json:"a"`
59
65
B * B `json:"b,omitempty"`
60
66
C C `json:"c"`
61
67
D D `json:"d"`
62
68
E E `json:"e"`
63
- }
64
-
65
- type G struct {
66
- I interface {} `json:"i"`
69
+ F F `json:"f"`
67
70
}
68
71
69
72
type H struct {
70
73
Ignored string `json:"_"`
71
74
NotIgnored string `json:"notIgnored"`
72
75
}
73
76
77
+ type I struct {
78
+ I interface {} `json:"i"`
79
+ }
80
+
74
81
var _ = Describe ("JSONPatch" , func () {
75
82
Context ("CreateJsonPatch_pointer_values" , func () {
76
83
It ("pointer" , func () {
@@ -237,18 +244,28 @@ var _ = Describe("JSONPatch", func() {
237
244
testPatchWithExpected (D {StructSliceWithKey : []C {{Str : "key2" , Map : map [string ]string {"key" : "value" }}, {Str : "key3" }}}, D {StructSliceWithKey : []C {{Str : "key2" , Map : map [string ]string {"key" : "value" }}, {Str : "key3" }}}, D {StructSliceWithKey : []C {{Str : "key2" , Map : map [string ]string {"key" : "value" }}, {Str : "key3" }}}, jsonpatch .IgnoreSliceOrderWithPattern ([]jsonpatch.IgnorePattern {{"/structsWithKey" , "str" }}))
238
245
})
239
246
})
247
+ Context ("CreateJsonPatch_escape_pointer" , func () {
248
+ It ("separator" , func () {
249
+ // add
250
+ testPatch (F {"value2" , 2 , false }, F {})
251
+ // replace
252
+ testPatch (F {"value1" , 1 , true }, F {"value2" , 2 , false })
253
+ // no change
254
+ testPatch (F {"value1" , 1 , true }, F {"value1" , 1 , true })
255
+ })
256
+ })
240
257
Context ("CreateJsonPatch_interface" , func () {
241
258
It ("int" , func () {
242
259
// replace
243
- testPatch (G {2 }, G {3 })
260
+ testPatch (I {2 }, I {3 })
244
261
// no change
245
- testPatch (G {2 }, G {2 })
262
+ testPatch (I {2 }, I {2 })
246
263
})
247
264
It ("string" , func () {
248
265
// replace
249
- testPatch (G {"value1" }, G {"value2" })
266
+ testPatch (I {"value1" }, I {"value2" })
250
267
// no change
251
- testPatch (G {"value1" }, G {"value1" })
268
+ testPatch (I {"value1" }, I {"value1" })
252
269
})
253
270
})
254
271
Context ("CreateJsonPatch_ignore" , func () {
@@ -302,34 +319,34 @@ var _ = Describe("JSONPatch", func() {
302
319
})
303
320
It ("predicate_add" , func () {
304
321
// add
305
- testPatchWithExpected (F {B : & B {Bool : true , Str : "str" }}, F {}, F {B : & B {Bool : true , Str : "str" }}, jsonpatch .WithPredicate (predicate ))
306
- testPatchWithExpected (F {B : & B {Int : 7 , Str : "str" }}, F {}, F {B : & B {Int : 7 , Str : "str" }}, jsonpatch .WithPredicate (predicate ))
322
+ testPatchWithExpected (G {B : & B {Bool : true , Str : "str" }}, G {}, G {B : & B {Bool : true , Str : "str" }}, jsonpatch .WithPredicate (predicate ))
323
+ testPatchWithExpected (G {B : & B {Int : 7 , Str : "str" }}, G {}, G {B : & B {Int : 7 , Str : "str" }}, jsonpatch .WithPredicate (predicate ))
307
324
// don't add
308
- testPatchWithExpected (F {B : & B {Bool : false , Str : "str" }, C : C {Map : map [string ]string {"key" : "value" }}}, F {}, F {C : C {Map : map [string ]string {"key" : "value" }}}, jsonpatch .WithPredicate (predicate ))
309
- testPatchWithExpected (F {B : & B {Int : 0 , Str : "str" }, C : C {Map : map [string ]string {"key" : "value" }}}, F {}, F {C : C {Map : map [string ]string {"key" : "value" }}}, jsonpatch .WithPredicate (predicate ))
325
+ testPatchWithExpected (G {B : & B {Bool : false , Str : "str" }, C : C {Map : map [string ]string {"key" : "value" }}}, G {}, G {C : C {Map : map [string ]string {"key" : "value" }}}, jsonpatch .WithPredicate (predicate ))
326
+ testPatchWithExpected (G {B : & B {Int : 0 , Str : "str" }, C : C {Map : map [string ]string {"key" : "value" }}}, G {}, G {C : C {Map : map [string ]string {"key" : "value" }}}, jsonpatch .WithPredicate (predicate ))
310
327
})
311
328
It ("predicate_replace" , func () {
312
329
// replace
313
- testPatchWithExpected (F {C : C {Str : "new" , Map : map [string ]string {"key" : "value" }}}, F {C : C {Str : "old" }}, F {C : C {Str : "new" , Map : map [string ]string {"key" : "value" }}}, jsonpatch .WithPredicate (predicate ))
330
+ testPatchWithExpected (G {C : C {Str : "new" , Map : map [string ]string {"key" : "value" }}}, G {C : C {Str : "old" }}, G {C : C {Str : "new" , Map : map [string ]string {"key" : "value" }}}, jsonpatch .WithPredicate (predicate ))
314
331
// don't replace
315
- testPatchWithExpected (F {C : C {Str : "new" }}, F {C : C {Str : "old" , Map : map [string ]string {"key" : "value" }}}, F {C : C {Str : "old" , Map : map [string ]string {"key" : "value" }}}, jsonpatch .WithPredicate (predicate ))
332
+ testPatchWithExpected (G {C : C {Str : "new" }}, G {C : C {Str : "old" , Map : map [string ]string {"key" : "value" }}}, G {C : C {Str : "old" , Map : map [string ]string {"key" : "value" }}}, jsonpatch .WithPredicate (predicate ))
316
333
})
317
334
It ("predicate_remove" , func () {
318
335
// remove
319
- testPatchWithExpected (F {}, F {B : & B {Str : "remove me" }}, F {B : nil }, jsonpatch .WithPredicate (predicate ))
336
+ testPatchWithExpected (G {}, G {B : & B {Str : "remove me" }}, G {B : nil }, jsonpatch .WithPredicate (predicate ))
320
337
// don't remove
321
- testPatchWithExpected (F {}, F {B : & B {Str : "don't remove me" }}, F {B : & B {Str : "don't remove me" }}, jsonpatch .WithPredicate (predicate ))
338
+ testPatchWithExpected (G {}, G {B : & B {Str : "don't remove me" }}, G {B : & B {Str : "don't remove me" }}, jsonpatch .WithPredicate (predicate ))
322
339
})
323
340
})
324
341
Context ("CreateJsonPatch_with_prefix" , func () {
325
342
It ("empty prefix" , func () {
326
- testPatchWithExpected (F {B : & B {Bool : true , Str : "str" }}, F {}, F {B : & B {Bool : true , Str : "str" }}, jsonpatch .WithPrefix ([]string {"" }))
343
+ testPatchWithExpected (G {B : & B {Bool : true , Str : "str" }}, G {}, G {B : & B {Bool : true , Str : "str" }}, jsonpatch .WithPrefix ([]string {"" }))
327
344
})
328
345
It ("pointer prefix" , func () {
329
346
prefix := "/a/ptr"
330
- modified := F {A : & A {B : & B {Bool : true , Str : "str" }}}
331
- current := F {A : & A {}}
332
- expected := F {A : & A {B : & B {Bool : true , Str : "str" }}}
347
+ modified := G {A : & A {B : & B {Bool : true , Str : "str" }}}
348
+ current := G {A : & A {}}
349
+ expected := G {A : & A {B : & B {Bool : true , Str : "str" }}}
333
350
334
351
currentJSON , err := json .Marshal (current )
335
352
Ω (err ).ShouldNot (HaveOccurred ())
@@ -350,9 +367,9 @@ var _ = Describe("JSONPatch", func() {
350
367
})
351
368
It ("string prefix" , func () {
352
369
prefix := []string {"b" }
353
- modified := F {B : & B {Bool : true , Str : "str" }}
354
- current := F {}
355
- expected := F {B : & B {Bool : true , Str : "str" }}
370
+ modified := G {B : & B {Bool : true , Str : "str" }}
371
+ current := G {}
372
+ expected := G {B : & B {Bool : true , Str : "str" }}
356
373
357
374
currentJSON , err := json .Marshal (current )
358
375
Ω (err ).ShouldNot (HaveOccurred ())
@@ -378,15 +395,15 @@ var _ = Describe("JSONPatch", func() {
378
395
Ω (err ).Should (HaveOccurred ())
379
396
})
380
397
It ("not matching interface types" , func () {
381
- _ , err := jsonpatch .CreateJSONPatch (G {1 }, G {"str" })
398
+ _ , err := jsonpatch .CreateJSONPatch (I {1 }, I {"str" })
382
399
Ω (err ).Should (HaveOccurred ())
383
400
})
384
401
It ("invalid map (map[string]int)" , func () {
385
- _ , err := jsonpatch .CreateJSONPatch (G {map [string ]int {"key" : 2 }}, G {map [string ]int {"key" : 3 }})
402
+ _ , err := jsonpatch .CreateJSONPatch (I {map [string ]int {"key" : 2 }}, I {map [string ]int {"key" : 3 }})
386
403
Ω (err ).Should (HaveOccurred ())
387
404
})
388
405
It ("invalid map (map[int]string)" , func () {
389
- _ , err := jsonpatch .CreateJSONPatch (G {map [int ]string {1 : "value" }}, G {map [int ]string {2 : "value" }})
406
+ _ , err := jsonpatch .CreateJSONPatch (I {map [int ]string {1 : "value" }}, I {map [int ]string {2 : "value" }})
390
407
Ω (err ).Should (HaveOccurred ())
391
408
})
392
409
It ("ignore slice order failed (duplicated key)" , func () {
@@ -398,15 +415,15 @@ var _ = Describe("JSONPatch", func() {
398
415
})
399
416
Context ("CreateJsonPatch_fuzzy" , func () {
400
417
var (
401
- current F
402
- modified F
418
+ current G
419
+ modified G
403
420
)
404
421
BeforeEach (func () {
405
- current = F {}
422
+ current = G {}
406
423
err := faker .FakeData (& current )
407
424
Ω (err ).ShouldNot (HaveOccurred ())
408
425
409
- modified = F {}
426
+ modified = G {}
410
427
err = faker .FakeData (& modified )
411
428
Ω (err ).ShouldNot (HaveOccurred ())
412
429
})
0 commit comments