Update test.sh
Some checks failed
Build-Test-Publish / build (linux/arm64) (push) Has been cancelled
Build-Test-Publish / build (linux/amd64) (push) Has been cancelled

This commit is contained in:
Your Name
2025-08-24 11:14:11 +12:00
parent 7d4c75bcf3
commit 834e88af46

55
test.sh
View File

@@ -184,6 +184,15 @@ function start_test_server() {
TEST_PORT="${new_port}"
fi
# Get container IP address for Docker-in-Docker environments
CONTAINER_IP=$(docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' "${CONTAINER_NAME}")
if [ -z "${CONTAINER_IP}" ]; then
log_warning "Could not get container IP, will use localhost"
CONTAINER_IP="localhost"
else
log_info "Container IP address: ${CONTAINER_IP}"
fi
# Check if container is still running
if ! docker ps --format '{{.Names}}' | grep -q "^${CONTAINER_NAME}$"; then
log_error "Container stopped unexpectedly. Logs:"
@@ -204,13 +213,22 @@ function start_test_server() {
local attempt=0
while [ $attempt -lt $max_attempts ]; do
# Try to check if the server responds - use a simple curl with timeout
# The SOS server should respond to a basic GET request
local http_code=$(curl -s --max-time 2 -o /dev/null -w "%{http_code}" "http://localhost:${TEST_PORT}/" 2>/dev/null || echo "000")
# Try container IP first (for Docker-in-Docker), then localhost with mapped port
local http_code="000"
# Try direct container IP on port 80 (works in Docker-in-Docker)
if [ "${CONTAINER_IP}" != "localhost" ]; then
http_code=$(curl -s --max-time 2 -o /dev/null -w "%{http_code}" "http://${CONTAINER_IP}:80/" 2>/dev/null || echo "000")
fi
# If that didn't work, try localhost with mapped port
if [ "$http_code" = "000" ]; then
http_code=$(curl -s --max-time 2 -o /dev/null -w "%{http_code}" "http://localhost:${TEST_PORT}/" 2>/dev/null || echo "000")
fi
# Debug: Show HTTP code and container status on first few attempts
if [ $attempt -lt 3 ]; then
log_info "Health check attempt $((attempt + 1)): HTTP code ${http_code}"
log_info "Health check attempt $((attempt + 1)): HTTP code ${http_code} (IP: ${CONTAINER_IP}:80, localhost:${TEST_PORT})"
# Check if container is actually running
if docker ps --format '{{.Names}}' | grep -q "^${CONTAINER_NAME}$"; then
log_info "Container is running, checking logs..."
@@ -222,6 +240,19 @@ function start_test_server() {
if [ "$http_code" = "200" ] || [ "$http_code" = "204" ] || [ "$http_code" = "404" ]; then
log_info "Server is ready! (HTTP ${http_code})"
# Set which connection method works for later use
if [ "${CONTAINER_IP}" != "localhost" ]; then
# Test which one actually worked
if curl -s --max-time 1 -o /dev/null "http://${CONTAINER_IP}:80/" 2>/dev/null; then
export SOS_TEST_HOST="${CONTAINER_IP}:80"
log_info "Using container IP: ${SOS_TEST_HOST}"
else
export SOS_TEST_HOST="localhost:${TEST_PORT}"
log_info "Using localhost: ${SOS_TEST_HOST}"
fi
else
export SOS_TEST_HOST="localhost:${TEST_PORT}"
fi
return 0
fi
@@ -258,7 +289,16 @@ function test_upload() {
export SOS_WRITE_TOKEN="${TEST_TOKEN}"
# Override to use HTTP for local testing
export SOS_TEST_MODE=1
"${SCRIPT_DIR}/sos" upload "localhost:${TEST_PORT}" "${file}" "${label}" ${extra_labels} 2>&1 | tee "${TEST_DIR}/upload_output.txt"
# Use the determined host (either container IP or localhost)
local test_host="${SOS_TEST_HOST:-localhost:${TEST_PORT}}"
# For container IP, we use IP:80 directly, for localhost we use localhost:port
if [[ "${test_host}" == *":"* ]]; then
# Has port, use as is
"${SCRIPT_DIR}/sos" upload "${test_host}" "${file}" "${label}" ${extra_labels} 2>&1 | tee "${TEST_DIR}/upload_output.txt"
else
# No port, shouldn't happen but handle it
"${SCRIPT_DIR}/sos" upload "${test_host}:80" "${file}" "${label}" ${extra_labels} 2>&1 | tee "${TEST_DIR}/upload_output.txt"
fi
if [ ${PIPESTATUS[0]} -ne 0 ]; then
log_error "Upload failed for ${file}"
@@ -281,8 +321,9 @@ function test_retrieval() {
log_info "Testing retrieval by ${identifier}"
# Try to retrieve the file
local response=$(curl -s "http://localhost:${TEST_PORT}/${identifier}")
# Try to retrieve the file using the determined host
local test_host="${SOS_TEST_HOST:-localhost:${TEST_PORT}}"
local response=$(curl -s "http://${test_host}/${identifier}")
if [ -z "${response}" ]; then
log_error "Failed to retrieve by ${identifier}"