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.

115 rivejä
6.0 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, undefined},3},
  26. {<<"pkg2">>,{pkg,<<"name1">>,<<"1.1.6">>,undefined, undefined},2},
  27. {<<"pkg3">>,{pkg,<<"name2">>,<<"3.0.6">>,undefined, 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. ExtHashes = [{<<"pkg1">>, <<"outer_tarballhash">>},
  39. {<<"pkg3">>, <<"outer_otherhash">>}],
  40. ExpandedLocks = [
  41. {<<"app1">>, {git,"some_url", {ref,"some_ref"}}, 2},
  42. {<<"app2">>, {git,"some_url", {ref,"some_ref"}}, 0},
  43. {<<"app3">>, {hg,"some_url", {ref,"some_ref"}}, 1},
  44. {<<"pkg1">>,{pkg,<<"name">>,<<"0.1.6">>,<<"tarballhash">>, <<"outer_tarballhash">>},3},
  45. {<<"pkg2">>,{pkg,<<"name1">>,<<"1.1.6">>,undefined, undefined},2},
  46. {<<"pkg3">>,{pkg,<<"name2">>,<<"3.0.6">>,<<"otherhash">>, <<"outer_otherhash">>},1}
  47. ],
  48. file:write_file(LockFile,
  49. io_lib:format("~p.~n~p.~n",
  50. [{"1.2.0", Locks},
  51. [{pkg_hash, Hashes}, {pkg_hash_ext, ExtHashes}]])),
  52. ?assertEqual(ExpandedLocks, rebar_config:consult_lock_file(LockFile)),
  53. %% Then check that we can reverse that
  54. ok = rebar_config:write_lock_file(LockFile, ExpandedLocks),
  55. ?assertEqual({ok, [{"1.2.0", Locks}, [{pkg_hash, Hashes}, {pkg_hash_ext, ExtHashes}]]},
  56. file:consult(LockFile)).
  57. beta_version(Config) ->
  58. %% Current version just dumps the locks as is on disk.
  59. LockFile = filename:join(?config(priv_dir, Config), "current_version"),
  60. Locks = [{<<"app1">>, {git,"some_url", {ref,"some_ref"}}, 2},
  61. {<<"app2">>, {git,"some_url", {ref,"some_ref"}}, 0},
  62. {<<"app3">>, {hg,"some_url", {ref,"some_ref"}}, 1},
  63. {<<"pkg1">>,{pkg,<<"name">>,<<"0.1.6">>},3}],
  64. ExpandedLocks = [
  65. {<<"app1">>, {git,"some_url", {ref,"some_ref"}}, 2},
  66. {<<"app2">>, {git,"some_url", {ref,"some_ref"}}, 0},
  67. {<<"app3">>, {hg,"some_url", {ref,"some_ref"}}, 1},
  68. {<<"pkg1">>,{pkg,<<"name">>,<<"0.1.6">>,undefined, undefined},3}
  69. ],
  70. file:write_file(LockFile, io_lib:format("~p.~n", [Locks])),
  71. ?assertEqual(ExpandedLocks, rebar_config:consult_lock_file(LockFile)).
  72. future_versions_no_attrs(Config) ->
  73. %% Future versions will keep the same core attribute in there, but
  74. %% will do so under a new format bundled with a version and potentially
  75. %% some trailing attributes
  76. LockFile = filename:join(?config(priv_dir, Config), "future_versions"),
  77. Locks = [{<<"app1">>, {git,"some_url", {ref,"some_ref"}}, 2},
  78. {<<"app2">>, {git,"some_url", {ref,"some_ref"}}, 0},
  79. {<<"app3">>, {hg,"some_url", {ref,"some_ref"}}, 1},
  80. {<<"pkg1">>, {pkg,<<"name">>,<<"0.1.6">>},3}],
  81. ExpandedLocks = [{<<"app1">>, {git,"some_url", {ref,"some_ref"}}, 2},
  82. {<<"app2">>, {git,"some_url", {ref,"some_ref"}}, 0},
  83. {<<"app3">>, {hg,"some_url", {ref,"some_ref"}}, 1},
  84. {<<"pkg1">>, {pkg,<<"name">>,<<"0.1.6">>,undefined, undefined},3}],
  85. LockData = {"3.5.2", Locks},
  86. file:write_file(LockFile, io_lib:format("~p.~n", [LockData])),
  87. ?assertEqual(ExpandedLocks, rebar_config:consult_lock_file(LockFile)).
  88. future_versions_attrs(Config) ->
  89. %% Future versions will keep the same core attribute in there, but
  90. %% will do so under a new format bundled with a version and potentially
  91. %% some trailing attributes
  92. LockFile = filename:join(?config(priv_dir, Config), "future_versions"),
  93. Locks = [{<<"app1">>, {git,"some_url", {ref,"some_ref"}}, 2},
  94. {<<"app2">>, {git,"some_url", {ref,"some_ref"}}, 0},
  95. {<<"app3">>, {hg,"some_url", {ref,"some_ref"}}, 1},
  96. {<<"pkg1">>,{pkg,<<"name">>,<<"0.1.6">>},3}],
  97. ExpandedLocks = [{<<"app1">>, {git,"some_url", {ref,"some_ref"}}, 2},
  98. {<<"app2">>, {git,"some_url", {ref,"some_ref"}}, 0},
  99. {<<"app3">>, {hg,"some_url", {ref,"some_ref"}}, 1},
  100. {<<"pkg1">>,{pkg,<<"name">>,<<"0.1.6">>, <<"tarballhash">>, <<"outer_tarballhash">>},3}],
  101. Hashes = [{<<"pkg1">>, <<"tarballhash">>}],
  102. ExtHashes = [{<<"pkg1">>, <<"outer_tarballhash">>}],
  103. LockData = {"3.5.2", Locks},
  104. file:write_file(LockFile,
  105. io_lib:format("~p.~n~p.~ngarbage.~n",
  106. [LockData,
  107. [{a, x},
  108. {pkg_hash, Hashes},{pkg_hash_ext, ExtHashes},
  109. {b, y}]])),
  110. ?assertEqual(ExpandedLocks, rebar_config:consult_lock_file(LockFile)).