PageRenderTime 43ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 0ms

/ucengine/src/tests/url_tests.erl

http://github.com/AF83/ucengine
Erlang | 53 lines | 30 code | 6 blank | 17 comment | 0 complexity | 995585d900b179a52b36da48995f8d6a MD5 | raw file
  1. %%
  2. %% U.C.Engine - Unified Collaboration Engine
  3. %% Copyright (C) 2011 af83
  4. %%
  5. %% This program is free software: you can redistribute it and/or modify
  6. %% it under the terms of the GNU Affero General Public License as published by
  7. %% the Free Software Foundation, either version 3 of the License, or
  8. %% (at your option) any later version.
  9. %%
  10. %% This program is distributed in the hope that it will be useful,
  11. %% but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. %% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. %% GNU Affero General Public License for more details.
  14. %%
  15. %% You should have received a copy of the GNU Affero General Public License
  16. %% along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. %%
  18. -module(url_tests).
  19. -include_lib("eunit/include/eunit.hrl").
  20. url_test_() ->
  21. {inparallel,
  22. [?_test(test_bad_url()),
  23. ?_test(test_options()),
  24. ?_test(test_head()),
  25. ?_test(test_get_time())]}.
  26. test_bad_url() ->
  27. BaseUrl = fixtures:get_base_url(),
  28. ?assertMatch({struct, [{"error", "not_found"},
  29. {"infos", _Description}]}, tests_utils:get(BaseUrl, "", [])).
  30. test_options() ->
  31. BaseUrl = fixtures:get_base_url(),
  32. ?assertMatch({ok, "200", _, _}, tests_utils:options_raw(BaseUrl, "/time")),
  33. ?assertMatch({ok, "404", _, _}, tests_utils:options_raw(BaseUrl, "/")).
  34. test_head() ->
  35. BaseUrl = fixtures:get_base_url(),
  36. ?assertMatch({ok, "200", _, ""}, tests_utils:head_raw(BaseUrl, "/time")),
  37. ?assertMatch({ok, "404", _, ""}, tests_utils:head_raw(BaseUrl, "/")).
  38. test_get_time() ->
  39. BaseUrl = fixtures:get_base_url(),
  40. {struct, [{"result", Time}]} = tests_utils:get(BaseUrl, "/time", []),
  41. Diff = Time - utils:now(),
  42. if
  43. Diff > 1000 ->
  44. throw({error, too_much_delay, Diff});
  45. true ->
  46. nothing
  47. end.