diff options
Diffstat (limited to 'test/rebar_pkg_SUITE.erl')
-rw-r--r-- | test/rebar_pkg_SUITE.erl | 45 |
1 files changed, 37 insertions, 8 deletions
diff --git a/test/rebar_pkg_SUITE.erl b/test/rebar_pkg_SUITE.erl index b3201ad..9f19e0d 100644 --- a/test/rebar_pkg_SUITE.erl +++ b/test/rebar_pkg_SUITE.erl @@ -11,7 +11,8 @@ -define(good_checksum, <<"1C6CE379D191FBAB41B7905075E0BF87CBBE23C77CECE775C5A0B786B2244C35">>). all() -> [good_uncached, good_cached, badindexchk, badpkg, - bad_to_good, good_disconnect, bad_disconnect, pkgs_provider]. + bad_to_good, good_disconnect, bad_disconnect, pkgs_provider, + find_highest_matching]. init_per_suite(Config) -> application:start(meck), @@ -20,7 +21,19 @@ init_per_suite(Config) -> end_per_suite(_Config) -> application:stop(meck). -init_per_testcase(pkgs_provider, Config) -> +init_per_testcase(pkgs_provider=Name, Config) -> + %% Need to mock out a registry for this test now because it will try to update it automatically + Priv = ?config(priv_dir, Config), + Tid = ets:new(registry_table, [public]), + ets:insert_new(Tid, []), + CacheRoot = filename:join([Priv, "cache", atom_to_list(Name)]), + CacheDir = filename:join([CacheRoot, "hex", "com", "test", "packages"]), + filelib:ensure_dir(filename:join([CacheDir, "registry"])), + ok = ets:tab2file(Tid, filename:join([CacheDir, "registry"])), + meck:new(rebar_packages, [passthrough]), + meck:expect(rebar_packages, registry_dir, fun(_) -> {ok, CacheDir} end), + meck:expect(rebar_packages, package_dir, fun(_) -> {ok, CacheDir} end), + rebar_prv_update:hex_to_index(rebar_state:new()), Config; init_per_testcase(good_uncached=Name, Config0) -> Config = [{good_cache, false}, @@ -74,10 +87,13 @@ init_per_testcase(bad_disconnect=Name, Config0) -> meck:unload(httpc), meck:new(httpc, [passthrough, unsticky]), meck:expect(httpc, request, fun(_, _, _, _, _) -> {error, econnrefused} end), - Config. - -end_per_testcase(pkgs_provider, Config) -> Config; +init_per_testcase(Name, Config0) -> + Config = [{good_cache, false}, + {pkg, {<<"goodpkg">>, <<"1.0.0">>}} + | Config0], + mock_config(Name, Config). + end_per_testcase(_, Config) -> unmock_config(Config), Config. @@ -162,6 +178,16 @@ pkgs_provider(Config) -> {ok, []} ). +find_highest_matching(_Config) -> + State = rebar_state:new(), + {ok, Vsn} = rebar_packages:find_highest_matching(<<"goodpkg">>, <<"1.0.0">>, package_index, State), + ?assertEqual(<<"1.0.1">>, Vsn), + {ok, Vsn1} = rebar_packages:find_highest_matching(<<"goodpkg">>, <<"1.0">>, package_index, State), + ?assertEqual(<<"1.1.1">>, Vsn1), + {ok, Vsn2} = rebar_packages:find_highest_matching(<<"goodpkg">>, <<"2.0">>, package_index, State), + ?assertEqual(<<"2.0.0">>, Vsn2). + + %%%%%%%%%%%%%%% %%% Helpers %%% %%%%%%%%%%%%%%% @@ -172,10 +198,13 @@ mock_config(Name, Config) -> Tid = ets:new(registry_table, [public]), ets:insert_new(Tid, [ {<<"badindexchk">>,[[<<"1.0.0">>]]}, - {<<"goodpkg">>,[[<<"1.0.0">>]]}, + {<<"goodpkg">>,[[<<"1.0.0">>, <<"1.0.1">>, <<"1.1.1">>, <<"2.0.0">>]]}, {<<"badpkg">>,[[<<"1.0.0">>]]}, {{<<"badindexchk">>,<<"1.0.0">>}, [[], ?bad_checksum, [<<"rebar3">>]]}, {{<<"goodpkg">>,<<"1.0.0">>}, [[], ?good_checksum, [<<"rebar3">>]]}, + {{<<"goodpkg">>,<<"1.0.1">>}, [[], ?good_checksum, [<<"rebar3">>]]}, + {{<<"goodpkg">>,<<"1.1.1">>}, [[], ?good_checksum, [<<"rebar3">>]]}, + {{<<"goodpkg">>,<<"2.0.0">>}, [[], ?good_checksum, [<<"rebar3">>]]}, {{<<"badpkg">>,<<"1.0.0">>}, [[], ?good_checksum, [<<"rebar3">>]]} ]), CacheDir = filename:join([CacheRoot, "hex", "com", "test", "packages"]), @@ -193,8 +222,8 @@ mock_config(Name, Config) -> meck:expect(rebar_dir, global_cache_dir, fun(_) -> CacheRoot end), meck:new(rebar_packages, [passthrough]), - meck:expect(rebar_packages, registry_dir, fun(_) -> CacheDir end), - meck:expect(rebar_packages, package_dir, fun(_) -> CacheDir end), + meck:expect(rebar_packages, registry_dir, fun(_) -> {ok, CacheDir} end), + meck:expect(rebar_packages, package_dir, fun(_) -> {ok, CacheDir} end), rebar_prv_update:hex_to_index(rebar_state:new()), %% Cache fetches are mocked -- we assume the server and clients are |