diff options
author | Paul J. Davis <paul.joseph.davis@gmail.com> | 2019-04-26 13:35:16 -0500 |
---|---|---|
committer | Paul J. Davis <paul.joseph.davis@gmail.com> | 2019-04-26 13:35:16 -0500 |
commit | d3b5823aae8b39b6ce63f70cf24f73ccd2050acb (patch) | |
tree | e11f5be84795a76d686b7ed3d1a0e0d021e797d7 | |
parent | c1a6af893225f0cd0836d9621b6e25471dda438b (diff) | |
download | couchdb-d3b5823aae8b39b6ce63f70cf24f73ccd2050acb.tar.gz |
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.
-rw-r--r-- | rel/files/eunit.config | 3 | ||||
-rw-r--r-- | src/fabric/src/fabric2_server.erl | 9 | ||||
-rw-r--r-- | src/fabric/test/fabric2_db_crud_tests.erl | 40 |
3 files changed, 49 insertions, 3 deletions
diff --git a/rel/files/eunit.config b/rel/files/eunit.config index 3c7457d3a..5e96fae9e 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 1e086ca99..922acb19d 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/src/fabric/test/fabric2_db_crud_tests.erl b/src/fabric/test/fabric2_db_crud_tests.erl new file mode 100644 index 000000000..9503d961c --- /dev/null +++ b/src/fabric/test/fabric2_db_crud_tests.erl @@ -0,0 +1,40 @@ +% Licensed under the Apache License, Version 2.0 (the "License"); you may not +% use this file except in compliance with the License. You may obtain a copy of +% the License at +% +% http://www.apache.org/licenses/LICENSE-2.0 +% +% Unless required by applicable law or agreed to in writing, software +% distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +% WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +% License for the specific language governing permissions and limitations under +% the License. + +-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, [])). + |