diff options
author | Paul J. Davis <paul.joseph.davis@gmail.com> | 2017-02-01 15:15:09 -0600 |
---|---|---|
committer | Joan Touzet <wohali@users.noreply.github.com> | 2017-10-19 19:13:25 -0400 |
commit | 3a2e9b47265575ee6b7934a4978925ca1fc3f6cd (patch) | |
tree | f39ab3a01b2527571ad92e67ff1c8f9d360fbfa2 | |
parent | de146b81f0eae08e0881396f865ddcac283b2678 (diff) | |
download | couchdb-3a2e9b47265575ee6b7934a4978925ca1fc3f6cd.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 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. |