summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul J. Davis <paul.joseph.davis@gmail.com>2020-02-14 11:17:52 -0600
committerNick Vatamaniuc <nickva@users.noreply.github.com>2020-02-15 15:09:02 -0500
commitdae118bd2585fbe0d080df88fe3c958f7b58b773 (patch)
tree450f507baf2923dfa1fff93e4df39fcff17d5f26
parente60ff8562b6cc7ff7eab15494e94c42265d876cf (diff)
downloadcouchdb-dae118bd2585fbe0d080df88fe3c958f7b58b773.tar.gz
Test coverage: get_full_doc_info
-rw-r--r--src/fabric/test/fabric2_db_misc_tests.erl87
1 files changed, 87 insertions, 0 deletions
diff --git a/src/fabric/test/fabric2_db_misc_tests.erl b/src/fabric/test/fabric2_db_misc_tests.erl
index 12fc3e50b..f1ee8a893 100644
--- a/src/fabric/test/fabric2_db_misc_tests.erl
+++ b/src/fabric/test/fabric2_db_misc_tests.erl
@@ -33,6 +33,11 @@ misc_test_() ->
?TDEF(set_revs_limit),
?TDEF(set_security),
?TDEF(is_system_db),
+ ?TDEF(get_doc_info),
+ ?TDEF(get_doc_info_not_found),
+ ?TDEF(get_full_doc_info),
+ ?TDEF(get_full_doc_info_not_found),
+ ?TDEF(get_full_doc_infos),
?TDEF(ensure_full_commit),
?TDEF(metadata_bump),
?TDEF(db_version_bump)
@@ -109,6 +114,88 @@ is_system_db({DbName, Db, _}) ->
?assertEqual(false, fabric2_db:is_system_db_name(<<"foo/bar">>)).
+get_doc_info({_, Db, _}) ->
+ DocId = couch_uuids:random(),
+ InsertDoc = #doc{
+ id = DocId,
+ body = {[{<<"foo">>, true}]}
+ },
+ {ok, {Pos, Rev}} = fabric2_db:update_doc(Db, InsertDoc, []),
+
+ DI = fabric2_db:get_doc_info(Db, DocId),
+ ?assert(is_record(DI, doc_info)),
+ #doc_info{
+ id = DIDocId,
+ high_seq = HighSeq,
+ revs = Revs
+ } = DI,
+
+ ?assertEqual(DocId, DIDocId),
+ ?assert(is_binary(HighSeq)),
+ ?assertMatch([#rev_info{}], Revs),
+
+ [#rev_info{
+ rev = DIRev,
+ seq = Seq,
+ deleted = Deleted,
+ body_sp = BodySp
+ }] = Revs,
+
+ ?assertEqual({Pos, Rev}, DIRev),
+ ?assert(is_binary(Seq)),
+ ?assert(not Deleted),
+ ?assertMatch(undefined, BodySp).
+
+
+get_doc_info_not_found({_, Db, _}) ->
+ DocId = couch_uuids:random(),
+ ?assertEqual(not_found, fabric2_db:get_doc_info(Db, DocId)).
+
+
+get_full_doc_info({_, Db, _}) ->
+ DocId = couch_uuids:random(),
+ InsertDoc = #doc{
+ id = DocId,
+ body = {[{<<"foo">>, true}]}
+ },
+ {ok, {Pos, Rev}} = fabric2_db:update_doc(Db, InsertDoc, []),
+ FDI = fabric2_db:get_full_doc_info(Db, DocId),
+
+ ?assert(is_record(FDI, full_doc_info)),
+ #full_doc_info{
+ id = FDIDocId,
+ update_seq = UpdateSeq,
+ deleted = Deleted,
+ rev_tree = RevTree,
+ sizes = SizeInfo
+ } = FDI,
+
+ ?assertEqual(DocId, FDIDocId),
+ ?assert(is_binary(UpdateSeq)),
+ ?assert(not Deleted),
+ ?assertMatch([{Pos, {Rev, _, []}}], RevTree),
+ ?assertEqual(#size_info{}, SizeInfo).
+
+
+get_full_doc_info_not_found({_, Db, _}) ->
+ DocId = couch_uuids:random(),
+ ?assertEqual(not_found, fabric2_db:get_full_doc_info(Db, DocId)).
+
+
+get_full_doc_infos({_, Db, _}) ->
+ DocIds = lists:map(fun(_) ->
+ DocId = couch_uuids:random(),
+ Doc = #doc{id = DocId},
+ {ok, _} = fabric2_db:update_doc(Db, Doc, []),
+ DocId
+ end, lists:seq(1, 5)),
+
+ FDIs = fabric2_db:get_full_doc_infos(Db, DocIds),
+ lists:zipwith(fun(DocId, FDI) ->
+ ?assertEqual(DocId, FDI#full_doc_info.id)
+ end, DocIds, FDIs).
+
+
ensure_full_commit({_, Db, _}) ->
?assertEqual({ok, 0}, fabric2_db:ensure_full_commit(Db)),
?assertEqual({ok, 0}, fabric2_db:ensure_full_commit(Db, 5)).