Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

77 Zeilen
3.1 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", 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. rebar_test_utils:run_and_check(Config, [], ["unlock", "uuid"], {ok, []}),
  41. ?assertEqual(Locks -- ["uuid"], read_locks(Config)),
  42. rebar_test_utils:run_and_check(Config, [], ["unlock", "gproc,itc"], {ok, []}),
  43. ?assertEqual(Locks -- ["uuid","gproc","itc"], read_locks(Config)),
  44. rebar_test_utils:run_and_check(Config, [], ["unlock", string:join(Locks,",")], {ok, []}),
  45. ?assertEqual({error, enoent}, read_locks(Config)),
  46. ok.
  47. unlock_all(Config) ->
  48. [_|_] = read_locks(Config),
  49. rebar_test_utils:run_and_check(Config, [], ["unlock"], {ok, []}),
  50. ?assertEqual({error, enoent}, read_locks(Config)),
  51. ok.
  52. read_locks(Config) ->
  53. case file:consult(?config(lockfile, Config)) of
  54. {ok, _} ->
  55. Locks = rebar_config:consult_lock_file(?config(lockfile, Config)),
  56. [binary_to_list(element(1,Lock)) || Lock <- Locks];
  57. Other ->
  58. Other
  59. end.
  60. read_hashes(Config) ->
  61. case file:consult(?config(lockfile, Config)) of
  62. {ok, [{_Vsn, _Locks},Props|_]} ->
  63. Hashes = proplists:get_value(pkg_hash, Props, []),
  64. [binary_to_list(element(1,Hash)) || Hash <- Hashes];
  65. {ok, [{_Vsn, _Locks}]} ->
  66. [];
  67. Other ->
  68. Other
  69. end.