MCPcopy Create free account
hub / github.com/couchbase/sync_gateway / TestRevTreeChannelMapLeafOnly

Function TestRevTreeChannelMapLeafOnly

db/revtree_test.go:383–421  ·  view source on GitHub ↗

TestRevTreeChannelMapLeafOnly ensures that only non-winning leaf revisions populate channel information from/to channelMap.

(t *testing.T)

Source from the content-addressed store, hash-verified

381
382// TestRevTreeChannelMapLeafOnly ensures that only non-winning leaf revisions populate channel information from/to channelMap.
383func TestRevTreeChannelMapLeafOnly(t *testing.T) {
384
385 // Add a 4th revision with channels to supersede rev 3-three
386 // ┌─────────────┐ ╔═══════════════════════╗
387 // ┌─│3-three (EN) │──║ 4-four (EN-us, EN-gb) ║
388 // ┌────────┐ ┌────────┐ │ └─────────────┘ ╚═══════════════════════╝
389 // │ 1-one │──│ 2-two │─┤
390 // └────────┘ └────────┘ │ ┌─────────────┐
391 // └─│ 3-drei (DE) │
392 // └─────────────┘
393 tree := branchymap.copy()
394
395 ri, err := tree.getInfo("3-three")
396 require.NoError(t, err)
397 // this wouldn't have been set normally (winning rev),
398 // but let's force it to ensure we're not storing old revs in ChannelsMap
399 ri.Channels = base.SetOf("EN")
400
401 err = tree.addRevision(t.Name(), RevInfo{
402 ID: "4-four",
403 Parent: "3-three",
404 Channels: nil, // we don't store channels for winning revs
405 })
406 require.NoError(t, err)
407
408 // insert channel into tree - we don't store it in the globals because each test requires different channel data.
409 ri, err = tree.getInfo("3-drei")
410 require.NoError(t, err)
411 ri.Channels = base.SetOf("DE")
412
413 // marshal RevTree into storage format
414 bytes, err := base.JSONMarshal(tree)
415 require.NoError(t, err)
416
417 // unmarshal back into revTreeList to ensure non-leaf channels are stripped on marshal for stored format
418 var storedMap revTreeList
419 require.NoError(t, base.JSONUnmarshal(bytes, &storedMap))
420 assert.Len(t, storedMap.ChannelsMap, 1, "expected only one channelsMap entry (for the non-winning leaf revisions)")
421}
422
423func TestRevTreeIsLeaf(t *testing.T) {
424 assert.True(t, branchymap.isLeaf("3-three"), "isLeaf failed on 3-three")

Callers

nothing calls this directly

Calls 8

SetOfFunction · 0.92
JSONMarshalFunction · 0.92
JSONUnmarshalFunction · 0.92
getInfoMethod · 0.80
addRevisionMethod · 0.80
NameMethod · 0.65
LenMethod · 0.65
copyMethod · 0.45

Tested by

no test coverage detected