summaryrefslogtreecommitdiff
path: root/ctdb/tests/cunit/conf_test_001.sh
blob: 487b508b57a61dae9176581080cf701576988bb6 (plain)
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
#!/bin/sh

. "${TEST_SCRIPTS_DIR}/unit.sh"

conffile="${TEST_VAR_DIR}/config.$$"

remove_files ()
{
	rm -f "$conffile"
}

test_cleanup remove_files

ok_null
unit_test conf_test 1

ok <<EOF
conf: unknown section [section1]
EOF
unit_test conf_test 2

ok <<EOF
conf: option "key1" already exists
EOF
unit_test conf_test 3

ok <<EOF
conf: option "key1" already exists
EOF
unit_test conf_test 4

ok_null
unit_test conf_test 5

ok <<EOF
[section1]
	key1 = foobar # temporary
	key2 = 20 # temporary
	key3 = false # temporary
EOF
unit_test conf_test 6

ok <<EOF
conf: validation for option "key1" failed
conf: validation for option "key2" failed
conf: validation for option "key3" failed
EOF
unit_test conf_test 7

cat > "$conffile" <<EOF
[section1]
EOF

required_error EINVAL <<EOF
conf: validation for section [section1] failed
[section1]
	# key1 = default
EOF
unit_test conf_test 8 "$conffile"

cat > "$conffile" <<EOF
[section1]
    key1 = unknown
EOF

required_error EINVAL <<EOF
conf: validation for section [section1] failed
[section1]
	# key1 = default
EOF
unit_test conf_test 8 "$conffile"

cat > "$conffile" <<EOF

[section1]
    key1 = value2  
    key2 =     20  # comment
key3    =    false
EOF

ok <<EOF
[section1]
	key1 = value2
	key2 = 20
	# key3 = true
EOF
unit_test conf_test 9 "$conffile"

cat > "$conffile" <<EOF
[section1]
key1 = value2  
EOF

ok <<EOF
[section1]
	key1 = value2
	# key2 = 10
	# key3 = true
EOF
unit_test conf_test 9 "$conffile"

cat > "$conffile" <<EOF
[section2]
    foo = bar
EOF

required_error EINVAL <<EOF
conf: unknown section [section2]
conf: unknown section for option "foo"
[section1]
	# key1 = value1
	# key2 = 10
	key3 = false # temporary
EOF
unit_test conf_test 10 "$conffile"

cat > "$conffile" <<EOF
[section1]
    key1 = value2
    foo = bar
    key2 = 20
EOF

required_error EINVAL <<EOF
conf: unknown option [section1] -> "foo"
[section1]
	# key1 = value1
	# key2 = 10
	key3 = false # temporary
EOF
unit_test conf_test 10 "$conffile"

cat > "$conffile" <<EOF
[section1]
    key1 = value2
    key2 = 20
    key3 = false
EOF

touch "${conffile}.reload"

ok <<EOF
[section1]
	# key1 = value1
	# key2 = 10
	# key3 = true
EOF
unit_test conf_test 11 "$conffile"

cat > "$conffile" <<EOF
[section1]
    key1 = value2
    key2 = 20
    key3 = false
EOF

cat > "${conffile}.reload" <<EOF
[section1]
    key1 = value3
EOF

ok <<EOF
[section1]
	key1 = value3
	# key2 = 10
	# key3 = true
EOF
unit_test conf_test 11 "$conffile"