Repository: couchdb-erlang-tests Updated Branches: refs/heads/initial_version [created] 52ac06e8b
Add setups/couch_epi_dispatch Project: http://git-wip-us.apache.org/repos/asf/couchdb-erlang-tests/repo Commit: http://git-wip-us.apache.org/repos/asf/couchdb-erlang-tests/commit/52ac06e8 Tree: http://git-wip-us.apache.org/repos/asf/couchdb-erlang-tests/tree/52ac06e8 Diff: http://git-wip-us.apache.org/repos/asf/couchdb-erlang-tests/diff/52ac06e8 Branch: refs/heads/initial_version Commit: 52ac06e8b4582fdd44904eadfc9cc47c958de23b Parents: 0b1ee5b Author: ILYA Khlopotov <[email protected]> Authored: Thu Mar 17 10:15:06 2016 -0700 Committer: ILYA Khlopotov <[email protected]> Committed: Thu Mar 17 10:16:34 2016 -0700 ---------------------------------------------------------------------- setups/couch_epi_dispatch.erl | 95 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/couchdb-erlang-tests/blob/52ac06e8/setups/couch_epi_dispatch.erl ---------------------------------------------------------------------- diff --git a/setups/couch_epi_dispatch.erl b/setups/couch_epi_dispatch.erl new file mode 100644 index 0000000..9c0b6b0 --- /dev/null +++ b/setups/couch_epi_dispatch.erl @@ -0,0 +1,95 @@ +% 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(couch_epi_dispatch). + +-export([ + dispatch/2 +]). + +%% Exports needed for tests +-export([ + app/0, + providers/0, + services/0, + data_providers/0, + data_subscriptions/0, + processes/0, + notify/3 +]). + + +%% ------------------------------------------------------------------ +%% API functions definitions +%% ------------------------------------------------------------------ + +dispatch(ServiceId, CallbackModule) -> + couch_tests:new(?MODULE, dispatch, + setup_dispatch(ServiceId, CallbackModule), teardown_dispatch()). + +%% ------------------------------------------------------------------ +%% setups and teardowns +%% ------------------------------------------------------------------ + +setup_dispatch(ServiceId, CallbackModule) -> + fun(Fixture, Ctx0) -> + Plugins = application:get_env(couch_epi, plugins, []), + Ctx1 = start_epi(Ctx0, [CallbackModule]), + couch_tests:set_state(Fixture, Ctx1, {ServiceId, CallbackModule, Plugins}) + end. + +teardown_dispatch() -> + fun(Fixture, Ctx0) -> + {ServiceId, _Module, Plugins} = couch_tests:get_state(Fixture, Ctx0), + stop_epi(Ctx0, ServiceId, Plugins) + end. + +%% ------------------------------------------------------------------ +%% Helper functions definitions +%% ------------------------------------------------------------------ + +start_epi(Ctx0, Plugins) -> + %% stop in case it's started from other tests.. + Ctx1 = couch_tests:stop_applications([couch_epi], Ctx0), + application:unload(couch_epi), + ok = application:load(couch_epi), + ok = application:set_env(couch_epi, plugins, Plugins), + couch_tests:start_applications([couch_epi], Ctx1). + +stop_epi(Ctx0, ServiceId, Plugins) -> + ok = application:set_env(couch_epi, plugins, Plugins), + Handle = couch_epi:get_handle(ServiceId), + catch couch_epi_module_keeper:reload(Handle), + Ctx1 = couch_tests:stop_applications([couch_epi], Ctx0), + application:unload(couch_epi), + Ctx1. + +%% ------------------------------------------------------------------ +%% Tests +%% ------------------------------------------------------------------ + +%% EPI behaviour callbacks +app() -> test_app. +providers() -> []. +services() -> []. +data_providers() -> []. +data_subscriptions() -> []. +processes() -> []. +notify(_, _, _) -> ok. + +-ifdef(TEST). +-include_lib("eunit/include/eunit.hrl"). + +dispatch_test() -> + ?assert(couch_tests:validate_fixture(dispatch(test_service, ?MODULE))). + +-endif.
