improve test

This commit is contained in:
Jason Swank
2026-05-11 13:00:45 -04:00
parent c92a46c49d
commit 07bdbbd224

View File

@@ -83,21 +83,29 @@ tasks:
- |
function test_service() {
local path="$1"
local url="https://{{.SERVICE_NAME}}.{{.DOMAIN}}/$path"
# Use curl to capture both HTTP status code and response body
local response=$(curl -s -w "%{http_code}" https://{{.SERVICE_NAME}}.{{.DOMAIN}}/$path)
# Use curl to capture response body and append the http_code at the end.
# Using `|| true` prevents Task from failing if curl encounters a network error.
local response=$(curl -s -w "%{http_code}" "$url") || true
# Extract status code (last 3 chars) and body (everything else)
local status_code="${response:${#response}-3}"
local status_text="ERROR"
local body="${response:0:${#response}-3}"
if [ "$status_code" -lt 399 ]; then
printf "GET /%s -> [SUCCESS] Status: %s, Body: %s\n" "$path" "$status_code" "$body"
else
printf "GET /%s -> [FAILURE] Status: %s, Body: %s\n" "$path" "$status_code" "$body"
# Check if curl failed completely (e.g. DNS failure), resulting in empty output
if [ -z "$response" ] || [ "${response:${#response}-3}" = "000" ]; then
body="[Network failure or unresolvable host]"
fi
# Explicitly return 0 so the task does not fail if a test fails
# Status code in the 200-399 range is considered a successful response
if [ "$status_code" -ge 200 ] && [ "$status_code" -lt 400 ]; then
status_text="SUCCESS"
fi
printf "GET /%s -> [%s] Status: %s, Body: %s\n" "$path" "$status_text" "$status_code" "$body"
return 0
}