71 lines
1.9 KiB
Bash
Executable File
71 lines
1.9 KiB
Bash
Executable File
#!/bin/bash
|
|
# test_ipv4_validator.sh - Automated tests for validate_ipv4.sh
|
|
# Run this to verify the IPv4 validator works correctly
|
|
|
|
SCRIPT="/root/.hermes/wizard-outputs/spark/validate_ipv4.sh"
|
|
ERRORS=0
|
|
|
|
test_case() {
|
|
local input="$1"
|
|
local expected="$2"
|
|
local output
|
|
output=$($SCRIPT "$input" 2>/dev/null)
|
|
local exit_code=$?
|
|
|
|
if [[ "$expected" == "valid" ]]; then
|
|
if [[ "$output" == "valid" && $exit_code -eq 0 ]]; then
|
|
echo "PASS: '$input' -> valid (exit 0)"
|
|
else
|
|
echo "FAIL: '$input' expected valid, got '$output' (exit $exit_code)"
|
|
((ERRORS++))
|
|
fi
|
|
else
|
|
if [[ "$output" == "invalid" && $exit_code -ne 0 ]]; then
|
|
echo "PASS: '$input' -> invalid (exit $exit_code)"
|
|
else
|
|
echo "FAIL: '$input' expected invalid, got '$output' (exit $exit_code)"
|
|
((ERRORS++))
|
|
fi
|
|
fi
|
|
}
|
|
|
|
echo "=== IPv4 Validator Test Suite ==="
|
|
echo ""
|
|
|
|
# Valid addresses
|
|
test_case "192.168.1.1" "valid"
|
|
test_case "0.0.0.0" "valid"
|
|
test_case "255.255.255.255" "valid"
|
|
test_case "10.0.0.1" "valid"
|
|
test_case "172.16.0.1" "valid"
|
|
test_case "8.8.8.8" "valid"
|
|
test_case "127.0.0.1" "valid"
|
|
test_case "1.2.3.4" "valid"
|
|
test_case "200.200.200.200" "valid"
|
|
|
|
# Invalid addresses
|
|
test_case "256.1.1.1" "invalid"
|
|
test_case "1.2.3" "invalid"
|
|
test_case "1.2.3.4.5" "invalid"
|
|
test_case "a.b.c.d" "invalid"
|
|
test_case "192.168.1.300" "invalid"
|
|
test_case "999.999.999.999" "invalid"
|
|
test_case "192.168.1.256" "invalid"
|
|
test_case "255.255.255.256" "invalid"
|
|
test_case "-1.2.3.4" "invalid"
|
|
test_case "192.168.1.-1" "invalid"
|
|
test_case "" "invalid"
|
|
test_case "192.168.1.1." "invalid"
|
|
test_case ".192.168.1.1" "invalid"
|
|
test_case "192.168.1.1a" "invalid"
|
|
|
|
echo ""
|
|
echo "=== Results: $ERRORS failures ==="
|
|
|
|
if [[ $ERRORS -eq 0 ]]; then
|
|
echo "ALL TESTS PASSED"
|
|
exit 0
|
|
else
|
|
echo "SOME TESTS FAILED"
|
|
exit 1
|
|
fi |