Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

112 rader
5.7 KiB

  1. %%% Most locking tests are implicit in other test suites handling
  2. %%% dependencies.
  3. %%% This suite is to test the compatibility layers between various
  4. %%% versions of lockfiles.
  5. -module(rebar_lock_SUITE).
  6. -compile(export_all).
  7. -include_lib("common_test/include/ct.hrl").
  8. -include_lib("eunit/include/eunit.hrl").
  9. all() -> [current_version,
  10. beta_version, future_versions_no_attrs, future_versions_attrs].
  11. current_version(Config) ->
  12. %% Current version just dumps the locks as is on disk.
  13. LockFile = filename:join(?config(priv_dir, Config), "current_version"),
  14. Locks = [{<<"app1">>, {git,"some_url", {ref,"some_ref"}}, 2},
  15. {<<"app2">>, {git,"some_url", {ref,"some_ref"}}, 0},
  16. {<<"app3">>, {hg,"some_url", {ref,"some_ref"}}, 1},
  17. {<<"pkg1">>,{pkg,<<"name">>,<<"0.1.6">>},3},
  18. {<<"pkg2">>,{pkg,<<"name1">>,<<"1.1.6">>},2},
  19. {<<"pkg3">>,{pkg,<<"name2">>,<<"3.0.6">>},1}
  20. ],
  21. ExpandedNull = [
  22. {<<"app1">>, {git,"some_url", {ref,"some_ref"}}, 2},
  23. {<<"app2">>, {git,"some_url", {ref,"some_ref"}}, 0},
  24. {<<"app3">>, {hg,"some_url", {ref,"some_ref"}}, 1},
  25. {<<"pkg1">>,{pkg,<<"name">>,<<"0.1.6">>,undefined},3},
  26. {<<"pkg2">>,{pkg,<<"name1">>,<<"1.1.6">>,undefined},2},
  27. {<<"pkg3">>,{pkg,<<"name2">>,<<"3.0.6">>,undefined},1}
  28. ],
  29. %% Simulate a beta lockfile
  30. file:write_file(LockFile, io_lib:format("~p.~n", [Locks])),
  31. %% No properties fetched from a beta lockfile, expand locks
  32. %% to undefined
  33. ?assertEqual(ExpandedNull,
  34. rebar_config:consult_lock_file(LockFile)),
  35. %% Adding hash data
  36. Hashes = [{<<"pkg1">>, <<"tarballhash">>},
  37. {<<"pkg3">>, <<"otherhash">>}],
  38. ExpandedLocks = [
  39. {<<"app1">>, {git,"some_url", {ref,"some_ref"}}, 2},
  40. {<<"app2">>, {git,"some_url", {ref,"some_ref"}}, 0},
  41. {<<"app3">>, {hg,"some_url", {ref,"some_ref"}}, 1},
  42. {<<"pkg1">>,{pkg,<<"name">>,<<"0.1.6">>,<<"tarballhash">>},3},
  43. {<<"pkg2">>,{pkg,<<"name1">>,<<"1.1.6">>,undefined},2},
  44. {<<"pkg3">>,{pkg,<<"name2">>,<<"3.0.6">>,<<"otherhash">>},1}
  45. ],
  46. file:write_file(LockFile,
  47. io_lib:format("~p.~n~p.~n",
  48. [{"1.1.0", Locks},
  49. [{pkg_hash, Hashes}]])),
  50. ?assertEqual(ExpandedLocks, rebar_config:consult_lock_file(LockFile)),
  51. %% Then check that we can reverse that
  52. ok = rebar_config:write_lock_file(LockFile, ExpandedLocks),
  53. ?assertEqual({ok, [{"1.1.0", Locks}, [{pkg_hash, Hashes}]]},
  54. file:consult(LockFile)).
  55. beta_version(Config) ->
  56. %% Current version just dumps the locks as is on disk.
  57. LockFile = filename:join(?config(priv_dir, Config), "current_version"),
  58. Locks = [{<<"app1">>, {git,"some_url", {ref,"some_ref"}}, 2},
  59. {<<"app2">>, {git,"some_url", {ref,"some_ref"}}, 0},
  60. {<<"app3">>, {hg,"some_url", {ref,"some_ref"}}, 1},
  61. {<<"pkg1">>,{pkg,<<"name">>,<<"0.1.6">>},3}],
  62. ExpandedLocks = [
  63. {<<"app1">>, {git,"some_url", {ref,"some_ref"}}, 2},
  64. {<<"app2">>, {git,"some_url", {ref,"some_ref"}}, 0},
  65. {<<"app3">>, {hg,"some_url", {ref,"some_ref"}}, 1},
  66. {<<"pkg1">>,{pkg,<<"name">>,<<"0.1.6">>,undefined},3}
  67. ],
  68. file:write_file(LockFile, io_lib:format("~p.~n", [Locks])),
  69. ?assertEqual(ExpandedLocks, rebar_config:consult_lock_file(LockFile)).
  70. future_versions_no_attrs(Config) ->
  71. %% Future versions will keep the same core attribute in there, but
  72. %% will do so under a new format bundled with a version and potentially
  73. %% some trailing attributes
  74. LockFile = filename:join(?config(priv_dir, Config), "future_versions"),
  75. Locks = [{<<"app1">>, {git,"some_url", {ref,"some_ref"}}, 2},
  76. {<<"app2">>, {git,"some_url", {ref,"some_ref"}}, 0},
  77. {<<"app3">>, {hg,"some_url", {ref,"some_ref"}}, 1},
  78. {<<"pkg1">>, {pkg,<<"name">>,<<"0.1.6">>},3}],
  79. ExpandedLocks = [{<<"app1">>, {git,"some_url", {ref,"some_ref"}}, 2},
  80. {<<"app2">>, {git,"some_url", {ref,"some_ref"}}, 0},
  81. {<<"app3">>, {hg,"some_url", {ref,"some_ref"}}, 1},
  82. {<<"pkg1">>, {pkg,<<"name">>,<<"0.1.6">>,undefined},3}],
  83. LockData = {"3.5.2", Locks},
  84. file:write_file(LockFile, io_lib:format("~p.~n", [LockData])),
  85. ?assertEqual(ExpandedLocks, rebar_config:consult_lock_file(LockFile)).
  86. future_versions_attrs(Config) ->
  87. %% Future versions will keep the same core attribute in there, but
  88. %% will do so under a new format bundled with a version and potentially
  89. %% some trailing attributes
  90. LockFile = filename:join(?config(priv_dir, Config), "future_versions"),
  91. Locks = [{<<"app1">>, {git,"some_url", {ref,"some_ref"}}, 2},
  92. {<<"app2">>, {git,"some_url", {ref,"some_ref"}}, 0},
  93. {<<"app3">>, {hg,"some_url", {ref,"some_ref"}}, 1},
  94. {<<"pkg1">>,{pkg,<<"name">>,<<"0.1.6">>},3}],
  95. ExpandedLocks = [{<<"app1">>, {git,"some_url", {ref,"some_ref"}}, 2},
  96. {<<"app2">>, {git,"some_url", {ref,"some_ref"}}, 0},
  97. {<<"app3">>, {hg,"some_url", {ref,"some_ref"}}, 1},
  98. {<<"pkg1">>,{pkg,<<"name">>,<<"0.1.6">>, <<"tarballhash">>},3}],
  99. Hashes = [{<<"pkg1">>, <<"tarballhash">>}],
  100. LockData = {"3.5.2", Locks},
  101. file:write_file(LockFile,
  102. io_lib:format("~p.~n~p.~ngarbage.~n",
  103. [LockData,
  104. [{a, x},
  105. {pkg_hash, Hashes},
  106. {b, y}]])),
  107. ?assertEqual(ExpandedLocks, rebar_config:consult_lock_file(LockFile)).