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

Function TestAlignRevTreeHistory

db/document_test.go:677–774  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

675}
676
677func TestAlignRevTreeHistory(t *testing.T) {
678 testCases := []struct {
679 name string
680 currentRev string
681 expectedActive string
682 expectedTombstone string
683 localRevTree []string
684 incomingRevTree []string
685 expectedRevTree []string
686 }{
687 {
688 name: "common history between the two",
689 currentRev: "2-abc",
690 localRevTree: []string{"2-abc", "1-abc"},
691 incomingRevTree: []string{"5-abc", "4-abc", "3-abc", "2-abc", "1-abc"},
692 expectedRevTree: []string{"5-abc", "4-abc", "3-abc", "2-abc", "1-abc"},
693 expectedActive: "5-abc",
694 },
695 {
696 name: "gap in histories, incoming larger",
697 currentRev: "3-abc",
698 localRevTree: []string{"1-abc", "2-abc", "3-abc"},
699 incomingRevTree: []string{"12-abc", "10-abc", "11-abc"},
700 // rev 4- is new rev created for tombstone here, 12-abc is the active rev
701 expectedRevTree: []string{"12-abc", "10-abc", "11-abc", "4-cc0337d9d38c8e5fc930ae3deda62bf8", "3-abc", "2-abc", "1-abc"},
702 expectedActive: "12-abc",
703 expectedTombstone: "4-cc0337d9d38c8e5fc930ae3deda62bf8",
704 },
705 {
706 name: "gap in histories, local larger",
707 currentRev: "12-abc",
708 localRevTree: []string{"12-abc", "11-abc", "10-abc"},
709 incomingRevTree: []string{"3-abc", "2-abc", "1-abc"},
710 expectedRevTree: []string{"3-abc", "2-abc", "1-abc", "13-8db1e1e49db43d4c2fff25a6a4815c92", "12-abc", "11-abc", "10-abc"},
711 // rev 13- is new rev created for tombstone here, 3-abc is the active rev
712 expectedActive: "3-abc",
713 expectedTombstone: "13-8db1e1e49db43d4c2fff25a6a4815c92",
714 },
715 {
716 name: "no common history, one generation above",
717 currentRev: "3-abc",
718 localRevTree: []string{"3-abc", "2-abc", "1-abc"},
719 incomingRevTree: []string{"5-abc", "4-abc"},
720 expectedRevTree: []string{"5-abc", "4-abc", "4-cc0337d9d38c8e5fc930ae3deda62bf8", "3-abc", "2-abc", "1-abc"},
721 // active rev will be 5-abc with 4-cc0337d9d38c8e5fc930ae3deda62bf8 as tombstone
722 expectedActive: "5-abc",
723 expectedTombstone: "4-cc0337d9d38c8e5fc930ae3deda62bf8",
724 },
725 {
726 name: "one common rev between the two",
727 currentRev: "4-abc",
728 localRevTree: []string{"4-abc", "3-abc", "2-abc", "1-abc"},
729 incomingRevTree: []string{"5-abc", "4-abc"},
730 expectedRevTree: []string{"5-abc", "4-abc", "3-abc", "2-abc", "1-abc"},
731 // no tombstone, active rev will be 5-abc
732 expectedActive: "5-abc",
733 },
734 {

Callers

nothing calls this directly

Calls 11

RequireKeysEqualFunction · 0.92
setupTestDBFunction · 0.85
NewDocumentFunction · 0.85
SetRevTreeIDMethod · 0.80
addRevisionMethod · 0.80
RunMethod · 0.65
CloseMethod · 0.65
EqualMethod · 0.45
GetRevTreeIDMethod · 0.45

Tested by

no test coverage detected