blob: e7fbe0c559a7e587b0e85eba3e5ba50a32c50e4b [file] [log] [blame]
Dean Troyer489bd2a2012-03-02 10:44:29 -06001#!/usr/bin/env bash
2
3# Tests for DevStack functions
4
5TOP=$(cd $(dirname "$0")/.. && pwd)
6
7# Import common functions
8source $TOP/functions
9
10# Import configuration
11source $TOP/openrc
12
13
Dean Troyer489bd2a2012-03-02 10:44:29 -060014echo "Testing die_if_not_set()"
15
Dean Troyer27e32692012-03-16 16:16:56 -050016bash -cx "source $TOP/functions; X=`echo Y && true`; die_if_not_set X 'not OK'"
Dean Troyer489bd2a2012-03-02 10:44:29 -060017if [[ $? != 0 ]]; then
18 echo "die_if_not_set [X='Y' true] Failed"
19else
20 echo 'OK'
21fi
22
Dean Troyer27e32692012-03-16 16:16:56 -050023bash -cx "source $TOP/functions; X=`true`; die_if_not_set X 'OK'"
Dean Troyer489bd2a2012-03-02 10:44:29 -060024if [[ $? = 0 ]]; then
25 echo "die_if_not_set [X='' true] Failed"
26fi
27
Dean Troyer27e32692012-03-16 16:16:56 -050028bash -cx "source $TOP/functions; X=`echo Y && false`; die_if_not_set X 'not OK'"
Dean Troyer489bd2a2012-03-02 10:44:29 -060029if [[ $? != 0 ]]; then
30 echo "die_if_not_set [X='Y' false] Failed"
31else
32 echo 'OK'
33fi
34
Dean Troyer27e32692012-03-16 16:16:56 -050035bash -cx "source $TOP/functions; X=`false`; die_if_not_set X 'OK'"
Dean Troyer489bd2a2012-03-02 10:44:29 -060036if [[ $? = 0 ]]; then
37 echo "die_if_not_set [X='' false] Failed"
38fi
39
Dean Troyer13dc5cc2012-03-27 14:50:45 -050040
41echo "Testing INI functions"
42
43cat >test.ini <<EOF
44[default]
45# comment an option
46#log_file=./log.conf
47log_file=/etc/log.conf
48handlers=do not disturb
49
50[aaa]
51# the commented option should not change
52#handlers=cc,dd
53handlers = aa, bb
54
55[bbb]
56handlers=ee,ff
57EOF
58
59# Test with spaces
60
61VAL=$(iniget test.ini aaa handlers)
62if [[ "$VAL" == "aa, bb" ]]; then
63 echo "OK: $VAL"
64else
65 echo "iniget failed: $VAL"
66fi
67
68iniset test.ini aaa handlers "11, 22"
69
70VAL=$(iniget test.ini aaa handlers)
71if [[ "$VAL" == "11, 22" ]]; then
72 echo "OK: $VAL"
73else
74 echo "iniget failed: $VAL"
75fi
76
77
78# Test without spaces, end of file
79
80VAL=$(iniget test.ini bbb handlers)
81if [[ "$VAL" == "ee,ff" ]]; then
82 echo "OK: $VAL"
83else
84 echo "iniget failed: $VAL"
85fi
86
87iniset test.ini bbb handlers "33,44"
88
89VAL=$(iniget test.ini bbb handlers)
90if [[ "$VAL" == "33,44" ]]; then
91 echo "OK: $VAL"
92else
93 echo "iniget failed: $VAL"
94fi
95
96
97# Test section not exist
98
99VAL=$(iniget test.ini zzz handlers)
100if [[ -z "$VAL" ]]; then
Dean Troyer09e636e2012-03-19 16:31:12 -0500101 echo "OK: zzz not present"
Dean Troyer13dc5cc2012-03-27 14:50:45 -0500102else
103 echo "iniget failed: $VAL"
104fi
105
106iniset test.ini zzz handlers "999"
107
108VAL=$(iniget test.ini zzz handlers)
Dean Troyer09e636e2012-03-19 16:31:12 -0500109if [[ -n "$VAL" ]]; then
110 echo "OK: zzz not present"
Dean Troyer13dc5cc2012-03-27 14:50:45 -0500111else
112 echo "iniget failed: $VAL"
113fi
114
115
Dean Troyer09e636e2012-03-19 16:31:12 -0500116# Test option not exist
117
118VAL=$(iniget test.ini aaa debug)
119if [[ -z "$VAL" ]]; then
120 echo "OK aaa.debug not present"
121else
122 echo "iniget failed: $VAL"
123fi
124
125iniset test.ini aaa debug "999"
126
127VAL=$(iniget test.ini aaa debug)
128if [[ -n "$VAL" ]]; then
129 echo "OK aaa.debug present"
130else
131 echo "iniget failed: $VAL"
132fi
133
Dean Troyer13dc5cc2012-03-27 14:50:45 -0500134# Test comments
135
136inicomment test.ini aaa handlers
137
138VAL=$(iniget test.ini aaa handlers)
139if [[ -z "$VAL" ]]; then
140 echo "OK"
141else
142 echo "inicomment failed: $VAL"
143fi