summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul J. Davis <paul.joseph.davis@gmail.com>2017-02-01 15:15:09 -0600
committerJoan Touzet <wohali@users.noreply.github.com>2017-10-19 19:13:25 -0400
commit3a2e9b47265575ee6b7934a4978925ca1fc3f6cd (patch)
treef39ab3a01b2527571ad92e67ff1c8f9d360fbfa2
parentde146b81f0eae08e0881396f865ddcac283b2678 (diff)
downloadcouchdb-3a2e9b47265575ee6b7934a4978925ca1fc3f6cd.tar.gz
Add a test helper for creating fake db records
COUCHDB-3288
-rw-r--r--src/couch/src/test_util.erl14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/couch/src/test_util.erl b/src/couch/src/test_util.erl
index e652dd9b3..8a05e8830 100644
--- a/src/couch/src/test_util.erl
+++ b/src/couch/src/test_util.erl
@@ -13,6 +13,8 @@
-module(test_util).
-include_lib("couch/include/couch_eunit.hrl").
+-include("couch_db.hrl").
+-include("couch_db_int.hrl").
-export([init_code_path/0]).
-export([source_file/1, build_file/1]).
@@ -32,6 +34,8 @@
-export([start/1, start/2, start/3, stop/1]).
+-export([fake_db/1]).
+
-record(test_context, {mocked = [], started = [], module}).
-define(DEFAULT_APPS,
@@ -230,6 +234,16 @@ stop(#test_context{mocked = Mocked, started = Apps}) ->
meck:unload(Mocked),
stop_applications(Apps).
+fake_db(Fields) ->
+ Indexes = lists:zip(
+ record_info(fields, db),
+ lists:seq(2, record_info(size, db))
+ ),
+ lists:foldl(fun({FieldName, Value}, Acc) ->
+ Idx = couch_util:get_value(FieldName, Indexes),
+ setelement(Idx, Acc, Value)
+ end, #db{}, Fields).
+
now_us() ->
{MegaSecs, Secs, MicroSecs} = now(),
(MegaSecs * 1000000 + Secs) * 1000000 + MicroSecs.