Skip to content
This repository has been archived by the owner on Oct 22, 2021. It is now read-only.

Commit

Permalink
improve tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Robert Newson committed Mar 11, 2011
1 parent 91cca8f commit 69662a1
Showing 1 changed file with 32 additions and 33 deletions.
65 changes: 32 additions & 33 deletions test/monic_file_tests.erl
Original file line number Diff line number Diff line change
Expand Up @@ -18,43 +18,42 @@

all_test_() ->
{foreach,
fun setup/0,
fun cleanup/1,
[fun add/1,
fun add_long/1,
fun add_read/1,
fun add_multi/1,
fun overflow/1,
fun underflow/1
fun() ->
file:delete("foo.monic"),
file:delete("foo.monic.idx"),
{ok, Pid} = monic_file:open("foo.monic"),
Pid end,
fun(Pid) -> monic_file:close(Pid) end,
[
fun add_single_hunk/1,
fun add_multi_hunk/1,
fun add_multi_items/1,
fun overflow/1,
fun underflow/1
]}.

setup() ->
file:delete("foo.monic"),
file:delete("foo.monic.idx"),
{ok, Pid} = monic_file:open("foo.monic"),
Pid.
add_single_hunk(Pid) ->
{"add an item in one hunk",
fun() ->
StreamBody = {<<"123">>, done},
Result = monic_file:add(Pid, 3, StreamBody),
?assertMatch({ok, _}, Result),
{ok, {Key, Cookie}} = Result,
?assertMatch({ok, StreamBody}, monic_file:read(Pid, Key, Cookie))
end}.

cleanup(Pid) ->
monic_file:close(Pid).
add_multi_hunk(Pid) ->
{"add an item in multiple hunks",
fun() ->
StreamBody = {<<"123">>, fun() -> {<<"456">>, done} end},
?assertMatch({ok, _}, monic_file:add(Pid, 6, StreamBody))
end}.

add(Pid) ->
Result = monic_file:add(Pid, 3, {<<"123">>, done}),
?_assertMatch({ok, _}, Result),
{ok, {Key, Cookie}} = Result.

add_long(Pid) ->
?_assertMatch({ok, 0, _}, monic_file:add(Pid, 6,
{<<"123">>, fun() -> {<<"456">>, done} end})).

add_read(Pid) ->
{ok, Key, Cookie} = monic_file:add(Pid, 3, {<<"123">>, done}),
?_assertEqual(ok, monic_file:read(Pid, Key, Cookie, fun({ok, <<"123">>}) -> ok end)).

add_multi(Pid) ->
[?_assertMatch({ok, 0, _}, monic_file:add(Pid, 3, {<<"123">>, done})),
?_assertMatch({ok, 1, _}, monic_file:add(Pid, 3, {<<"456">>, done})),
?_assertMatch({ok, 2, _}, monic_file:add(Pid, 3, {<<"789">>, done})),
?_assertMatch({ok, 3, _}, monic_file:add(Pid, 3, {<<"abc">>, done}))].
add_multi_items(Pid) ->
[?_assertMatch({ok, _}, monic_file:add(Pid, 3, {<<"123">>, done})),
?_assertMatch({ok, _}, monic_file:add(Pid, 3, {<<"456">>, done})),
?_assertMatch({ok, _}, monic_file:add(Pid, 3, {<<"789">>, done})),
?_assertMatch({ok, _}, monic_file:add(Pid, 3, {<<"abc">>, done}))].

overflow(Pid) ->
Res = monic_file:add(Pid, 3, {<<"1234">>, done}),
Expand Down

0 comments on commit 69662a1

Please sign in to comment.