summaryrefslogtreecommitdiffhomepage
path: root/vhosts/t/phpcon-kagawa-2025/tests/test_404.sh
blob: 509dfdbf34f17d906cd1cac5c5b475b2bcb6fbad (plain)
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
#!/bin/bash
# Test for 404 Not Found response

BASE_URL="${BASE_URL:-http://127.0.0.1:8080}"
PASSED=0
FAILED=0

echo "Testing 404 Not Found"
echo "====================="

# Test 1: GET / returns 404
echo -n "Test 1: GET / returns 404... "
response=$(curl -s -o /dev/null -w "%{http_code}" "$BASE_URL/")
if [ "$response" = "404" ]; then
    echo "PASSED"
    ((PASSED++))
else
    echo "FAILED (got $response)"
    ((FAILED++))
fi

# Test 2: GET /nonexistent returns 404
echo -n "Test 2: GET /nonexistent returns 404... "
response=$(curl -s -o /dev/null -w "%{http_code}" "$BASE_URL/nonexistent")
if [ "$response" = "404" ]; then
    echo "PASSED"
    ((PASSED++))
else
    echo "FAILED (got $response)"
    ((FAILED++))
fi

# Test 3: GET /foo/bar returns 404
echo -n "Test 3: GET /foo/bar returns 404... "
response=$(curl -s -o /dev/null -w "%{http_code}" "$BASE_URL/foo/bar")
if [ "$response" = "404" ]; then
    echo "PASSED"
    ((PASSED++))
else
    echo "FAILED (got $response)"
    ((FAILED++))
fi

# Test 4: 404 response body contains "404 Not Found"
echo -n "Test 4: 404 response body contains '404 Not Found'... "
content=$(curl -s "$BASE_URL/nonexistent")
if [ "$content" = "404 Not Found" ]; then
    echo "PASSED"
    ((PASSED++))
else
    echo "FAILED (got '$content')"
    ((FAILED++))
fi

echo ""
echo "Results: $PASSED passed, $FAILED failed"

if [ $FAILED -gt 0 ]; then
    exit 1
fi
exit 0