You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

80 line
3.4 KiB

  1. -module(rebar_unlock_SUITE).
  2. -include_lib("common_test/include/ct.hrl").
  3. -include_lib("eunit/include/eunit.hrl").
  4. -compile(export_all).
  5. all() -> [pkgunlock, unlock, unlock_all].
  6. init_per_testcase(pkgunlock, Config0) ->
  7. Config = rebar_test_utils:init_rebar_state(Config0, "pkgunlock"),
  8. Lockfile = filename:join(?config(apps, Config), "rebar.lock"),
  9. ec_file:copy(filename:join(?config(data_dir, Config), "pkg.rebar.lock"),
  10. Lockfile),
  11. [{lockfile, Lockfile} | Config];
  12. init_per_testcase(Case, Config0) ->
  13. Config = rebar_test_utils:init_rebar_state(Config0, atom_to_list(Case)),
  14. Lockfile = filename:join(?config(apps, Config), "rebar.lock"),
  15. ec_file:copy(filename:join(?config(data_dir, Config), "rebar.lock"),
  16. Lockfile),
  17. [{lockfile, Lockfile} | Config].
  18. end_per_testcase(_, Config) ->
  19. Config.
  20. pkgunlock(Config) ->
  21. Locks = read_locks(Config),
  22. Hashes = read_hashes(Config),
  23. rebar_test_utils:run_and_check(Config, [], ["unlock", "fakeapp"], {ok, []}),
  24. Locks = read_locks(Config),
  25. Hashes = read_hashes(Config),
  26. rebar_test_utils:run_and_check(Config, [], ["unlock", "bbmustache"], {ok, []}),
  27. ?assertEqual(Locks -- ["bbmustache"], read_locks(Config)),
  28. ?assertEqual(Hashes -- ["bbmustache"], read_hashes(Config)),
  29. rebar_test_utils:run_and_check(Config, [], ["unlock", "cf,certifi"], {ok, []}),
  30. ?assertEqual(Locks -- ["bbmustache","cf","certifi"], read_locks(Config)),
  31. ?assertEqual(Hashes -- ["bbmustache","cf","certifi"], read_hashes(Config)),
  32. rebar_test_utils:run_and_check(Config, [], ["unlock", rebar_string:join(Locks,",")], {ok, []}),
  33. ?assertEqual({error, enoent}, read_locks(Config)),
  34. ?assertEqual({error, enoent}, read_hashes(Config)),
  35. ok.
  36. unlock(Config) ->
  37. Locks = read_locks(Config),
  38. rebar_test_utils:run_and_check(Config, [], ["unlock", "fakeapp"], {ok, []}),
  39. Locks = read_locks(Config),
  40. {ok, State} = rebar_test_utils:run_and_check(Config, [], ["unlock", "uuid"], return),
  41. ?assertEqual(Locks -- ["uuid"], read_locks(Config)),
  42. ?assert(false =:= lists:keyfind(<<"uuid">>, 1, rebar_state:get(State, {locks, default}))),
  43. ?assert(false =/= lists:keyfind(<<"itc">>, 1, rebar_state:get(State, {locks, default}))),
  44. rebar_test_utils:run_and_check(Config, [], ["unlock", "gproc,itc"], {ok, []}),
  45. ?assertEqual(Locks -- ["uuid","gproc","itc"], read_locks(Config)),
  46. rebar_test_utils:run_and_check(Config, [], ["unlock", rebar_string:join(Locks,",")], {ok, []}),
  47. ?assertEqual({error, enoent}, read_locks(Config)),
  48. ok.
  49. unlock_all(Config) ->
  50. [_|_] = read_locks(Config),
  51. {ok, State} = rebar_test_utils:run_and_check(Config, [], ["unlock"], return),
  52. ?assertEqual({error, enoent}, read_locks(Config)),
  53. ?assertEqual([], rebar_state:get(State, {locks, default})),
  54. ok.
  55. read_locks(Config) ->
  56. case file:consult(?config(lockfile, Config)) of
  57. {ok, _} ->
  58. Locks = rebar_config:consult_lock_file(?config(lockfile, Config)),
  59. [binary_to_list(element(1,Lock)) || Lock <- Locks];
  60. Other ->
  61. Other
  62. end.
  63. read_hashes(Config) ->
  64. case file:consult(?config(lockfile, Config)) of
  65. {ok, [{_Vsn, _Locks},Props|_]} ->
  66. Hashes = proplists:get_value(pkg_hash, Props, []),
  67. [binary_to_list(element(1,Hash)) || Hash <- Hashes];
  68. {ok, [{_Vsn, _Locks}]} ->
  69. [];
  70. Other ->
  71. Other
  72. end.