@@ -29,7 +29,7 @@ import (
29
29
// │ 1-one │──│ 2-two │──║3-three ║
30
30
// └────────┘ └────────┘ ╚════════╝
31
31
var testmap = RevTree {
32
- "3-three" : {ID : "3-three" , Parent : "2-two" , Body : []byte (`{"foo":"bar"}` ), Channels : base . SetOf ( "ABC" , "CBS" ) },
32
+ "3-three" : {ID : "3-three" , Parent : "2-two" , Body : []byte (`{"foo":"bar"}` )},
33
33
"2-two" : {ID : "2-two" , Parent : "1-one" },
34
34
"1-one" : {ID : "1-one" },
35
35
}
@@ -44,10 +44,10 @@ var testmap = RevTree{
44
44
// └─│ 3-drei │
45
45
// └────────┘
46
46
var branchymap = RevTree {
47
- "3-three" : {ID : "3-three" , Parent : "2-two" , Channels : base . SetOf ( "EN" ) }, // winner because higher ASCII value (d vs. t)
47
+ "3-three" : {ID : "3-three" , Parent : "2-two" }, // winner because higher ASCII value (d vs. t)
48
48
"2-two" : {ID : "2-two" , Parent : "1-one" },
49
49
"1-one" : {ID : "1-one" },
50
- "3-drei" : {ID : "3-drei" , Parent : "2-two" , Channels : base . SetOf ( "DE" ) },
50
+ "3-drei" : {ID : "3-drei" , Parent : "2-two" },
51
51
}
52
52
53
53
// multiroot is a revtree with multiple roots (disconnected branches)
@@ -226,17 +226,47 @@ func TestRevTreeUnmarshalOldFormat(t *testing.T) {
226
226
"bodies": ["{\"foo\":\"bar\"}", "", ""],
227
227
"channels": [["ABC", "CBS"], null, ["ABC"]]
228
228
}`
229
- assertRevTreeUnmarshal (t , testJSON , testmap )
229
+ tree := testmap .copy ()
230
+
231
+ // set desired channels
232
+ ri , err := tree .getInfo ("3-three" )
233
+ require .NoError (t , err )
234
+ ri .Channels = base .SetOf ("ABC" , "CBS" )
235
+
236
+ assertRevTreeUnmarshal (t , testJSON , tree )
230
237
}
231
238
232
- func TestRevTreeUnmarshal (t * testing.T ) {
233
- // 'channels' is an old revtree property that stored channel history for previous revisions.
239
+ func TestRevTreeUnmarshalChannelMap (t * testing.T ) {
234
240
// we moved non-winning leaf revision channel information into a 'channelMap' property instead to handle the case where documents are in conflict.
241
+ const testJSON = `{
242
+ "revs": ["3-drei", "3-three", "2-two", "1-one"],
243
+ "parents": [2, 2, 3, -1],
244
+ "bodies": ["{\"foo\":\"buzz\"}", "{\"foo\":\"bar\"}", "", ""],
245
+ "channels": [["DE"], ["EN"], null, ["ABC"]]
246
+ }`
247
+ tree := testmap .copy ()
248
+
249
+ // set desired channels
250
+ ri , err := tree .getInfo ("3-three" )
251
+ require .NoError (t , err )
252
+ ri .Channels = base .SetOf ("EN" )
253
+
254
+ err = tree .addRevision ("" , RevInfo {
255
+ ID : "3-drei" ,
256
+ Parent : "2-two" ,
257
+ Body : []byte (`{"foo":"buzz"}` ),
258
+ Channels : base .SetOf ("DE" ),
259
+ })
260
+ require .NoError (t , err )
261
+
262
+ assertRevTreeUnmarshal (t , testJSON , tree )
263
+ }
264
+
265
+ func TestRevTreeUnmarshal (t * testing.T ) {
235
266
const testJSON = `{
236
267
"revs": ["3-three", "2-two", "1-one"],
237
268
"parents": [1, 2, -1],
238
- "bodymap": {"0":"{\"foo\":\"bar\"}"},
239
- "channelsMap": {"0": ["ABC", "CBS"]}
269
+ "bodymap": {"0":"{\"foo\":\"bar\"}"}
240
270
}`
241
271
assertRevTreeUnmarshal (t , testJSON , testmap )
242
272
}
@@ -355,18 +385,23 @@ func TestRevTreeChannelMapLeafOnly(t *testing.T) {
355
385
// └────────┘ └────────┘ │ ┌─────────────┐
356
386
// └─│ 3-drei (DE) │
357
387
// └─────────────┘
358
- rev4Channels := base .SetOf ("EN-us" , "EN-gb" )
359
388
tree := branchymap .copy ()
360
389
err := tree .addRevision (t .Name (), RevInfo {
361
390
ID : "4-four" ,
362
391
Parent : "3-three" ,
363
- Channels : rev4Channels ,
392
+ Channels : base . SetOf ( "EN-us" , "EN-gb" ) ,
364
393
})
365
394
require .NoError (t , err )
366
395
396
+ // insert channel into tree - we don't store it in the globals because each test requires different channel data.
397
+ ri , err := tree .getInfo ("3-drei" )
398
+ require .NoError (t , err )
399
+ ri .Channels = base .SetOf ("DE" )
400
+
367
401
// marshal RevTree into storage format
368
402
bytes , err := base .JSONMarshal (tree )
369
403
require .NoError (t , err )
404
+
370
405
// unmarshal back into revTreeList to ensure non-leaf channels are stripped on marshal for stored format
371
406
var storedMap revTreeList
372
407
require .NoError (t , base .JSONUnmarshal (bytes , & storedMap ))
0 commit comments