summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorTristan Sloughter <t@crashfast.com>2018-10-01 15:41:34 -0600
committerGitHub <noreply@github.com>2018-10-01 15:41:34 -0600
commit8bcb7da1dd294f13bc8d2040ec88f0b41b941e1b (patch)
treeb43607097dd16cdc8916ac8dfb5f045e87e906d0 /test
parent651b54fc1b90c0603b8679a693f6f69b35bacad4 (diff)
warn if the matched package is retired, skip prerelease (#1897)
retired packages are now used the same as any other but a warning will be printed when it is resolved. prerelease versions are skipped unless explicitly given as the version in the constraint or lock file.
Diffstat (limited to 'test')
-rw-r--r--test/mock_pkg_resource.erl6
-rw-r--r--test/rebar_pkg_SUITE.erl8
-rw-r--r--test/rebar_pkg_alias_SUITE.erl2
-rw-r--r--test/rebar_pkg_repos_SUITE.erl91
4 files changed, 76 insertions, 31 deletions
diff --git a/test/mock_pkg_resource.erl b/test/mock_pkg_resource.erl
index 9a31461..a169efd 100644
--- a/test/mock_pkg_resource.erl
+++ b/test/mock_pkg_resource.erl
@@ -171,7 +171,7 @@ to_index(AllDeps, Dict, Repos) ->
DKB <- [ec_cnv:to_binary(DK)],
DVB <- [ec_cnv:to_binary(DV)]],
Repo = rebar_test_utils:random_element(Repos),
- ets:insert(?PACKAGE_TABLE, #package{key={N, V, Repo},
+ ets:insert(?PACKAGE_TABLE, #package{key={N, ec_semver:parse(V), Repo},
dependencies=parse_deps(DepsList),
retired=false,
checksum = <<"checksum">>})
@@ -179,11 +179,11 @@ to_index(AllDeps, Dict, Repos) ->
lists:foreach(fun({{Name, Vsn}, _}) ->
case lists:any(fun(R) ->
- ets:member(?PACKAGE_TABLE, {ec_cnv:to_binary(Name), Vsn, R})
+ ets:member(?PACKAGE_TABLE, {ec_cnv:to_binary(Name), ec_semver:parse(Vsn), R})
end, Repos) of
false ->
Repo = rebar_test_utils:random_element(Repos),
- ets:insert(?PACKAGE_TABLE, #package{key={ec_cnv:to_binary(Name), Vsn, Repo},
+ ets:insert(?PACKAGE_TABLE, #package{key={ec_cnv:to_binary(Name), ec_semver:parse(Vsn), Repo},
dependencies=[],
retired=false,
checksum = <<"checksum">>});
diff --git a/test/rebar_pkg_SUITE.erl b/test/rebar_pkg_SUITE.erl
index 62bc4d1..b8495fd 100644
--- a/test/rebar_pkg_SUITE.erl
+++ b/test/rebar_pkg_SUITE.erl
@@ -226,13 +226,13 @@ find_highest_matching(_Config) ->
State = rebar_state:new(),
{ok, Vsn} = rebar_packages:find_highest_matching_(
<<"goodpkg">>, <<"1.0.0">>, #{name => <<"hexpm">>}, ?PACKAGE_TABLE, State),
- ?assertEqual(<<"1.0.1">>, Vsn),
+ ?assertEqual({{1,0,1},{[],[]}}, Vsn),
{ok, Vsn1} = rebar_packages:find_highest_matching(
<<"goodpkg">>, <<"1.0">>, #{name => <<"hexpm">>}, ?PACKAGE_TABLE, State),
- ?assertEqual(<<"1.1.1">>, Vsn1),
+ ?assertEqual({{1,1,1},{[],[]}}, Vsn1),
{ok, Vsn2} = rebar_packages:find_highest_matching(
<<"goodpkg">>, <<"2.0">>, #{name => <<"hexpm">>}, ?PACKAGE_TABLE, State),
- ?assertEqual(<<"2.0.0">>, Vsn2),
+ ?assertEqual({{2,0,0},{[],[]}}, Vsn2),
%% regression test. ~> constraints higher than the available packages would result
%% in returning the first package version instead of 'none'.
@@ -265,7 +265,7 @@ mock_config(Name, Config) ->
lists:foreach(fun({{N, Vsn}, [Deps, Checksum, _]}) ->
case ets:member(?PACKAGE_TABLE, {ec_cnv:to_binary(N), Vsn, <<"hexpm">>}) of
false ->
- ets:insert(?PACKAGE_TABLE, #package{key={ec_cnv:to_binary(N), Vsn, <<"hexpm">>},
+ ets:insert(?PACKAGE_TABLE, #package{key={ec_cnv:to_binary(N), ec_semver:parse(Vsn), <<"hexpm">>},
dependencies=Deps,
retired=false,
checksum=Checksum});
diff --git a/test/rebar_pkg_alias_SUITE.erl b/test/rebar_pkg_alias_SUITE.erl
index d977b64..079a3fd 100644
--- a/test/rebar_pkg_alias_SUITE.erl
+++ b/test/rebar_pkg_alias_SUITE.erl
@@ -229,7 +229,7 @@ mock_config(Name, Config) ->
lists:foreach(fun({{N, Vsn}, [Deps, Checksum, _]}) ->
case ets:member(?PACKAGE_TABLE, {ec_cnv:to_binary(N), Vsn, <<"hexpm">>}) of
false ->
- ets:insert(?PACKAGE_TABLE, #package{key={ec_cnv:to_binary(N), Vsn, <<"hexpm">>},
+ ets:insert(?PACKAGE_TABLE, #package{key={ec_cnv:to_binary(N), ec_semver:parse(Vsn), <<"hexpm">>},
dependencies=[{DAppName, {pkg, DN, DV, undefined}} || {DN, DV, _, DAppName} <- Deps],
retired=false,
checksum=Checksum});
diff --git a/test/rebar_pkg_repos_SUITE.erl b/test/rebar_pkg_repos_SUITE.erl
index 601566e..c808475 100644
--- a/test/rebar_pkg_repos_SUITE.erl
+++ b/test/rebar_pkg_repos_SUITE.erl
@@ -13,7 +13,7 @@ all() ->
groups() ->
[{resolve_version, [use_first_repo_match, use_exact_with_hash, fail_repo_update,
- ignore_match_in_excluded_repo]}].
+ ignore_match_in_excluded_repo, optional_prereleases]}].
init_per_group(resolve_version, Config) ->
Repo1 = <<"test-repo-1">>,
@@ -22,14 +22,17 @@ init_per_group(resolve_version, Config) ->
Hexpm = <<"hexpm">>,
Repos = [Repo1, Repo2, Repo3, Hexpm],
- Deps = [{"A", "0.1.1", <<"good checksum">>, Repo1},
- {"A", "0.1.1", <<"good checksum">>, Repo2},
- {"B", "1.0.0", Repo1},
- {"B", "2.0.0", Repo2},
- {"B", "1.4.0", Repo3},
- {"B", "1.4.3", Hexpm},
- {"C", "1.3.1", <<"bad checksum">>, Repo1},
- {"C", "1.3.1", <<"good checksum">>, Repo2}],
+ Deps = [{"A", "0.1.1", <<"good checksum">>, Repo1, false},
+ {"A", "0.1.1", <<"good checksum">>, Repo2, false},
+ {"B", "1.0.0", Repo1, false},
+ {"B", "2.0.0", Repo2, false},
+ {"B", "1.4.0", Repo3, false},
+ {"B", "1.4.3", Hexpm, false},
+ {"B", "1.4.6", Hexpm, #{reason => 'RETIRED_INVALID'}},
+ {"B", "1.5.0", Hexpm, false},
+ {"B", "1.5.6-rc.0", Hexpm, true},
+ {"C", "1.3.1", <<"bad checksum">>, Repo1, false},
+ {"C", "1.3.1", <<"good checksum">>, Repo2, false}],
[{deps, Deps}, {repos, Repos} | Config];
init_per_group(_, Config) ->
Config.
@@ -102,6 +105,20 @@ init_per_testcase(ignore_match_in_excluded_repo, Config) ->
fun(_State) -> true end),
[{state, State} | Config];
+init_per_testcase(optional_prereleases, Config) ->
+ Deps = ?config(deps, Config),
+ Repos = ?config(repos, Config),
+
+ State = setup_deps_and_repos(Deps, Repos),
+
+ meck:new(rebar_packages, [passthrough, no_link]),
+
+ meck:expect(rebar_packages, update_package,
+ fun(_, _, _State) -> ok end),
+ meck:expect(rebar_packages, verify_table,
+ fun(_State) -> true end),
+
+ [{state, State} | Config];
init_per_testcase(auth_merging, Config) ->
meck:new(file, [passthrough, no_link, unstick]),
meck:new(rebar_packages, [passthrough, no_link]),
@@ -120,7 +137,8 @@ end_per_testcase(Case, _Config) when Case =:= auth_merging ;
end_per_testcase(Case, _Config) when Case =:= use_first_repo_match ;
Case =:= use_exact_with_hash ;
Case =:= fail_repo_update ;
- Case =:= ignore_match_in_excluded_repo ->
+ Case =:= ignore_match_in_excluded_repo ;
+ Case =:= optional_prereleases ->
meck:unload(rebar_packages);
end_per_testcase(_, _) ->
ok.
@@ -250,14 +268,14 @@ organization_merging(_Config) ->
use_first_repo_match(Config) ->
State = ?config(state, Config),
- ?assertMatch({ok,{package,{<<"B">>, <<"2.0.0">>, Repo2},
+ ?assertMatch({ok,{package,{<<"B">>, {{2,0,0}, {[],[]}}, Repo2},
<<"some checksum">>, false, []},
#{name := Repo2,
http_adapter_config := #{profile := rebar}}},
rebar_packages:resolve_version(<<"B">>, <<"> 1.4.0">>, undefined,
?PACKAGE_TABLE, State)),
- ?assertMatch({ok,{package,{<<"B">>, <<"1.4.0">>, Repo3},
+ ?assertMatch({ok,{package,{<<"B">>, {{1,4,0}, {[],[]}}, Repo3},
<<"some checksum">>, false, []},
#{name := Repo3,
http_adapter_config := #{profile := rebar}}},
@@ -268,7 +286,7 @@ use_first_repo_match(Config) ->
use_exact_with_hash(Config) ->
State = ?config(state, Config),
- ?assertMatch({ok,{package,{<<"C">>, <<"1.3.1">>, Repo2},
+ ?assertMatch({ok,{package,{<<"C">>, {{1,3,1}, {[],[]}}, Repo2},
<<"good checksum">>, false, []},
#{name := Repo2,
http_adapter_config := #{profile := rebar}}},
@@ -278,7 +296,7 @@ use_exact_with_hash(Config) ->
fail_repo_update(Config) ->
State = ?config(state, Config),
- ?assertMatch({ok,{package,{<<"B">>, <<"1.4.0">>, Repo3},
+ ?assertMatch({ok,{package,{<<"B">>, {{1,4,0}, {[],[]}}, Repo3},
<<"some checksum">>, false, []},
#{name := Repo3,
http_adapter_config := #{profile := rebar}}},
@@ -289,24 +307,51 @@ ignore_match_in_excluded_repo(Config) ->
State = ?config(state, Config),
Repos = ?config(repos, Config),
- ?assertMatch({ok,{package,{<<"B">>, <<"1.4.3">>, Hexpm},
- <<"some checksum">>, false, []},
+ ?assertMatch({ok,{package,{<<"B">>, {{1,4,6}, {[],[]}}, Hexpm},
+ <<"some checksum">>, #{reason := 'RETIRED_INVALID'}, []},
#{name := Hexpm,
http_adapter_config := #{profile := rebar}}},
rebar_packages:resolve_version(<<"B">>, <<"~> 1.4.0">>, undefined,
?PACKAGE_TABLE, State)),
[_, Repo2 | _] = Repos,
- ?assertMatch({ok,{package,{<<"A">>, <<"0.1.1">>, Repo2},
+ ?assertMatch({ok,{package,{<<"A">>, {{0,1,1}, {[],[]}}, Repo2},
<<"good checksum">>, false, []},
#{name := Repo2,
http_adapter_config := #{profile := rebar}}},
rebar_packages:resolve_version(<<"A">>, <<"0.1.1">>, <<"good checksum">>,
?PACKAGE_TABLE, State)).
+optional_prereleases(Config) ->
+ State = ?config(state, Config),
+
+ ?assertMatch({ok,{package,{<<"B">>, {{1,5,0}, {[],[]}}, Hexpm},
+ <<"some checksum">>, false, []},
+ #{name := Hexpm,
+ http_adapter_config := #{profile := rebar}}},
+ rebar_packages:resolve_version(<<"B">>, <<"~> 1.5.0">>, undefined,
+ ?PACKAGE_TABLE, State)),
+
+ ?assertMatch({ok,{package,{<<"B">>, {{1,5,6}, {[<<"rc">>,0],[]}}, Hexpm},
+ <<"some checksum">>, true, []},
+ #{name := Hexpm,
+ http_adapter_config := #{profile := rebar}}},
+ rebar_packages:resolve_version(<<"B">>, <<"1.5.6-rc.0">>, <<"some checksum">>,
+ ?PACKAGE_TABLE, State)),
+
+ %% allow prerelease through configuration
+ State1 = rebar_state:set(State, deps_allow_prerelease, true),
+ ?assertMatch({ok,{package,{<<"B">>, {{1,5,6}, {[<<"rc">>,0],[]}}, Hexpm},
+ <<"some checksum">>, true, []},
+ #{name := Hexpm,
+ http_adapter_config := #{profile := rebar}}},
+ rebar_packages:resolve_version(<<"B">>, <<"~> 1.5.0">>, <<"some checksum">>,
+ ?PACKAGE_TABLE, State1)).
+
%%
setup_deps_and_repos(Deps, Repos) ->
+ catch ets:delete(?PACKAGE_TABLE),
true = rebar_packages:new_package_table(),
insert_deps(Deps),
State = rebar_state:new([{hex, [{repos, [#{name => R} || R <- Repos]}]}]),
@@ -314,18 +359,18 @@ setup_deps_and_repos(Deps, Repos) ->
insert_deps(Deps) ->
- lists:foreach(fun({Name, Version, Repo}) ->
+ lists:foreach(fun({Name, Version, Repo, Retired}) ->
ets:insert(?PACKAGE_TABLE, #package{key={rebar_utils:to_binary(Name),
- rebar_utils:to_binary(Version),
+ ec_semver:parse(Version),
rebar_utils:to_binary(Repo)},
dependencies=[],
- retired=false,
+ retired=Retired,
checksum = <<"some checksum">>});
- ({Name, Version, Checksum, Repo}) ->
+ ({Name, Version, Checksum, Repo, Retired}) ->
ets:insert(?PACKAGE_TABLE, #package{key={rebar_utils:to_binary(Name),
- rebar_utils:to_binary(Version),
+ ec_semver:parse(Version),
rebar_utils:to_binary(Repo)},
dependencies=[],
- retired=false,
+ retired=Retired,
checksum = Checksum})
end, Deps).