-
Notifications
You must be signed in to change notification settings - Fork 0
/
smoke_test.sh
126 lines (107 loc) · 4.23 KB
/
smoke_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
#!/bin/bash
# Colors
RED="\033[33;31m";
GREEN="\033[33;32m"
YELLOW="\033[38;5;11m"
RESET="\033[0m"
BASEURL="https://adrian.tilita.ro/"
APPURL="http://127.0.0.1:9293/"
AUTH="test:new"
paddash=$(printf '%0.1s' "-"{1..60})
padspace=$(printf '%0.1s' " "{1..60})
padlength=74
function showresult {
leftstring=$1
rightstring=$2
printf '%s' "$leftstring"
printf '%*.*s' 0 $((padlength - ${#leftstring} - ${#rightstring} )) "$padspace"
printf "[ ${rightstring} ]\n"
}
echo "${YELLOW}Running smoke tests${RESET}"
echo "${YELLOW}${paddash}${RESET}"
# Delete first if any legacy left
curl -o /dev/null --silent -u ${AUTH} -H "Content-Type: application/json" -X DELETE ${APPURL}url/check-redirect
# Create new
HTTP_CALL=$(curl -o /dev/null --silent -u ${AUTH} -H "Content-Type: application/json" -X POST -d '{"from_url": "check-redirect","to_url": "http://example.com"}' --write-out '%{http_code}' ${APPURL}url)
IFS='-' read -r -a HTTP_STATUS <<< "$HTTP_CALL"
leftstring="CREATE NEW"
if [ ${HTTP_STATUS} -ne 201 ]
then
rightstring="${RED}CRITICAL${RESET}"
showresult "${leftstring}" "${rightstring}"
printf " - Got ${RED}${HTTP_STATUS}${RESET} instead of ${GREEN}201${RESET}\n"
exit 2
else
rightstring="${GREEN}OK${RESET}"
showresult "${leftstring}" "${rightstring}"
fi
# Create duplicate
HTTP_CALL=$(curl -o /dev/null --silent -u ${AUTH} -H "Content-Type: application/json" -X POST -d '{"from_url": "check-redirect","to_url": "http://example.com"}' --write-out '%{http_code}' ${APPURL}url)
IFS='-' read -r -a HTTP_STATUS <<< "$HTTP_CALL"
leftstring="CREATE DUPLICATE"
if [ ${HTTP_STATUS} -ne 409 ]
then
rightstring="${RED}CRITICAL${RESET}"
showresult "${leftstring}" "${rightstring}"
printf " - Got ${RED}${HTTP_STATUS}${RESET} instead of ${GREEN}409${RESET}\n"
exit 2
else
rightstring="${GREEN}OK${RESET}"
showresult "${leftstring}" "${rightstring}"
fi
# Call
HTTP_CALL=$(curl -o /dev/null --silent -u ${AUTH} -H "Content-Type: application/json" --write-out '%{http_code}' ${APPURL}check-redirect)
IFS='-' read -r -a HTTP_STATUS <<< "$HTTP_CALL"
leftstring="REDIRECT URL"
if [ ${HTTP_STATUS} -ne 301 ]
then
rightstring="${RED}CRITICAL${RESET}"
showresult "${leftstring}" "${rightstring}"
printf " - Got ${RED}${HTTP_STATUS}${RESET} instead of ${GREEN}301${RESET}\n"
exit 2
else
rightstring="${GREEN}OK${RESET}"
showresult "${leftstring}" "${rightstring}"
fi
# Update
HTTP_CALL=$(curl -o /dev/null --silent -u ${AUTH} -H "Content-Type: application/json" -X PATCH -d '{"from_url": "check-redirect","to_url": "https://www.github.com"}' --write-out '%{http_code}' ${APPURL}url)
IFS='-' read -r -a HTTP_STATUS <<< "$HTTP_CALL"
leftstring="UPDATE URL"
if [ ${HTTP_STATUS} -ne 200 ]
then
rightstring="${RED}CRITICAL${RESET}"
showresult "${leftstring}" "${rightstring}"
printf " - Got ${RED}${HTTP_STATUS}${RESET} instead of ${GREEN}200${RESET}\n"
exit 2
else
rightstring="${GREEN}OK${RESET}"
showresult "${leftstring}" "${rightstring}"
fi
# Update
HTTP_CALL=$(curl -o /dev/null --silent -u ${AUTH} -H "Content-Type: application/json" -X DELETE --write-out '%{http_code}' ${APPURL}url/check-redirect)
IFS='-' read -r -a HTTP_STATUS <<< "$HTTP_CALL"
leftstring="DELETE URL"
if [ ${HTTP_STATUS} -ne 200 ]
then
rightstring="${RED}CRITICAL${RESET}"
showresult "${leftstring}" "${rightstring}"
printf " - Got ${RED}${HTTP_STATUS}${RESET} instead of ${GREEN}200${RESET}\n"
exit 2
else
rightstring="${GREEN}OK${RESET}"
showresult "${leftstring}" "${rightstring}"
fi
# Call
HTTP_CALL=$(curl -o /dev/null --silent -u ${AUTH} -H "Content-Type: application/json" --write-out '%{http_code}' ${APPURL}check-redirect)
IFS='-' read -r -a HTTP_STATUS <<< "$HTTP_CALL"
leftstring="REDIRECT URL"
if [ ${HTTP_STATUS} -ne 307 ]
then
rightstring="${RED}CRITICAL${RESET}"
showresult "${leftstring}" "${rightstring}"
printf " - Got ${RED}${HTTP_STATUS}${RESET} instead of ${GREEN}307${RESET}\n"
exit 2
else
rightstring="${GREEN}OK${RESET}"
showresult "${leftstring}" "${rightstring}"
fi