-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.sh
executable file
·98 lines (84 loc) · 2.94 KB
/
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
#!/usr/bin/env bash
dir="$(dirname "$0")"
if [[ ! -e ./assert.sh ]]; then
wget https://raw.githubusercontent.com/torokmark/assert.sh/master/assert.sh
fi
source "./assert.sh"
function result() {
if [ "$?" == 0 ]; then
log_success "OK"
fi
}
function localTests() {
log_header "Local tests assert : test.sh"
today=$(date +"%m-%d")
command_table=(
"$(curl -s -X PUT -d '{"dateOfBirth": "1979-11-31"}' http://127.0.0.1:9000/hello/Yezhi)"
"$(curl -s http://127.0.0.1:9000/hello/Yezhi)"
"$(curl -s http://127.0.0.1:9000/notfound/)"
"$(curl -s http://127.0.0.1:9000/health/)"
"$(curl -s -X PUT -d '{"dateOfBirth": "1965-10-22"}' http://127.0.0.1:9000/hello/Rudy)"
"$(curl -s -X PUT -d '{"dateOfBirth": "1950-03-14"}' http://127.0.0.1:9000/hello/Duda)"
"$(curl -s -X PUT -d '{"dateOfBirth": "1999-'${today}'"}' http://127.0.0.1:9000/hello/Dada)"
"$(curl -s http://127.0.0.1:9000/hello/Dada)"
)
expected_table=(
'Invalid dateOfBirth value (YYYY-MM-DD)'
'User Yezhi, is not in database'
'404 page not found'
'{"Service is healthy": true}'
''
''
''
'{"message":"Hello, Dada! Happy Birthday!"}'
)
for ((i=0;i<${#command_table[@]};++i)); do
echo "Test #" "$i" "${command_table[i]}"
assert_eq "${command_table[i]}" "${expected_table[i]}" "Failed!"; result;
done
}
function remoteTests() {
log_header "Remote tests assert : test.sh"
REMOTE_HOST=$(<"$dir/.ext.ipv4")
today=$(date +"%m-%d")
echo "Checking service on: $REMOTE_HOST"
command_table=(
"$(curl -s -X PUT -d '{"dateOfBirth": "1979-11-31"}' http://${REMOTE_HOST}:80/hello/Yezhi)"
"$(curl -s http://${REMOTE_HOST}:80/hello/Yezhi)"
"$(curl -s http://${REMOTE_HOST}:80/notfound/)"
"$(curl -s http://${REMOTE_HOST}:80/health/)"
"$(curl -s -X PUT -d '{"dateOfBirth": "1965-10-22"}' http://${REMOTE_HOST}:80/hello/Rudy)"
"$(curl -s -X PUT -d '{"dateOfBirth": "1950-03-14"}' http://${REMOTE_HOST}:80/hello/Duda)"
"$(curl -s -X PUT -d '{"dateOfBirth": "1999-'${today}'"}' http://${REMOTE_HOST}:80/hello/Dada)"
"$(curl -s http://${REMOTE_HOST}:80/hello/Dada)"
)
expected_table=(
'Invalid dateOfBirth value (YYYY-MM-DD)'
'User Yezhi, is not in database'
'404 page not found'
'{"Service is healthy": true}'
''
''
''
'{"message":"Hello, Dada! Happy Birthday!"}'
)
for ((i=0;i<${#command_table[@]};++i)); do
echo "Test #" "$i" "${command_table[i]}"
assert_eq "${command_table[i]}" "${expected_table[i]}" "Failed!"; result;
done
}
while [[ $# -gt 0 ]]; do
case $1 in
remote)
remoteTests "$HOST";
shift
;;
local)
localTests;
shift
;;
*)
echo "Usage: ./test.sh (local|remote)";
shift
esac
done