Browse code

Merge "Convert test_functions.sh to use unittest helpers"

Jenkins authored on 2015/04/18 04:32:09
Showing 1 changed files
... ...
@@ -10,31 +10,32 @@ source $TOP/functions
10 10
 # Import configuration
11 11
 source $TOP/openrc
12 12
 
13
+source $TOP/tests/unittest.sh
13 14
 
14 15
 echo "Testing die_if_not_set()"
15 16
 
16 17
 bash -c "source $TOP/functions; X=`echo Y && true`; die_if_not_set $LINENO X 'not OK'"
17 18
 if [[ $? != 0 ]]; then
18
-    echo "die_if_not_set [X='Y' true] Failed"
19
+    failed "die_if_not_set [X='Y' true] Failed"
19 20
 else
20
-    echo 'OK'
21
+    passed 'OK'
21 22
 fi
22 23
 
23 24
 bash -c "source $TOP/functions; X=`true`; die_if_not_set $LINENO X 'OK'" > /dev/null 2>&1
24 25
 if [[ $? = 0 ]]; then
25
-    echo "die_if_not_set [X='' true] Failed"
26
+    failed "die_if_not_set [X='' true] Failed"
26 27
 fi
27 28
 
28 29
 bash -c "source $TOP/functions; X=`echo Y && false`; die_if_not_set $LINENO X 'not OK'"
29 30
 if [[ $? != 0 ]]; then
30
-    echo "die_if_not_set [X='Y' false] Failed"
31
+    failed "die_if_not_set [X='Y' false] Failed"
31 32
 else
32
-    echo 'OK'
33
+    passed 'OK'
33 34
 fi
34 35
 
35 36
 bash -c "source $TOP/functions; X=`false`; die_if_not_set $LINENO X 'OK'" > /dev/null 2>&1
36 37
 if [[ $? = 0 ]]; then
37
-    echo "die_if_not_set [X='' false] Failed"
38
+    failed "die_if_not_set [X='' false] Failed"
38 39
 fi
39 40
 
40 41
 
... ...
@@ -50,9 +51,9 @@ function test_enable_service {
50 50
     ENABLED_SERVICES="$start"
51 51
     enable_service $add
52 52
     if [ "$ENABLED_SERVICES" = "$finish" ]; then
53
-        echo "OK: $start + $add -> $ENABLED_SERVICES"
53
+        passed "OK: $start + $add -> $ENABLED_SERVICES"
54 54
     else
55
-        echo "changing $start to $finish with $add failed: $ENABLED_SERVICES"
55
+        failed "changing $start to $finish with $add failed: $ENABLED_SERVICES"
56 56
     fi
57 57
 }
58 58
 
... ...
@@ -76,9 +77,9 @@ function test_disable_service {
76 76
     ENABLED_SERVICES="$start"
77 77
     disable_service "$del"
78 78
     if [ "$ENABLED_SERVICES" = "$finish" ]; then
79
-        echo "OK: $start - $del -> $ENABLED_SERVICES"
79
+        passed "OK: $start - $del -> $ENABLED_SERVICES"
80 80
     else
81
-        echo "changing $start to $finish with $del failed: $ENABLED_SERVICES"
81
+        failed "changing $start to $finish with $del failed: $ENABLED_SERVICES"
82 82
     fi
83 83
 }
84 84
 
... ...
@@ -101,9 +102,9 @@ ENABLED_SERVICES=a,b,c
101 101
 disable_all_services
102 102
 
103 103
 if [[ -z "$ENABLED_SERVICES" ]]; then
104
-    echo "OK"
104
+    passed "OK"
105 105
 else
106
-    echo "disabling all services FAILED: $ENABLED_SERVICES"
106
+    failed "disabling all services FAILED: $ENABLED_SERVICES"
107 107
 fi
108 108
 
109 109
 echo "Testing disable_negated_services()"
... ...
@@ -116,9 +117,9 @@ function test_disable_negated_services {
116 116
     ENABLED_SERVICES="$start"
117 117
     disable_negated_services
118 118
     if [ "$ENABLED_SERVICES" = "$finish" ]; then
119
-        echo "OK: $start + $add -> $ENABLED_SERVICES"
119
+        passed "OK: $start + $add -> $ENABLED_SERVICES"
120 120
     else
121
-        echo "changing $start to $finish failed: $ENABLED_SERVICES"
121
+        failed "changing $start to $finish failed: $ENABLED_SERVICES"
122 122
     fi
123 123
 }
124 124
 
... ...
@@ -147,9 +148,9 @@ else
147 147
     VAL=1
148 148
 fi
149 149
 if [[ "$VAL" -eq 0 ]]; then
150
-    echo "OK"
150
+    passed "OK"
151 151
 else
152
-    echo "is_package_installed() on existing package failed"
152
+    failed "is_package_installed() on existing package failed"
153 153
 fi
154 154
 
155 155
 if [[ "$os_PACKAGE" = "deb" ]]; then
... ...
@@ -162,17 +163,17 @@ else
162 162
     VAL=1
163 163
 fi
164 164
 if [[ "$VAL" -eq 0 ]]; then
165
-    echo "OK"
165
+    passed "OK"
166 166
 else
167
-    echo "is_package_installed() on more than one existing package failed"
167
+    failed "is_package_installed() on more than one existing package failed"
168 168
 fi
169 169
 
170 170
 is_package_installed zzzZZZzzz
171 171
 VAL=$?
172 172
 if [[ "$VAL" -ne 0 ]]; then
173
-    echo "OK"
173
+    passed "OK"
174 174
 else
175
-    echo "is_package_installed() on non-existing package failed"
175
+    failed "is_package_installed() on non-existing package failed"
176 176
 fi
177 177
 
178 178
 # test against removed package...was a bug on Ubuntu
... ...
@@ -191,9 +192,9 @@ if is_ubuntu; then
191 191
     is_package_installed $PKG
192 192
     VAL=$?
193 193
     if [[ "$VAL" -ne 0 ]]; then
194
-        echo "OK"
194
+        passed "OK"
195 195
     else
196
-        echo "is_package_installed() on deleted package failed"
196
+        failed "is_package_installed() on deleted package failed"
197 197
     fi
198 198
 fi
199 199
 
... ...
@@ -202,14 +203,16 @@ echo  "Testing isset()"
202 202
 you_should_not_have_this_variable=42
203 203
 
204 204
 if isset "you_should_not_have_this_variable"; then
205
-    echo "OK"
205
+    passed "OK"
206 206
 else
207
-    echo "\"you_should_not_have_this_variable\" not declared. failed"
207
+    failed "\"you_should_not_have_this_variable\" not declared. failed"
208 208
 fi
209 209
 
210 210
 unset you_should_not_have_this_variable
211 211
 if isset "you_should_not_have_this_variable"; then
212
-    echo "\"you_should_not_have_this_variable\" looks like declared variable. failed"
212
+    failed "\"you_should_not_have_this_variable\" looks like declared variable."
213 213
 else
214
-    echo "OK"
214
+    passed "OK"
215 215
 fi
216
+
217
+report_results