Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

50 linhas
2.0 KiB

  1. -module(rebar_uri_SUITE).
  2. -export([all/0,
  3. parse/1,
  4. append_path/1]).
  5. -include_lib("common_test/include/ct.hrl").
  6. -include_lib("eunit/include/eunit.hrl").
  7. -include_lib("kernel/include/file.hrl").
  8. all() ->
  9. [parse, append_path].
  10. parse(_Config) ->
  11. #{scheme := Scheme, host := Host, path := Path} = rebar_uri:parse("https://repo.hex.pm"),
  12. ?assertEqual("https", Scheme),
  13. ?assertEqual("repo.hex.pm", Host),
  14. ?assertEqual(Path, "/"), % Normalize on OTP-23 behaviour.
  15. #{scheme := Scheme2, host := Host2, port := Port2, path := Path2, query := Query2} =
  16. rebar_uri:parse("https://repo.hex.pm:443?foo=bar"),
  17. ?assertEqual("https", Scheme2),
  18. ?assertEqual("repo.hex.pm", Host2),
  19. ?assertEqual(443, Port2),
  20. ?assertEqual(Path2, "/"), % Normalize on old http_uri behaviour
  21. ?assertEqual("foo=bar", Query2),
  22. #{scheme := Scheme3, host := Host3, path := Path3, query := Query3} =
  23. rebar_uri:parse("https://repo.hex.pm/over/here?foo=bar"),
  24. ?assertEqual("https", Scheme3),
  25. ?assertEqual("repo.hex.pm", Host3),
  26. ?assertEqual("/over/here", Path3),
  27. ?assertEqual("foo=bar", Query3),
  28. %% override default port and get it parsed as such
  29. ?assertMatch(#{port := 1337},
  30. rebar_uri:parse("https://repo.hex.pm/",
  31. [{scheme_defaults, [{https,1337}]}])),
  32. ok.
  33. append_path(_Config) ->
  34. %% Default port for the proto is omitted if not mentioned originally
  35. {ok, Val1} = rebar_uri:append_path("https://repo.hex.pm/", "/repos/org"),
  36. ?assertEqual("https://repo.hex.pm/repos/org", Val1),
  37. %% QS elements come after the path
  38. {ok, Val2} = rebar_uri:append_path("https://repo.hex.pm?foo=bar", "/repos/org"),
  39. ?assertEqual("https://repo.hex.pm/repos/org?foo=bar", Val2),
  40. %% If the port is explicitly mentioned, keep it.
  41. ?assertEqual({ok, "https://repo.hex.pm:443/repos/org?foo=bar"},
  42. rebar_uri:append_path("https://repo.hex.pm:443?foo=bar", "/repos/org")).