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 2019/04/26 18:37:17 UTC
[couchdb] branch prototype/rfc-001-revision-metadata-model updated:
Initial eunit test setup for fabric2 modules
This is an automated email from the ASF dual-hosted git repository.
davisp pushed a commit to branch prototype/rfc-001-revision-metadata-model
in repository https://gitbox.apache.org/repos/asf/couchdb.git
The following commit(s) were added to refs/heads/prototype/rfc-001-revision-metadata-model by this push:
new d3b5823 Initial eunit test setup for fabric2 modules
d3b5823 is described below
commit d3b5823aae8b39b6ce63f70cf24f73ccd2050acb
Author: Paul J. Davis <pa...@gmail.com>
AuthorDate: Fri Apr 26 13:35:16 2019 -0500
Initial eunit test setup for fabric2 modules
This uses the new erlfdb utilities to run eunit tests against and
epehemeral fdbserver instance. Every time the fabric application is
started the cluster is cleared so that test state is reset between
separate instances of the application. Generally speaking this means
that the state in the fdbserver process is valid for any given `setup`
batch of eunit tests.
---
rel/files/eunit.config | 3 +-
src/fabric/src/fabric2_server.erl | 9 ++++--
.../fabric/test/fabric2_db_crud_tests.erl | 32 +++++++++++++++++++---
3 files changed, 37 insertions(+), 7 deletions(-)
diff --git a/rel/files/eunit.config b/rel/files/eunit.config
index 3c7457d..5e96fae 100644
--- a/rel/files/eunit.config
+++ b/rel/files/eunit.config
@@ -12,5 +12,6 @@
[
{kernel, [{error_logger, silent}]},
- {sasl, [{sasl_error_logger, false}]}
+ {sasl, [{sasl_error_logger, false}]},
+ {fabric, [{eunit_run, true}]}
].
diff --git a/src/fabric/src/fabric2_server.erl b/src/fabric/src/fabric2_server.erl
index 1e086ca..922acb1 100644
--- a/src/fabric/src/fabric2_server.erl
+++ b/src/fabric/src/fabric2_server.erl
@@ -66,8 +66,13 @@ init(_) ->
{write_concurrency, true}
]),
- ClusterStr = config:get("erlfdb", "cluster_file", ?CLUSTER_FILE),
- Db = erlfdb:open(iolist_to_binary(ClusterStr)),
+ Db = case application:get_env(fabric, eunit_run) of
+ {ok, true} ->
+ erlfdb_util:get_test_db([empty]);
+ undefined ->
+ ClusterStr = config:get("erlfdb", "cluster_file", ?CLUSTER_FILE),
+ erlfdb:open(iolist_to_binary(ClusterStr))
+ end,
application:set_env(fabric, db, Db),
{ok, nil}.
diff --git a/rel/files/eunit.config b/src/fabric/test/fabric2_db_crud_tests.erl
similarity index 50%
copy from rel/files/eunit.config
copy to src/fabric/test/fabric2_db_crud_tests.erl
index 3c7457d..9503d96 100644
--- a/rel/files/eunit.config
+++ b/src/fabric/test/fabric2_db_crud_tests.erl
@@ -10,7 +10,31 @@
% License for the specific language governing permissions and limitations under
% the License.
-[
- {kernel, [{error_logger, silent}]},
- {sasl, [{sasl_error_logger, false}]}
-].
+-module(fabric2_db_crud_tests).
+
+
+-include_lib("couch/include/couch_eunit.hrl").
+-include_lib("eunit/include/eunit.hrl").
+
+
+-define(TDEF(A), {atom_to_list(A), fun A/0}).
+
+
+crud_test_() ->
+ {
+ "Test database CRUD operations",
+ {
+ setup,
+ fun() -> test_util:start_couch([fabric]) end,
+ fun test_util:stop_couch/1,
+ [
+ ?TDEF(create_db)
+ ]
+ }
+ }.
+
+
+create_db() ->
+ DbName = ?tempdb(),
+ ?assertMatch({ok, _}, fabric2_db:create(DbName, [])).
+