summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam Kocoloski <kocolosk@apache.org>2019-08-06 22:46:43 -0400
committerAdam Kocoloski <kocolosk@apache.org>2019-08-09 07:58:04 -0400
commitaab0c51d8dca39d6556d4636edec20d14f65e36d (patch)
tree3cdbad8791699fcb72daeda006405fc978716b28
parent0bdf74d6dcfdbca8f6b405e2f3e10e011e8d9191 (diff)
downloadcouchdb-aab0c51d8dca39d6556d4636edec20d14f65e36d.tar.gz
Move couch startup to a fixture
This improves reliability because that time isn't charged to the test, and also speeds up the test.
-rw-r--r--src/ddoc_cache/test/eunit/ddoc_cache_no_cache_test.erl76
1 files changed, 37 insertions, 39 deletions
diff --git a/src/ddoc_cache/test/eunit/ddoc_cache_no_cache_test.erl b/src/ddoc_cache/test/eunit/ddoc_cache_no_cache_test.erl
index 637a6e872..a1937a088 100644
--- a/src/ddoc_cache/test/eunit/ddoc_cache_no_cache_test.erl
+++ b/src/ddoc_cache/test/eunit/ddoc_cache_no_cache_test.erl
@@ -35,45 +35,43 @@ return_error(_DDocId) ->
{error, timeout}.
-start(Resp) ->
- Ctx = ddoc_cache_tutil:start_couch(),
+no_cache_test_() ->
+ {
+ "ddoc_cache no cache test",
+ {
+ setup,
+ fun ddoc_cache_tutil:start_couch/0, fun ddoc_cache_tutil:stop_couch/1,
+ {
+ foreachx,
+ fun setup/1, fun teardown/2,
+ [
+ {fun ddoc/1, fun no_cache_open_ok_test/2},
+ {fun not_found/1, fun no_cache_open_not_found_test/2},
+ {fun return_error/1, fun no_cache_open_error_test/2}
+ ]
+ }
+ }
+ }.
+
+setup(Resp) ->
meck:new(fabric),
meck:expect(fabric, open_doc, fun(_, DDocId, _) ->
Resp(DDocId)
- end),
- Ctx.
-
-
-stop(Ctx) ->
- meck:unload(),
- ddoc_cache_tutil:stop_couch(Ctx).
-
-
-no_cache_open_ok_test() ->
- Ctx = start(fun ddoc/1),
- try
- Resp = ddoc_cache:open_doc(<<"foo">>, <<"bar">>),
- ?assertEqual(ddoc(<<"bar">>), Resp)
- after
- stop(Ctx)
- end.
-
-
-no_cache_open_not_found_test() ->
- Ctx = start(fun not_found/1),
- try
- Resp = ddoc_cache:open_doc(<<"foo">>, <<"bar">>),
- ?assertEqual(not_found(<<"bar">>), Resp)
- after
- stop(Ctx)
- end.
-
-
-no_cache_open_error_test() ->
- Ctx = start(fun return_error/1),
- try
- Resp = ddoc_cache:open_doc(<<"foo">>, <<"bar">>),
- ?assertEqual(return_error(<<"bar">>), Resp)
- after
- stop(Ctx)
- end.
+ end).
+
+teardown(_, _) ->
+ meck:unload().
+
+no_cache_open_ok_test(_, _) ->
+ Resp = ddoc_cache:open_doc(<<"foo">>, <<"bar">>),
+ ?_assertEqual(ddoc(<<"bar">>), Resp).
+
+
+no_cache_open_not_found_test(_, _) ->
+ Resp = ddoc_cache:open_doc(<<"foo">>, <<"baz">>),
+ ?_assertEqual(not_found(<<"baz">>), Resp).
+
+
+no_cache_open_error_test(_, _) ->
+ Resp = ddoc_cache:open_doc(<<"foo">>, <<"bif">>),
+ ?_assertEqual(return_error(<<"bif">>), Resp).