diff options
author | Jay Doane <jaydoane@apache.org> | 2020-02-20 15:09:49 -0800 |
---|---|---|
committer | Jay Doane <jaydoane@apache.org> | 2020-02-20 15:09:49 -0800 |
commit | 39a600c3de01224be09224c0a89deb769f54bb5f (patch) | |
tree | 8aa5784805c7f32856ff364d4282926af7d45a8e | |
parent | fb52651bebf0332f01b14a3df2779cf65c4db70a (diff) | |
download | couchdb-fdb_to_revinfo-compatibility.tar.gz |
Add fdb_to_revinfo version compatibility unit testfdb_to_revinfo-compatibility
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.erl | 44 |
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. |