summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJay Doane <jaydoane@apache.org>2020-02-20 15:09:49 -0800
committerNick Vatamaniuc <nickva@users.noreply.github.com>2020-02-24 18:01:49 -0500
commit2c12d81427a6a3369e40ac3d3e9c05439b65f2bd (patch)
tree650f06ca9e49c52f25fe92652900007fe03414f4
parentae4abe8f2b6dd23771ca1412caf2e53b1763990c (diff)
downloadcouchdb-2c12d81427a6a3369e40ac3d3e9c05439b65f2bd.tar.gz
Add fdb_to_revinfo version compatibility unit test
This test adds coverage for the 4 fdb_to_revinfo compatibility clauses, and will help ensure any additional future clauses will not break backwards compatibility. Module coverage without this test: fabric2_fdb : 92% Module coverage with this test: fabric2_fdb : 94%
-rw-r--r--src/fabric/src/fabric2_fdb.erl44
1 files changed, 44 insertions, 0 deletions
diff --git a/src/fabric/src/fabric2_fdb.erl b/src/fabric/src/fabric2_fdb.erl
index ed4371a55..c34b33cbc 100644
--- a/src/fabric/src/fabric2_fdb.erl
+++ b/src/fabric/src/fabric2_fdb.erl
@@ -1746,3 +1746,47 @@ with_span(Operation, ExtraTags, Fun) ->
false ->
Fun()
end.
+
+
+-ifdef(TEST).
+-include_lib("eunit/include/eunit.hrl").
+
+fdb_to_revinfo_version_compatibility_test() ->
+ DocId = <<"doc_id">>,
+ FirstRevFormat = 0,
+ RevPos = 1,
+ Rev = <<60,84,174,140,210,120,192,18,100,148,9,181,129,165,248,92>>,
+ RevPath = {},
+ NotDeleted = true,
+ Sequence = {versionstamp, 10873034897377, 0, 0},
+ BranchCount = 1,
+
+ KeyWinner = {?DB_REVS, DocId, NotDeleted, RevPos, Rev},
+ ValWinner = {FirstRevFormat, Sequence, BranchCount, RevPath},
+ ExpectedWinner = expected(
+ true, BranchCount, NotDeleted, RevPos, Rev, RevPath, Sequence),
+ ?assertEqual(ExpectedWinner, fdb_to_revinfo(KeyWinner, ValWinner)),
+
+ KeyLoser = {?DB_REVS, DocId, NotDeleted, RevPos, Rev},
+ ValLoser = {FirstRevFormat, RevPath},
+ ExpectedLoser = expected(
+ false, undefined, NotDeleted, RevPos, Rev, RevPath, undefined),
+ ?assertEqual(ExpectedLoser, fdb_to_revinfo(KeyLoser, ValLoser)),
+ ok.
+
+
+expected(Winner, BranchCount, NotDeleted, RevPos, Rev, RevPath, Sequence) ->
+ #{
+ att_hash => <<>>,
+ branch_count => BranchCount,
+ deleted => not NotDeleted,
+ exists => true,
+ rev_id => {RevPos, Rev},
+ rev_path => tuple_to_list(RevPath),
+ rev_size => 0,
+ sequence => Sequence,
+ winner => Winner
+ }.
+
+
+-endif.