File: srcdir_SUITE.erl

package info (click to toggle)
yaws 2.0.8%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 8,084 kB
  • sloc: erlang: 42,190; sh: 2,543; javascript: 1,459; ansic: 890; makefile: 878; lisp: 79; python: 34; xml: 12; php: 1
file content (93 lines) | stat: -rw-r--r-- 2,528 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
-module(srcdir_SUITE).

-include("testsuite.hrl").
-include_lib("kernel/include/file.hrl").

-compile(export_all).

all() ->
    [
     srcdir_v1,
     srcdir_v2,
     srcdir_invalid
    ].

groups() ->
    [
    ].

%%====================================================================
init_per_suite(Config) ->
    ok = prepare_docroots(),

    Id    = "testsuite-server",
    YConf = filename:join(?tempdir(?MODULE), "yaws.conf"),
    application:load(yaws),
    application:set_env(yaws, id,   Id),
    application:set_env(yaws, conf, YConf),
    ok = yaws:start(),
    [{yaws_id, Id}, {yaws_config, YConf} | Config].

end_per_suite(_Config) ->
    ok = application:stop(yaws),
    ok = application:unload(yaws),
    ok.

init_per_group(_Group, Config) ->
    Config.

end_per_group(_Group, _Config) ->
    ok.

init_per_testcase(_Test, Config) ->
    Config.

end_per_testcase(_Test, _Config) ->
    ok.

%%====================================================================
srcdir_v1(Config) ->
    Port = testsuite:get_yaws_port(1, Config),
    Url = testsuite:make_url(http, "127.0.0.1", Port, "/"),
    Res = <<"1.0">>,

    ?assertMatch({ok, {{_,200,_}, _, Res}}, testsuite:http_get(Url)),
    ok.

srcdir_v2(Config) ->
    Port = testsuite:get_yaws_port(1, Config),
    Url = testsuite:make_url(http, "127.0.0.1", Port, "/"),
    Res = <<"2.0">>,

    ?assertEqual(ok, set_srcdir_version(<<"2.0">>)),
    ?assertEqual({yaws_hupped, ok}, yaws:hup()),

    ?assertMatch({ok, {{_,200,_}, _, Res}}, testsuite:http_get(Url)),
    ok.

srcdir_invalid(Config) ->
    Port = testsuite:get_yaws_port(1, Config),
    Url = testsuite:make_url(http, "127.0.0.1", Port, "/"),
    Res = <<"2.0">>,

    ?assertEqual(ok, set_srcdir_version(undefined)),
    ?assertEqual({yaws_hupped, ok}, yaws:hup()),

    ?assertMatch({ok, {{_,200,_}, _, Res}}, testsuite:http_get(Url)),
    ok.

%%====================================================================
prepare_docroots() ->
    INC = filename:join(?tempdir(?MODULE), "include"),
    ok = testsuite:create_dir(INC),
    ok = set_srcdir_version(<<"1.0">>),
    ok.

set_srcdir_version(undefined) ->
    INC = filename:join(?tempdir(?MODULE), "include"),
    Bin = <<"invalid_version">>,
    file:write_file(filename:join(INC, "srcdir_test.hrl"), Bin, [write]);
set_srcdir_version(Vsn) ->
    INC = filename:join(?tempdir(?MODULE), "include"),
    Bin = <<"-define(SRCDIR_VERSION, \"", Vsn/binary, "\").">>,
    file:write_file(filename:join(INC, "srcdir_test.hrl"), Bin, [write]).