Skip to content

Commit 195ca47

Browse files
committed
Move RevTree channel info into tests
1 parent fa6d0ed commit 195ca47

File tree

1 file changed

+45
-10
lines changed

1 file changed

+45
-10
lines changed

db/revtree_test.go

Lines changed: 45 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import (
2929
// │ 1-one │──│ 2-two │──║3-three ║
3030
// └────────┘ └────────┘ ╚════════╝
3131
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"}`)},
3333
"2-two": {ID: "2-two", Parent: "1-one"},
3434
"1-one": {ID: "1-one"},
3535
}
@@ -44,10 +44,10 @@ var testmap = RevTree{
4444
// └─│ 3-drei │
4545
// └────────┘
4646
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)
4848
"2-two": {ID: "2-two", Parent: "1-one"},
4949
"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"},
5151
}
5252

5353
// multiroot is a revtree with multiple roots (disconnected branches)
@@ -226,17 +226,47 @@ func TestRevTreeUnmarshalOldFormat(t *testing.T) {
226226
"bodies": ["{\"foo\":\"bar\"}", "", ""],
227227
"channels": [["ABC", "CBS"], null, ["ABC"]]
228228
}`
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)
230237
}
231238

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) {
234240
// 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) {
235266
const testJSON = `{
236267
"revs": ["3-three", "2-two", "1-one"],
237268
"parents": [1, 2, -1],
238-
"bodymap": {"0":"{\"foo\":\"bar\"}"},
239-
"channelsMap": {"0": ["ABC", "CBS"]}
269+
"bodymap": {"0":"{\"foo\":\"bar\"}"}
240270
}`
241271
assertRevTreeUnmarshal(t, testJSON, testmap)
242272
}
@@ -355,18 +385,23 @@ func TestRevTreeChannelMapLeafOnly(t *testing.T) {
355385
// └────────┘ └────────┘ │ ┌─────────────┐
356386
// └─│ 3-drei (DE) │
357387
// └─────────────┘
358-
rev4Channels := base.SetOf("EN-us", "EN-gb")
359388
tree := branchymap.copy()
360389
err := tree.addRevision(t.Name(), RevInfo{
361390
ID: "4-four",
362391
Parent: "3-three",
363-
Channels: rev4Channels,
392+
Channels: base.SetOf("EN-us", "EN-gb"),
364393
})
365394
require.NoError(t, err)
366395

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+
367401
// marshal RevTree into storage format
368402
bytes, err := base.JSONMarshal(tree)
369403
require.NoError(t, err)
404+
370405
// unmarshal back into revTreeList to ensure non-leaf channels are stripped on marshal for stored format
371406
var storedMap revTreeList
372407
require.NoError(t, base.JSONUnmarshal(bytes, &storedMap))

0 commit comments

Comments
 (0)