1-module(subconfig_SUITE).
2
3-include("testsuite.hrl").
4
5-compile(export_all).
6
7all() ->
8    [
9     bad_global_subconfig,
10     bad_server_subconfig,
11     absolute_subconfig,
12     relative_subconfig
13    ].
14
15groups() ->
16    [
17    ].
18
19%%====================================================================
20init_per_suite(Config) ->
21    Config.
22
23end_per_suite(_Config) ->
24    ok.
25
26init_per_group(_Group, Config) ->
27    Config.
28
29end_per_group(_Group, _Config) ->
30    ok.
31
32init_per_testcase(_Test, Config) ->
33    Config.
34
35end_per_testcase(_Test, _Config) ->
36    ok.
37
38%%====================================================================
39bad_global_subconfig(_Config) ->
40    Env1 = #env{debug = false,
41                conf  = {file, ?tempdir(?MODULE) ++ "/yaws_global_subconfig_notfound1.conf"}},
42    {error, _} = yaws_config:load(Env1),
43
44    Env2 = #env{debug = false,
45                conf  = {file, ?tempdir(?MODULE) ++ "/yaws_global_subconfig_notfound2.conf"}},
46    {error, _} = yaws_config:load(Env2),
47
48    Env3 = #env{debug = false,
49                conf  = {file, ?tempdir(?MODULE) ++ "/yaws_global_subconfig_notfound3.conf"}},
50    {error, _} = yaws_config:load(Env3),
51
52    ok.
53
54bad_server_subconfig(_Config) ->
55    Env1 = #env{debug = false,
56                conf  = {file, ?tempdir(?MODULE) ++ "/yaws_server_subconfig_notfound1.conf"}},
57    {error, _} = yaws_config:load(Env1),
58
59    Env2 = #env{debug = false,
60                conf  = {file, ?tempdir(?MODULE) ++ "/yaws_server_subconfig_notfound2.conf"}},
61    {error, _} = yaws_config:load(Env2),
62
63    Env3 = #env{debug = false,
64                conf  = {file, ?tempdir(?MODULE) ++ "/yaws_server_subconfig_notfound3.conf"}},
65    {error, _} = yaws_config:load(Env3),
66
67    Env4 = #env{debug = false,
68                conf  = {file, ?tempdir(?MODULE) ++ "/yaws_server_subconfig_closing_tag.conf"}},
69    {error, _} = yaws_config:load(Env4),
70
71    ok.
72
73absolute_subconfig(_Config) ->
74    F = ?tempdir(?MODULE) ++ "/yaws_absolute.conf",
75    Env = #env{debug=false, conf={file,F}},
76    {ok, _GC, SCs} = yaws_config:load(Env),
77    check_sconfs(lists:flatten(SCs)).
78
79relative_subconfig(_Config) ->
80    F = ?tempdir(?MODULE) ++ "/yaws_relative.conf",
81    Env = #env{debug=false, conf={file,F}},
82    {ok, _GC, SCs} = yaws_config:load(Env),
83    check_sconfs(lists:flatten(SCs)).
84
85check_sconfs(SCs) ->
86    ?assertEqual(5, length(SCs)),
87    ?assert(lists:keymember(8000, #sconf.port, SCs)),
88    ?assert(lists:keymember(8001, #sconf.port, SCs)),
89    ?assert(lists:keymember(8002, #sconf.port, SCs)),
90    ?assert(lists:keymember(8003, #sconf.port, SCs)),
91    ?assert(lists:keymember(8004, #sconf.port, SCs)),
92
93    SC_8000 = lists:keyfind(8000, #sconf.port, SCs),
94    ?assertEqual(5, length(SC_8000#sconf.serveralias)),
95    ?assert(lists:member("server_subconfig",     SC_8000#sconf.serveralias)),
96    ?assert(lists:member("server_subconfig1",    SC_8000#sconf.serveralias)),
97    ?assert(lists:member("server_subconfig2",    SC_8000#sconf.serveralias)),
98    ?assert(lists:member("server_subconfigdir1", SC_8000#sconf.serveralias)),
99    ?assert(lists:member("server_subconfigdir2", SC_8000#sconf.serveralias)),
100    ok.
101