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.

74 lines
4.3 KiB

  1. %%% This suite currently only tests for options parsing since we do
  2. %%% not know if epmd will be running to actually boot nodes.
  3. -module(rebar_dist_utils_SUITE).
  4. -include_lib("common_test/include/ct.hrl").
  5. -include_lib("eunit/include/eunit.hrl").
  6. -compile(export_all).
  7. all() -> [from_config, from_cli, overlap, from_config_profile].
  8. init_per_testcase(_, Config0) ->
  9. Config = rebar_test_utils:init_rebar_state(Config0),
  10. AppDir = ?config(apps, Config),
  11. Name = rebar_test_utils:create_random_name("app_"),
  12. Vsn = rebar_test_utils:create_random_vsn(),
  13. rebar_test_utils:create_app(filename:join([AppDir,"apps",Name]), Name, Vsn, [kernel, stdlib]),
  14. Config.
  15. end_per_testcase(_, _) ->
  16. ok.
  17. from_config(Config) ->
  18. ShortConfig = [{dist_node, [{sname, 'a@localhost'}, {setcookie, abc}]}],
  19. LongConfig = [{dist_node, [{name, 'a@localhost.x'}, {setcookie, abc}]}],
  20. BothConfig = [{dist_node, [{sname, 'a@localhost'}, {name, 'a@localhost.x'}, {setcookie,abc}]}],
  21. NoConfig = [],
  22. CookieConfig = [{dist_node, [{setcookie, def}]}],
  23. NoCookie = [{dist_node, [{sname, 'a@localhost'}]}],
  24. {ok, State0} = rebar_test_utils:run_and_check(Config, ShortConfig, ["version"], return),
  25. {undefined, 'a@localhost', [{setcookie, abc}]} = rebar_dist_utils:find_options(State0),
  26. {ok, State1} = rebar_test_utils:run_and_check(Config, LongConfig, ["version"], return),
  27. {'a@localhost.x', undefined, [{setcookie, abc}]} = rebar_dist_utils:find_options(State1),
  28. %% only support the first name found, side-effect of wanting profile support
  29. {ok, State2} = rebar_test_utils:run_and_check(Config, BothConfig, ["version"], return),
  30. {undefined, 'a@localhost', [{setcookie, abc}]} = rebar_dist_utils:find_options(State2),
  31. {ok, State3} = rebar_test_utils:run_and_check(Config, NoConfig, ["version"], return),
  32. {undefined, undefined, []} = rebar_dist_utils:find_options(State3),
  33. {ok, State4} = rebar_test_utils:run_and_check(Config, CookieConfig, ["version"], return),
  34. {undefined, undefined, [{setcookie, def}]} = rebar_dist_utils:find_options(State4),
  35. {ok, State5} = rebar_test_utils:run_and_check(Config, NoCookie, ["version"], return),
  36. {undefined, 'a@localhost', []} = rebar_dist_utils:find_options(State5),
  37. ok.
  38. from_cli(Config) ->
  39. {ok, State0} = rebar_test_utils:run_and_check(Config, [], ["version"], return),
  40. {undefined, undefined, []} = rebar_dist_utils:find_options(State0),
  41. State1 = rebar_state:command_parsed_args(State0, {[{sname, 'a@localhost'}, {setcookie,abc}], []}),
  42. {undefined, 'a@localhost', [{setcookie, abc}]} = rebar_dist_utils:find_options(State1),
  43. State2 = rebar_state:command_parsed_args(State0, {[{name, 'a@localhost.x'}, {setcookie,abc}], []}),
  44. {'a@localhost.x', undefined, [{setcookie, abc}]} = rebar_dist_utils:find_options(State2),
  45. State3 = rebar_state:command_parsed_args(State0, {[{sname, 'a@localhost'}, {name, 'a@localhost.x'}, {setcookie,abc}], []}),
  46. {'a@localhost.x', 'a@localhost', [{setcookie, abc}]} = rebar_dist_utils:find_options(State3),
  47. State4 = rebar_state:command_parsed_args(State0, {[{setcookie,def}], []}),
  48. {undefined, undefined, [{setcookie, def}]} = rebar_dist_utils:find_options(State4),
  49. State5 = rebar_state:command_parsed_args(State0, {[{sname, 'a@localhost'}], []}),
  50. {undefined, 'a@localhost', []} = rebar_dist_utils:find_options(State5),
  51. ok.
  52. overlap(Config) ->
  53. %% Make sure that CLI config takes over rebar config without clash for names, though
  54. %% cookies can pass through
  55. RebarConfig = [{dist_node, [{sname, 'a@localhost'}, {setcookie, abc}]}],
  56. {ok, State0} = rebar_test_utils:run_and_check(Config, RebarConfig, ["version"], return),
  57. State1 = rebar_state:command_parsed_args(State0, {[{name, 'b@localhost.x'}], []}),
  58. {'b@localhost.x', undefined, [{setcookie, abc}]} = rebar_dist_utils:find_options(State1),
  59. ok.
  60. from_config_profile(Config) ->
  61. %% running as a profile does not create name clashes
  62. RebarConfig = [{dist_node, [{sname, 'a@localhost'}, {setcookie, abc}]},
  63. {profiles, [ {fake, [{dist_node, [{name, 'a@localhost.x'}]}]} ]}],
  64. {ok, State0} = rebar_test_utils:run_and_check(Config, RebarConfig, ["as","fake","version"], return),
  65. {'a@localhost.x', undefined, [{setcookie, abc}]} = rebar_dist_utils:find_options(State0),
  66. ok.