diff --git a/test/mcd_cluster_tests.erl b/test/mcd_cluster_tests.erl index 75d6ece..0a46c4a 100644 --- a/test/mcd_cluster_tests.erl +++ b/test/mcd_cluster_tests.erl @@ -5,13 +5,83 @@ -define(NAME, mb_test). -define(setup(F), {setup, fun setup/0, fun cleanup/1, F}). +% XXX: turn off 'INFO' output +% XXX: mock memcached +% XXX: add check that adding nodes preserves their order, e.g. if we add +% a, c and then b we will get back [a, c, b], not [a, b, c] + +%%% Test helpers %%% + +mcd_node(NodeId) -> + {NodeId, ["localhost", 2222], 10}. + +a_node_id() -> + % XXX: return unique node ids each time + some_node_id. + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +test_XXX_test_() -> + [ + { + foreach, + + % setup + fun() -> + FirstNodeId = localhost, + {ok, _Pid} = mcd_cluster:start_link(?NAME, [mcd_node(FirstNodeId)]), + FirstNodeId + end, + + % cleanup + fun(_FirstNodeId) -> + mcd_cluster:stop(?NAME) + end, + + % instantiators + [ + fun(FirstNodeId) -> + { + % XXX: this should really be tested outside of the fixture + "using startup parameters", + fun() -> + Nodes = mcd_cluster:nodes(?NAME), + ?assertMatch([{FirstNodeId, _}], Nodes) + end + } + end, + + fun(FirstNodeId) -> + { + "Add node", + fun() -> + SecondNodeId = a_node_id(), + ok = mcd_cluster:add(?NAME, mcd_node(SecondNodeId)), + Nodes = mcd_cluster:nodes(?NAME), + ?assertMatch([{FirstNodeId, _}, {SecondNodeId, _}], Nodes) + end + } + end, + + fun(FirstNodeId) -> + { + "Adding duplicate node", + fun() -> + Result = mcd_cluster:add(?NAME, mcd_node(FirstNodeId)), + ?assertEqual({error, already_there, [FirstNodeId]}, Result) + end + } + end + ] + } + ]. all_test_() -> [{"Check MCD cluster", - ?setup(fun() -> [check_node_(), + ?setup(fun() -> [check_node_(), % using_startup_args_test add_node_(), - check_node_2_(), - add_node_dup_(), + check_node_2_(), % add_node_test + add_node_dup_(), % done check_node_2_(), del_node_(), check_node_(),