-
Notifications
You must be signed in to change notification settings - Fork 5
/
step_test.sh
executable file
·269 lines (220 loc) · 7.22 KB
/
step_test.sh
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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
#!/bin/bash
#
# Run it from the directory which contains step.sh
#
# ------------------------
# --- Helper functions ---
function print_and_do_command {
echo "$ $@"
$@
}
function inspect_test_result {
if [ $1 -eq 0 ]; then
test_results_success_count=$[test_results_success_count + 1]
else
test_results_error_count=$[test_results_error_count + 1]
fi
}
#
# First param is the expect message, other are the command which will be executed.
#
function expect_success {
expect_msg=$1
shift
echo " -> $expect_msg"
$@
cmd_res=$?
if [ $cmd_res -eq 0 ]; then
echo " [OK] Expected zero return code, got: 0"
else
echo " [ERROR] Expected zero return code, got: $cmd_res"
exit 1
fi
}
#
# First param is the expect message, other are the command which will be executed.
#
function expect_error {
expect_msg=$1
shift
echo " -> $expect_msg"
$@
cmd_res=$?
if [ ! $cmd_res -eq 0 ]; then
echo " [OK] Expected non-zero return code, got: $cmd_res"
else
echo " [ERROR] Expected non-zero return code, got: 0"
exit 1
fi
}
function is_dir_exist {
if [ -d "$1" ]; then
return 0
else
return 1
fi
}
function is_file_exist {
if [ -f "$1" ]; then
return 0
else
return 1
fi
}
function is_not_empty {
if [[ $1 ]]; then
return 0
else
return 1
fi
}
function test_env_cleanup {
unset account_sid
unset auth_token
unset to_number
unset from_number
unset message
unset sms_media
}
function print_new_test {
echo
echo "[TEST]"
}
# -----------------
# --- Run tests ---
echo "Starting tests..."
test_ipa_path="tests/testfile.ipa"
test_results_success_count=0
test_results_error_count=0
# [TEST] Call the command with account_sid not set,
# it should raise an error message and exit
#
(
print_new_test
test_env_cleanup
# Set env vars
export auth_token="dsa4321"
export to_number="dsa4321"
export from_number="dsa4321"
export message="dsa4321"
export sms_media="dsa4321"
# All env vars should exist except account_sid
expect_error "account_sid environment variable should NOT be set" is_not_empty "$account_sid"
expect_success "auth_token environment variable should be set" is_not_empty "$auth_token"
expect_success "to_number environment variable should be set" is_not_empty "$to_number"
expect_success "from_number environment variable should be set" is_not_empty "$from_number"
expect_success "message environment variable should be set" is_not_empty "$message"
expect_success "sms_media environment variable should be set" is_not_empty "$sms_media"
# Send sms request
expect_error "The command should be called, but should not complete sucessfully" print_and_do_command ./step.sh
)
test_result=$?
inspect_test_result $test_result
# [TEST] Call the command with auth_token not set,
# it should raise an error message and exit
#
(
print_new_test
test_env_cleanup
# Set env vars
export account_sid="dsa4321"
export to_number="dsa4321"
export from_number="dsa4321"
export message="dsa4321"
export sms_media="dsa4321"
# All env vars should exist except auth_token
expect_success "account_sid environment variable should be set" is_not_empty "$account_sid"
expect_error "auth_token environment variable should NOT be set" is_not_empty "$auth_token"
expect_success "to_number environment variable should be set" is_not_empty "$to_number"
expect_success "from_number environment variable should be set" is_not_empty "$from_number"
expect_success "message environment variable should be set" is_not_empty "$message"
expect_success "sms_media environment variable should be set" is_not_empty "$sms_media"
# Send sms request
expect_error "The command should be called, but should not complete sucessfully" print_and_do_command ./step.sh
)
test_result=$?
inspect_test_result $test_result
# [TEST] Call the command with to_number not set,
# it should raise an error message and exit
#
(
print_new_test
test_env_cleanup
# Set env vars
export account_sid="dsa4321"
export auth_token="dsa4321"
export from_number="dsa4321"
export message="dsa4321"
export sms_media="dsa4321"
# All env vars should exist except to_number
expect_success "account_sid environment variable should be set" is_not_empty "$account_sid"
expect_success "auth_token environment variable should be set" is_not_empty "$auth_token"
expect_error "to_number environment variable should NOT be set" is_not_empty "$to_number"
expect_success "from_number environment variable should be set" is_not_empty "$from_number"
expect_success "message environment variable should be set" is_not_empty "$message"
expect_success "sms_media environment variable should be set" is_not_empty "$sms_media"
# Send sms request
expect_error "The command should be called, but should not complete sucessfully" print_and_do_command ./step.sh
)
test_result=$?
inspect_test_result $test_result
# [TEST] Call the command with from_number not set,
# it should raise an error message and exit
#
(
print_new_test
test_env_cleanup
# Set env vars
export account_sid="dsa4321"
export auth_token="dsa4321"
export to_number="dsa4321"
export message="dsa4321"
export sms_media="dsa4321"
# All env vars should exist except from_number
expect_success "account_sid environment variable should be set" is_not_empty "$account_sid"
expect_success "auth_token environment variable should be set" is_not_empty "$auth_token"
expect_success "to_number environment variable should be set" is_not_empty "$to_number"
expect_error "from_number environment variable should NOT be set" is_not_empty "$from_number"
expect_success "message environment variable should be set" is_not_empty "$message"
expect_success "sms_media environment variable should be set" is_not_empty "$sms_media"
# Send sms request
expect_error "The command should be called, but should not complete sucessfully" print_and_do_command ./step.sh
)
test_result=$?
inspect_test_result $test_result
# [TEST] Call the command with message not set,
# it should raise an error message and exit
#
(
print_new_test
test_env_cleanup
# Set env vars
export account_sid="dsa4321"
export auth_token="dsa4321"
export to_number="dsa4321"
export from_number="dsa4321"
export sms_media="dsa4321"
# All env vars should exist except message
expect_success "account_sid environment variable should be set" is_not_empty "$account_sid"
expect_success "auth_token environment variable should be set" is_not_empty "$auth_token"
expect_success "to_number environment variable should be set" is_not_empty "$to_number"
expect_success "from_number environment variable should be set" is_not_empty "$from_number"
expect_error "message environment variable should NOT be set" is_not_empty "$message"
expect_success "sms_media environment variable should be set" is_not_empty "$sms_media"
# Send sms request
expect_error "The command should be called, but should not complete sucessfully" print_and_do_command ./step.sh
)
test_result=$?
inspect_test_result $test_result
# --------------------
# --- Test Results ---
echo
echo "--- Results ---"
echo " * Errors: $test_results_error_count"
echo " * Success: $test_results_success_count"
echo "---------------"
if [ $test_results_error_count -eq 0 ]; then
echo "-> SUCCESS"
else
echo "-> FAILED"
fi