Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files
Fix test suite
COUCHDB-2796
  • Loading branch information
iilyak committed Sep 2, 2015
1 parent a57fc94 commit d7eabf6439d0a1f8c7788b4c2a2766206d6a1bbb
Showing 5 changed files with 131 additions and 277 deletions.
@@ -220,66 +220,76 @@ fold_defs(Defs, Acc, Fun) ->
-include_lib("eunit/include/eunit.hrl").

basic_test() ->
Module = foo_bar_baz_bugz,
Data1 = [some_nice_data],
Data2 = "other data",
Data3 = {"even more data"},
Defs1 = [{foo, Data1}],
Defs2 = lists:usort([{foo, Data2}, {bar, Data3}]),
try
Module = foo_bar_baz_bugz,

set(Module, app1, Defs1),
set(Module, app2, Defs2),
meck:new(couch_epi_module_keeper, [passthrough]),
meck:expect(couch_epi_module_keeper, save, fun
(Handle, Source, Modules) -> save(Handle, Source, Modules)
end),

?assertEqual([bar, foo], lists:usort(Module:keys())),
?assertEqual([app1, app2], lists:usort(Module:subscribers())),
Data1 = [some_nice_data],
Data2 = "other data",
Data3 = {"even more data"},
Defs1 = [{foo, Data1}],
Defs2 = lists:usort([{foo, Data2}, {bar, Data3}]),

?assertEqual(Data1, Module:get(app1, foo)),
?assertEqual(Data2, Module:get(app2, foo)),
?assertEqual(Data3, Module:get(app2, bar)),
set(Module, app1, Defs1),
set(Module, app2, Defs2),

?assertEqual(undefined, Module:get(bad, key)),
?assertEqual(undefined, Module:get(source, bad)),
?assertEqual([bar, foo], lists:usort(Module:keys())),
?assertEqual([app1, app2], lists:usort(Module:subscribers())),

?assertEqual("3KZ4EG4WBF4J683W8GSDDPYR3", Module:version(app1)),
?assertEqual("4EFUU47W9XDNMV9RMZSSJQU3Y", Module:version(app2)),
?assertEqual(Data1, Module:get(app1, foo)),
?assertEqual(Data2, Module:get(app2, foo)),
?assertEqual(Data3, Module:get(app2, bar)),

?assertEqual({error,{unknown,bad}}, Module:version(bad)),
?assertEqual(undefined, Module:get(bad, key)),
?assertEqual(undefined, Module:get(source, bad)),

?assertEqual(
[{app1,"3KZ4EG4WBF4J683W8GSDDPYR3"},
{app2,"4EFUU47W9XDNMV9RMZSSJQU3Y"}], lists:usort(Module:version())),
?assertEqual("3KZ4EG4WBF4J683W8GSDDPYR3", Module:version(app1)),
?assertEqual("4EFUU47W9XDNMV9RMZSSJQU3Y", Module:version(app2)),

?assertEqual(
[{app1,[some_nice_data]},{app2,"other data"}],
lists:usort(Module:by_key(foo))),
?assertEqual({error,{unknown,bad}}, Module:version(bad)),

?assertEqual([], lists:usort(Module:by_key(bad))),
?assertEqual(
[{app1,"3KZ4EG4WBF4J683W8GSDDPYR3"},
{app2,"4EFUU47W9XDNMV9RMZSSJQU3Y"}], lists:usort(Module:version())),

?assertEqual(
[
{bar, [{app2, {"even more data"}}]},
{foo, [{app2, "other data"}, {app1, [some_nice_data]}]}
],
lists:usort(Module:by_key())),
?assertEqual(
[{app1,[some_nice_data]},{app2,"other data"}],
lists:usort(Module:by_key(foo))),

?assertEqual([], lists:usort(Module:by_key(bad))),

?assertEqual(Defs1, lists:usort(Module:by_source(app1))),
?assertEqual(Defs2, lists:usort(Module:by_source(app2))),
?assertEqual(
[
{bar, [{app2, {"even more data"}}]},
{foo, [{app2, "other data"}, {app1, [some_nice_data]}]}
],
lists:usort(Module:by_key())),

?assertEqual([], lists:usort(Module:by_source(bad))),

?assertEqual(
[
{app1, [{foo, [some_nice_data]}]},
{app2, [{foo, "other data"}, {bar, {"even more data"}}]}
],
lists:usort(Module:by_source())),
?assertEqual(Defs1, lists:usort(Module:by_source(app1))),
?assertEqual(Defs2, lists:usort(Module:by_source(app2))),

?assertEqual(
lists:usort([Data1, Data2, Data3]), lists:usort(Module:all())),
?assertEqual(lists:usort([Data1, Data2]), lists:usort(Module:all(foo))),
?assertEqual([], lists:usort(Module:all(bad))),
?assertEqual([], lists:usort(Module:by_source(bad))),

?assertEqual(
[
{app1, [{foo, [some_nice_data]}]},
{app2, [{foo, "other data"}, {bar, {"even more data"}}]}
],
lists:usort(Module:by_source())),

?assertEqual(
lists:usort([Data1, Data2, Data3]), lists:usort(Module:all())),
?assertEqual(lists:usort([Data1, Data2]), lists:usort(Module:all(foo))),
?assertEqual([], lists:usort(Module:all(bad))),
ok
after
meck:unload(couch_epi_module_keeper)
end,
ok.

-endif.
@@ -330,26 +330,36 @@ bar() ->
[].

basic_test() ->
Module = foo_bar_dispatcher,
add(Module, app1, [?MODULE]),
try
Module = foo_bar_dispatcher,
meck:new(couch_epi_module_keeper, [passthrough]),
meck:expect(couch_epi_module_keeper, save, fun
(Handle, Source, Modules) -> save(Handle, Source, Modules)
end),

add(Module, app1, [?MODULE]),

?assertMatch([?MODULE], modules(Module, foo, 2)),
?assertMatch([?MODULE], modules(Module, foo, 2)),

?assert(is_list(Module:version(app1))),
?assert(is_list(Module:version(app1))),

Defs1 = lists:usort(Module:definitions()),
?assertMatch([{app1, [{?MODULE, _}]}], Defs1),
[{app1, [{?MODULE, Exports}]}] = Defs1,
?assert(lists:member({bar, 0}, Exports)),
Defs1 = lists:usort(Module:definitions()),
?assertMatch([{app1, [{?MODULE, _}]}], Defs1),
[{app1, [{?MODULE, Exports}]}] = Defs1,
?assert(lists:member({bar, 0}, Exports)),

add(Module, app2, [?MODULE]),
Defs2 = lists:usort(Module:definitions()),
?assertMatch([{app1, [{?MODULE, _}]}, {app2, [{?MODULE, _}]}], Defs2),
add(Module, app2, [?MODULE]),
Defs2 = lists:usort(Module:definitions()),
?assertMatch([{app1, [{?MODULE, _}]}, {app2, [{?MODULE, _}]}], Defs2),

?assertMatch([{app1, Hash}, {app2, Hash}], Module:version()),
?assertMatch([{app1, Hash}, {app2, Hash}], Module:version()),

?assertMatch([], Module:dispatch(?MODULE, bar, [])),
?assertMatch({1, 2}, Module:dispatch(?MODULE, foo, [1, 2])),
?assertMatch([], Module:dispatch(?MODULE, bar, [])),
?assertMatch({1, 2}, Module:dispatch(?MODULE, foo, [1, 2])),
ok
after
meck:unload(couch_epi_module_keeper)
end,

ok.

This file was deleted.

This file was deleted.

0 comments on commit d7eabf6

Please sign in to comment.