diff options
author | Paul J. Davis <paul.joseph.davis@gmail.com> | 2017-02-01 15:15:09 -0600 |
---|---|---|
committer | Paul J. Davis <paul.joseph.davis@gmail.com> | 2017-05-12 10:32:47 -0500 |
commit | 692834e9b6bdfafffc5d26b3ef57c5e1c398a909 (patch) | |
tree | 06f46cb37187c012eb87f54287f791d32750bba9 | |
parent | a9a23b89ccf48b1b0e106111789a6d4ae5cf9631 (diff) | |
download | couchdb-692834e9b6bdfafffc5d26b3ef57c5e1c398a909.tar.gz |
Add a test helper for creating fake db records
COUCHDB-3288
-rw-r--r-- | src/couch/src/test_util.erl | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/src/couch/src/test_util.erl b/src/couch/src/test_util.erl index 3c4d17060..f879d8f51 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, @@ -229,6 +233,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. |