PageRenderTime 102ms CodeModel.GetById 61ms app.highlight 6ms RepoModel.GetById 34ms 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
20-include_lib("eunit/include/eunit.hrl").
21
22url_test_() ->
23    {inparallel,
24     [?_test(test_bad_url()),
25      ?_test(test_options()),
26      ?_test(test_head()),
27      ?_test(test_get_time())]}.
28
29test_bad_url() ->
30    BaseUrl = fixtures:get_base_url(),
31    ?assertMatch({struct, [{"error", "not_found"},
32                           {"infos", _Description}]}, tests_utils:get(BaseUrl, "", [])).
33
34test_options() ->
35    BaseUrl = fixtures:get_base_url(),
36    ?assertMatch({ok, "200", _, _}, tests_utils:options_raw(BaseUrl, "/time")),
37    ?assertMatch({ok, "404", _, _}, tests_utils:options_raw(BaseUrl, "/")).
38
39test_head() ->
40    BaseUrl = fixtures:get_base_url(),
41    ?assertMatch({ok, "200", _, ""}, tests_utils:head_raw(BaseUrl, "/time")),
42    ?assertMatch({ok, "404", _, ""}, tests_utils:head_raw(BaseUrl, "/")).
43
44test_get_time() ->
45    BaseUrl = fixtures:get_base_url(),
46    {struct, [{"result", Time}]} = tests_utils:get(BaseUrl, "/time", []),
47    Diff = Time - utils:now(),
48    if
49        Diff > 1000 ->
50            throw({error, too_much_delay, Diff});
51        true ->
52            nothing
53    end.