summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorFred Hebert <mononcqc@ferd.ca>2015-02-23 22:57:34 +0000
committerFred Hebert <mononcqc@ferd.ca>2015-02-23 23:05:59 +0000
commitc283dd2c69174586e5964654a5fec8eeb66f6b6c (patch)
treefc96c62215eb008cc3ef4382ef6a67efa6c571f8 /test
parent249be4985c130f8cc096033e2aa8305b99817aa5 (diff)
Add tests and fixes for packages upgrades
- Track level of packages properly, they're not level 0 anymore (this could yield an issue where a src dep takes precedence over a pkg dep) - Proper stable sort of vertices in the digraph module - PkgDeps no longer 'see themselves' when fetching and upgrading after locking themselves - Pkg Locks are added to pkg deps rather than source deps - Updating test cases to support pkg mocking on top of src mocking
Diffstat (limited to 'test')
-rw-r--r--test/mock_pkg_resource.erl4
-rw-r--r--test/rebar_test_utils.erl3
-rw-r--r--test/rebar_upgrade_SUITE.erl21
3 files changed, 20 insertions, 8 deletions
diff --git a/test/mock_pkg_resource.erl b/test/mock_pkg_resource.erl
index c7276b6..a22d1b0 100644
--- a/test/mock_pkg_resource.erl
+++ b/test/mock_pkg_resource.erl
@@ -47,11 +47,11 @@ mock_lock(_) ->
%% @doc The config passed to the `mock/2' function can specify which apps
%% should be updated on a per-name basis: `{update, ["App1", "App3"]}'.
mock_update(Opts) ->
- ToUpdate = proplists:get_value(update, Opts, []),
+ ToUpdate = proplists:get_value(upgrade, Opts, []),
meck:expect(
?MOD, needs_update,
fun(_Dir, {pkg, App, _Vsn}) ->
- lists:member(App, ToUpdate)
+ lists:member(binary_to_list(App), ToUpdate)
end).
%% @doc Replicated an unsupported call.
diff --git a/test/rebar_test_utils.erl b/test/rebar_test_utils.erl
index e1fb050..a036619 100644
--- a/test/rebar_test_utils.erl
+++ b/test/rebar_test_utils.erl
@@ -205,6 +205,9 @@ check_results(AppDir, Expected) ->
case lists:keyfind(iolist_to_binary(Name), 1, Locks) of
false ->
error({lock_not_found, Name});
+ {_LockName, {pkg, _, LockVsn}, _} ->
+ ?assertEqual(iolist_to_binary(Vsn),
+ iolist_to_binary(LockVsn));
{_LockName, {_, _, {ref, LockVsn}}, _} ->
?assertEqual(iolist_to_binary(Vsn),
iolist_to_binary(LockVsn))
diff --git a/test/rebar_upgrade_SUITE.erl b/test/rebar_upgrade_SUITE.erl
index f35ebb9..14186be 100644
--- a/test/rebar_upgrade_SUITE.erl
+++ b/test/rebar_upgrade_SUITE.erl
@@ -3,7 +3,7 @@
-include_lib("eunit/include/eunit.hrl").
-compile(export_all).
-all() -> [{group, git}].%, {group, pkg}].
+all() -> [{group, git}, {group, pkg}].
groups() ->
[{all, [], [top_a, top_b, top_c, top_d1, top_d2, top_e,
@@ -38,7 +38,7 @@ init_per_testcase(Case, Config) ->
UpExpanded = rebar_test_utils:expand_deps(DepsType, UpDeps),
[{expected, normalize_unlocks(Expectations)},
{mock, fun() -> mock_deps(DepsType, Expanded, []) end},
- {mock_update, fun() -> mock_deps(DepsType, UpExpanded, ToUp) end}
+ {mock_update, fun() -> mock_deps(DepsType, Expanded, UpExpanded, ToUp) end}
| setup_project(Case, Config, Expanded, UpExpanded)].
end_per_testcase(_, Config) ->
@@ -206,7 +206,7 @@ upgrades(triplet_b) ->
{"G",[]}]},
{"C", "0", [{"H","3",[]},
{"I",[]}]}],
- [{"A", "1", [{"D",[]},
+ [{"A", "2", [{"D",[]},
{"E","2",[]}]},
{"B", "1", [{"F","1",[]},
{"G",[]}]},
@@ -223,7 +223,7 @@ upgrades(triplet_c) ->
{"G",[]}]},
{"C", "0", [{"H","3",[]},
{"I",[]}]}],
- [{"A", "1", [{"D",[]},
+ [{"A", "2", [{"D",[]},
{"E","2",[]}]},
{"B", "1", [{"F","1",[]},
{"G",[]}]},
@@ -245,7 +245,7 @@ upgrades(tree_a) ->
{"E",[{"I","1",[]}]}]},
{"B", "1", [{"F",[]},
{"G",[]}]},
- {"C", "1", [{"H",[]}]}
+ {"C", "2", [{"H",[]}]}
],
["C"],
{"A", [{"A","1"}, "D", "J", "E",
@@ -263,7 +263,7 @@ upgrades(tree_b) ->
{"E",[{"I","1",[]}]}]},
{"B", "1", [{"F",[]},
{"G",[]}]},
- {"C", "1", [{"H",[]}]}
+ {"C", "2", [{"H",[]}]}
],
["C"],
{"B", [{"A","1"}, "D", "J", "E",
@@ -363,6 +363,15 @@ mock_deps(pkg, Deps, Upgrades) ->
catch mock_pkg_resource:unmock(),
mock_pkg_resource:mock([{pkgdeps, rebar_test_utils:flat_pkgdeps(Deps)}, {upgrade, Upgrades}]).
+mock_deps(git, _OldDeps, Deps, Upgrades) ->
+ catch mock_git_resource:unmock(),
+ mock_git_resource:mock([{deps, rebar_test_utils:flat_deps(Deps)}, {upgrade, Upgrades}]);
+mock_deps(pkg, OldDeps, Deps, Upgrades) ->
+ Merged = Deps ++ [Dep || Dep <- OldDeps,
+ not lists:keymember(element(1, Dep), 1, Deps)],
+ catch mock_pkg_resource:unmock(),
+ mock_pkg_resource:mock([{pkgdeps, rebar_test_utils:flat_pkgdeps(Merged)}, {upgrade, Upgrades}]).
+
normalize_unlocks({App, Locks}) ->
{iolist_to_binary(App),
normalize_unlocks_expect(Locks)};