-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathe2e_tests.sh
executable file
·68 lines (57 loc) · 1.54 KB
/
e2e_tests.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
#!/bin/bash
# Define colors for terminal output
GREEN='\033[0;32m'
RED='\033[0;31m'
NC='\033[0m' # No Color
N=0
# Define base URL of your webserver
BASE_URL="http://localhost:8888"
# Define endpoints to test (modify as needed)
ENDPOINTS=(
"/"
"/example"
"/test"
"/42"
"/.."
)
EXPECTED_RESULT=(
200
200
200
404
200
)
# Loop through each endpoint
for i in "${!ENDPOINTS[@]}"; do # Iterate over indices of the array
endpoint="${ENDPOINTS[$i]}"
expected_code="${EXPECTED_RESULT[$i]}"
full_url="$BASE_URL$endpoint"
response=$(curl -sSL -o /dev/null -w "%{http_code}" "$full_url")
if [[ $response == $expected_code ]]; then
echo -e "$N - ${GREEN}OK${NC} - GET $full_url"
else
echo -e "$N - ${RED}FAILED${NC} - GET $full_url (HTTP code: $response)"]
exit 1
fi
N=$((N+1))
done
declare -A TEST_CASES=(
["/:POST"]="name=TestUser&email=test@example.com" # Create a user
["/:PUT"]="name=UpdatedName" # Update user 123
["/:PATCH"]="status=published" # Partially update article 456
["/:DELETE"]=""
)
for item in "${!TEST_CASES[@]}"; do
endpoint=$(echo $item | cut -d ':' -f 1)
method=$(echo $item | cut -d ':' -f 2)
data=$(echo ${TEST_CASES[$item]})
full_url="$BASE_URL$endpoint"
response=$(curl -sSL -o /dev/null -w "%{http_code}" -X $method -d "DATA" "$full_url")
if [[ $response == 405 ]]; then
echo -e "$N - ${GREEN}OK${NC} - $method $full_url"
else
echo -e "$N - ${RED}FAILED${NC} - $method $full_url (HTTP code: $response)"
exit 1
fi
N=$((N+1))
done