aboutsummaryrefslogtreecommitdiffstats
path: root/lib/common_test/test/ct_config_SUITE_data/config/test/config_static_SUITE.erl
blob: d3f07980bc8187c0f2bedcc030f749272bdfbfae (plain) (blame)
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
%%
%% %CopyrightBegin%
%%
%% Copyright Ericsson AB 2009-2010. All Rights Reserved.
%%
%% The contents of this file are subject to the Erlang Public License,
%% Version 1.1, (the "License"); you may not use this file except in
%% compliance with the License. You should have received a copy of the
%% Erlang Public License along with this software. If not, it can be
%% retrieved online at http://www.erlang.org/.
%%
%% Software distributed under the License is distributed on an "AS IS"
%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
%% the License for the specific language governing rights and limitations
%% under the License.
%%
%% %CopyrightEnd%
%%

%%%-------------------------------------------------------------------
%%% File: config_1_SUITE
%%%
%%% Description:
%%% Test suite for common_test which tests the get_config and require
%%% functionality
%%%-------------------------------------------------------------------
-module(config_static_SUITE).

-compile(export_all).

-include_lib("common_test/include/ct.hrl").

% The config contains variables:
% x - atom
% gen_cfg - list with two key-values tagged with a and b
% gen_cfg2 - list of five key-values tagged with c, d, e, f and g
% gen_cfg3 - list of two complex key-values taggen with:
%	h: three elements inside - i, j and k
%	l: m inside, contains n and o

suite() ->
    [
     {timetrap, {seconds,10}},
     %% x1 doesn't exist in cfg-file!
     {require, x1, x},
     {require, gen_cfg3},
     {require, alias, gen_cfg},
     %% x1 default value
     {x1, {x,suite}}
    ].

% to get it running on development branch (without userconfig features)
% function to print full config is in the ct_util, for me it's moved to ct_config
% two following functions are only for the design period
% after merging of userconfigs to the main branch ct_config:get_all_config/0
% should be called instead
is_exported(Module, Function, Arity)->
    Exports = Module:module_info(exports),
    case lists:keyfind(Function, 1, Exports) of
	false->
	    false;
	{Function, Arity}->
	    true;
	{Function, _OtherArity}->
	    false
    end.

get_all_config()->
    case is_exported(ct_util, get_all_config, 0) of
	true->
	    {ct_util, ct_util:get_all_config()};
	false->
	    {ct_config, ct_config:get_all_config()}
    end.

init_per_suite(Config) ->
    %{Module, Cfg} = get_all_config(),
    %ct:pal("CONFIG (handled by ~p):~n~p", [Module, Cfg]),
    Config.

end_per_suite(_) ->
    ok.

all() -> [test_get_config_simple, test_get_config_nested, test_default_suitewide,
	  test_config_name_already_in_use1, test_default_tclocal,
	  test_config_name_already_in_use2, test_alias_tclocal,
	  test_get_config_undefined].

init_per_testcase(_, Config) ->
    %{Module, Cfg} = get_all_config(),
    %ct:pal("CONFIG (handled by ~p):~n~p", [Module, Cfg]),
    Config.

end_per_testcase(_, _) ->
    ok.

%% test getting a simple value
test_get_config_simple(_)->
    suite = ct:get_config(x),
    ok.

%% test getting a nested value
test_get_config_nested(_)->
    a_value = ct:get_config({gen_cfg, a}),
    ok.

%% test suite-wide default value
test_default_suitewide(_)->
    suite = ct:get_config(x1),
    ok.

%% should get skipped
test_config_name_already_in_use1() ->
    [{timetrap, {seconds,2}},
     {require, x1, x},
     {x1, {x,test2}}].
test_config_name_already_in_use1(_) ->
    ct:fail("Test should've been skipped, you shouldn't see this!"),
    ok.

%% test defaults in a testcase
test_default_tclocal() ->
    [{timetrap, {seconds,3}},
     {require, y1, y},
     {y1, {y,test3}}].
test_default_tclocal(_) ->
    test3 = ct:get_config(y1),
    ok.

%% should get skipped
test_config_name_already_in_use2() ->
    [{require,alias,something},
     {alias,{something,else}},
     {require, x1, x},
     {x1, {x,test4}}].
test_config_name_already_in_use2(_) ->
    ct:fail("Test should've been skipped, you shouldn't see this!"),
    ok.

%% test aliases
test_alias_tclocal() ->
    [{require,newalias,gen_cfg}].
test_alias_tclocal(_) ->
    A = [{a,a_value},{b,b_value}] = ct:get_config(newalias),
    A = ct:get_config(gen_cfg),
    ok.

%% test for getting undefined variables
test_get_config_undefined(_) ->
    undefined = ct:get_config(y1),
    ok.