Commits

Anonymous committed dbb0bf1

improve backend simple_test (bucket-key usage, and list-keys tests), and abstract to utility module

Comments (0)

Files changed (4)

src/riak_dets_backend.erl

     application:set_env(riak, riak_dets_backend_root,
                         "test/dets-backend"),
     ?assertCmd("rm -rf test/dets-backend"),
-    {ok,S} = riak_dets_backend:start(42),
-    ok = riak_dets_backend:put(S,<<"k1">>,<<"v1">>),
-    ok = riak_dets_backend:put(S,<<"k2">>,<<"v2">>),
-    {ok,<<"v2">>} = riak_dets_backend:get(S,<<"k2">>),
-    {error, notfound} = riak_dets_backend:get(S, <<"k3">>),
-    [<<"k1">>,<<"k2">>] = lists:sort(riak_dets_backend:list(S)),
-    ok = riak_dets_backend:delete(S,<<"k2">>),
-    [<<"k1">>] = riak_dets_backend:list(S),
-    ok = riak_dets_backend:stop(S).
+    riak_test_util:standard_backend_test(riak_dets_backend).
 
 % @spec start(Partition :: integer()) ->
 %                        {ok, state()} | {{error, Reason :: term()}, state()}

src/riak_ets_backend.erl

 
 % @private
 simple_test() ->
-    {ok,S} = riak_ets_backend:start(42),
-    ok = riak_ets_backend:put(S,<<"k1">>,<<"v1">>),
-    ok = riak_ets_backend:put(S,<<"k2">>,<<"v2">>),
-    {ok,<<"v2">>} = riak_ets_backend:get(S,<<"k2">>),
-    [<<"k1">>,<<"k2">>] = lists:sort(riak_ets_backend:list(S)),
-    ok = riak_ets_backend:delete(S,<<"k2">>),
-    [<<"k1">>] = riak_ets_backend:list(S),
-    ok = riak_ets_backend:stop(S).
+    riak_test_util:standard_backend_test(riak_ets_backend).
 
 % @spec start(Partition :: integer()) ->
 %                        {ok, state()} | {{error, Reason :: term()}, state()}

src/riak_osmos_backend.erl

     application:set_env(riak, riak_osmos_backend_root,
                         "test/osmos-backend"),
     ?assertCmd("rm -rf test/osmos-backend"),
-    {ok, S} = riak_osmos_backend:start(42),
-    ok = riak_osmos_backend:put(S,<<"k1">>,<<"v1">>),
-    ok = riak_osmos_backend:put(S,<<"k2">>,<<"v2">>),
-    {ok,<<"v2">>} = riak_osmos_backend:get(S,<<"k2">>),
-    {error, notfound} = riak_osmos_backend:get(S, <<"k3">>),
-    [<<"k1">>,<<"k2">>] = lists:sort(riak_osmos_backend:list(S)),
-    ok = riak_osmos_backend:delete(S,<<"k2">>),
-    [<<"k1">>] = riak_osmos_backend:list(S),
-    ok = riak_osmos_backend:stop(S).
+    riak_test_util:standard_backend_test(riak_osmos_backend).

src/riak_test_util.erl

+-module(riak_test_util).
+-export([standard_backend_test/1]).
+-include_lib("eunit/include/eunit.hrl").
+
+standard_backend_test(BackendMod) ->
+    {ok, S} = BackendMod:start(42),
+    ?assertEqual(ok, BackendMod:put(S,{b1,<<"k1">>},<<"v1">>)),
+    ?assertEqual(ok, BackendMod:put(S,{b2,<<"k2">>},<<"v2">>)),
+    ?assertEqual({ok,<<"v2">>}, BackendMod:get(S,{b2,<<"k2">>})),
+    ?assertEqual({error, notfound}, BackendMod:get(S, {b1,<<"k3">>})),
+    ?assertEqual([{b1,<<"k1">>},{b2,<<"k2">>}],
+                 lists:sort(BackendMod:list(S))),
+    ?assertEqual([<<"k2">>], BackendMod:list_bucket(S, b2)),
+    ?assertEqual([<<"k1">>], BackendMod:list_bucket(S, b1)),
+    ?assertEqual(ok, BackendMod:delete(S,{b2,<<"k2">>})),
+    ?assertEqual({error, notfound}, BackendMod:get(S, {b2, <<"k2">>})),
+    ?assertEqual([{b1, <<"k1">>}], BackendMod:list(S)),
+    ok = BackendMod:stop(S).