summaryrefslogtreecommitdiff
path: root/test/rebar_upgrade_SUITE.erl
diff options
context:
space:
mode:
Diffstat (limited to 'test/rebar_upgrade_SUITE.erl')
-rw-r--r--test/rebar_upgrade_SUITE.erl118
1 files changed, 115 insertions, 3 deletions
diff --git a/test/rebar_upgrade_SUITE.erl b/test/rebar_upgrade_SUITE.erl
index 1dc0af2..79cf29e 100644
--- a/test/rebar_upgrade_SUITE.erl
+++ b/test/rebar_upgrade_SUITE.erl
@@ -3,14 +3,14 @@
-include_lib("eunit/include/eunit.hrl").
-compile(export_all).
-all() -> [{group, git}, {group, pkg}].
+all() -> [{group, git}, {group, pkg}, novsn_pkg].
groups() ->
[{all, [], [top_a, top_b, top_c, top_d1, top_d2, top_e,
pair_a, pair_b, pair_ab, pair_c, pair_all,
triplet_a, triplet_b, triplet_c,
tree_a, tree_b, tree_c, tree_c2, tree_ac, tree_all,
- delete_d, promote]},
+ delete_d, promote, stable_lock, fwd_lock]},
{git, [], [{group, all}]},
{pkg, [], [{group, all}]}].
@@ -31,6 +31,26 @@ init_per_group(_, Config) ->
end_per_group(_, Config) ->
Config.
+init_per_testcase(novsn_pkg, Config0) ->
+ Config = rebar_test_utils:init_rebar_state(Config0, "novsn_pkg_"),
+ AppDir = ?config(apps, Config),
+ RebarConf = rebar_test_utils:create_config(AppDir, [{deps, [fakeapp]}]),
+
+ Deps = [{{<<"fakeapp">>, <<"1.0.0">>}, []}],
+ UpDeps = [{{<<"fakeapp">>, <<"1.1.0">>}, []}],
+ Upgrades = ["fakeapp"],
+
+ [{rebarconfig, RebarConf},
+ {mock, fun() ->
+ catch mock_pkg_resource:unmock(),
+ mock_pkg_resource:mock([{pkgdeps, Deps}, {upgrade, []}])
+ end},
+ {mock_update, fun() ->
+ catch mock_pkg_resource:unmock(),
+ mock_pkg_resource:mock([{pkgdeps, UpDeps}, {upgrade, Upgrades}])
+ end},
+ {expected, {ok, [{dep, "fakeapp", "1.1.0"}, {lock, "fakeapp", "1.1.0"}]}}
+ | Config];
init_per_testcase(Case, Config) ->
DepsType = ?config(deps_type, Config),
{Deps, UpDeps, ToUp, Expectations} = upgrades(Case),
@@ -361,7 +381,30 @@ upgrades(promote) ->
{"C", "3", []}
],
["A","B","C","D"],
- {"C", [{"A","1"},{"C","3"},{"B","1"},{"D","1"}]}}.
+ {"C", [{"A","1"},{"C","3"},{"B","1"},{"D","1"}]}};
+upgrades(stable_lock) ->
+ {[{"A", "1", [{"C", "1", []}]},
+ {"B", "1", [{"D", "1", []}]}
+ ], % lock after this
+ [{"A", "2", [{"C", "2", []}]},
+ {"B", "2", [{"D", "2", []}]}
+ ],
+ [],
+ %% Run a regular lock and no app should be upgraded
+ {"any", [{"A","1"},{"C","1"},{"B","1"},{"D","1"}]}};
+upgrades(fwd_lock) ->
+ {[{"A", "1", [{"C", "1", []}]},
+ {"B", "1", [{"D", "1", []}]}
+ ],
+ [{"A", "2", [{"C", "2", []}]},
+ {"B", "2", [{"D", "2", []}]}
+ ],
+ ["A","B","C","D"],
+ %% For this one, we should build, rewrite the lock
+ %% file to include the result post-upgrade, and then
+ %% run a regular lock to see that the lock file is respected
+ %% in deps.
+ {"any", [{"A","2"},{"C","2"},{"B","2"},{"D","2"}]}}.
%% TODO: add a test that verifies that unlocking files and then
%% running the upgrade code is enough to properly upgrade things.
@@ -435,6 +478,46 @@ delete_d(Config) ->
?assertNotEqual([],
[1 || {"App ~ts is no longer needed and can be deleted.",
[<<"D">>]} <- Infos]).
+
+stable_lock(Config) ->
+ apply(?config(mock, Config), []),
+ {ok, RebarConfig} = file:consult(?config(rebarconfig, Config)),
+ %% Install dependencies before re-mocking for an upgrade
+ rebar_test_utils:run_and_check(Config, RebarConfig, ["lock"], {ok, []}),
+ {App, Unlocks} = ?config(expected, Config),
+ ct:pal("Upgrades: ~p -> ~p", [App, Unlocks]),
+ Expectation = case Unlocks of
+ {error, Term} -> {error, Term};
+ _ -> {ok, Unlocks}
+ end,
+ apply(?config(mock_update, Config), []),
+ NewRebarConf = rebar_test_utils:create_config(?config(apps, Config),
+ [{deps, ?config(next_top_deps, Config)}]),
+ {ok, NewRebarConfig} = file:consult(NewRebarConf),
+ rebar_test_utils:run_and_check(
+ Config, NewRebarConfig, ["lock", App], Expectation
+ ).
+
+fwd_lock(Config) ->
+ apply(?config(mock, Config), []),
+ {ok, RebarConfig} = file:consult(?config(rebarconfig, Config)),
+ %% Install dependencies before re-mocking for an upgrade
+ rebar_test_utils:run_and_check(Config, RebarConfig, ["lock"], {ok, []}),
+ {App, Unlocks} = ?config(expected, Config),
+ ct:pal("Upgrades: ~p -> ~p", [App, Unlocks]),
+ Expectation = case Unlocks of
+ {error, Term} -> {error, Term};
+ _ -> {ok, Unlocks}
+ end,
+ rewrite_locks(Expectation, Config),
+ apply(?config(mock_update, Config), []),
+ NewRebarConf = rebar_test_utils:create_config(?config(apps, Config),
+ [{deps, ?config(next_top_deps, Config)}]),
+ {ok, NewRebarConfig} = file:consult(NewRebarConf),
+ rebar_test_utils:run_and_check(
+ Config, NewRebarConfig, ["lock", App], Expectation
+ ).
+
run(Config) ->
apply(?config(mock, Config), []),
{ok, RebarConfig} = file:consult(?config(rebarconfig, Config)),
@@ -453,3 +536,32 @@ run(Config) ->
rebar_test_utils:run_and_check(
Config, NewRebarConfig, ["upgrade", App], Expectation
).
+
+novsn_pkg(Config) ->
+ apply(?config(mock, Config), []),
+ {ok, RebarConfig} = file:consult(?config(rebarconfig, Config)),
+ %% Install dependencies before re-mocking for an upgrade
+ rebar_test_utils:run_and_check(Config, RebarConfig, ["lock"], {ok, []}),
+ Expectation = ?config(expected, Config),
+ apply(?config(mock_update, Config), []),
+ rebar_test_utils:run_and_check(
+ Config, RebarConfig, ["upgrade"], Expectation
+ ),
+ ok.
+
+rewrite_locks({ok, Expectations}, Config) ->
+ AppDir = ?config(apps, Config),
+ LockFile = filename:join([AppDir, "rebar.lock"]),
+ {ok, [Locks]} = file:consult(LockFile),
+ ExpLocks = [{list_to_binary(Name), Vsn}
+ || {lock, Name, Vsn} <- Expectations],
+ NewLocks = lists:foldl(
+ fun({App, {pkg, Name, _}, Lvl}, Acc) ->
+ Vsn = list_to_binary(proplists:get_value(App,ExpLocks)),
+ [{App, {pkg, Name, Vsn}, Lvl} | Acc]
+ ; ({App, {git, URL, {ref, _}}, Lvl}, Acc) ->
+ Vsn = proplists:get_value(App,ExpLocks),
+ [{App, {git, URL, {ref, Vsn}}, Lvl} | Acc]
+ end, [], Locks),
+ ct:pal("rewriting locks from ~p to~n~p", [Locks, NewLocks]),
+ file:write_file(LockFile, io_lib:format("~p.~n", [NewLocks])).