Skip to content

Commit

Permalink
test helper passes in a riak client to the fun
Browse files Browse the repository at this point in the history
  • Loading branch information
Cliff Moon committed May 18, 2010
1 parent f0ef7b6 commit 3e936e7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
19 changes: 15 additions & 4 deletions apps/luwak/test/luwak_obj_tests.erl
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
-include_lib("eunit/include/eunit.hrl").

object_creation_test() ->
test_helper:riak_test(fun() ->
{ok, Riak} = riak:local_client(),
test_helper:riak_test(fun(Riak) ->
Dict = dict:new(),
luwak_obj:create(Riak, <<"file1">>, dict:store(key, value, Dict)),
{ok, Obj} = luwak_obj:get(Riak, <<"file1">>),
Expand All @@ -13,12 +12,24 @@ object_creation_test() ->
end).

set_attributes_test() ->
test_helper:riak_test(fun() ->
{ok, Riak} = riak:local_client(),
test_helper:riak_test(fun(Riak) ->
Dict = dict:new(),
{ok, Obj} = luwak_obj:create(Riak, <<"file1">>, dict:store(key, value, Dict)),
{ok, Obj2} = luwak_obj:set_attributes(Riak, Obj, dict:store(key, blah, Dict)),
Attr = luwak_obj:get_attributes(Obj2),
?assertEqual({ok, blah}, dict:find(key, Attr))
end).

exists_test() ->
test_helper:riak_test(fun(Riak) ->
{ok, Obj} = luwak_obj:create(Riak, <<"file1">>, dict:new()),
?assertEqual({ok, true}, luwak_obj:exists(Riak, <<"file1">>))
end).

delete_test() ->
test_helper:riak_test(fun(Riak) ->
{ok, Obj} = luwak_obj:create(Riak, <<"file1">>, dict:new()),
ok = luwak_obj:delete(Riak, <<"file1">>),
?assertEqual({ok, false}, luwak_obj:exists(Riak, <<"file1">>))
end).

3 changes: 2 additions & 1 deletion apps/luwak/test/test_helper.erl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

riak_test(Fun) ->
start_riak(),
Ret = (catch Fun()),
{ok, Riak} = riak:local_client(),
Ret = (catch Fun(Riak)),
stop_riak(),
case Ret of
{'EXIT', Err} -> throw(Err);
Expand Down

0 comments on commit 3e936e7

Please sign in to comment.