You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by da...@apache.org on 2017/02/06 21:59:08 UTC

[09/13] couch commit: updated refs/heads/COUCHDB-3287-pluggable-storage-engines to e4e3a68

test_util add fake_db/1


Project: http://git-wip-us.apache.org/repos/asf/couchdb-couch/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-couch/commit/15222460
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch/tree/15222460
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch/diff/15222460

Branch: refs/heads/COUCHDB-3287-pluggable-storage-engines
Commit: 152224608cc9d39a00917cd07f3bbfe1d332ab2e
Parents: 39dc8bd
Author: Paul J. Davis <pa...@gmail.com>
Authored: Mon Feb 6 14:47:45 2017 -0600
Committer: Paul J. Davis <pa...@gmail.com>
Committed: Mon Feb 6 14:47:45 2017 -0600

----------------------------------------------------------------------
 src/test_util.erl | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/15222460/src/test_util.erl
----------------------------------------------------------------------
diff --git a/src/test_util.erl b/src/test_util.erl
index 3c4d170..70fb02b 100644
--- a/src/test_util.erl
+++ b/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,18 @@ 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.