Update test.sh
This commit is contained in:
55
test.sh
55
test.sh
@@ -184,6 +184,15 @@ function start_test_server() {
|
|||||||
TEST_PORT="${new_port}"
|
TEST_PORT="${new_port}"
|
||||||
fi
|
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
|
# Check if container is still running
|
||||||
if ! docker ps --format '{{.Names}}' | grep -q "^${CONTAINER_NAME}$"; then
|
if ! docker ps --format '{{.Names}}' | grep -q "^${CONTAINER_NAME}$"; then
|
||||||
log_error "Container stopped unexpectedly. Logs:"
|
log_error "Container stopped unexpectedly. Logs:"
|
||||||
@@ -204,13 +213,22 @@ function start_test_server() {
|
|||||||
local attempt=0
|
local attempt=0
|
||||||
|
|
||||||
while [ $attempt -lt $max_attempts ]; do
|
while [ $attempt -lt $max_attempts ]; do
|
||||||
# Try to check if the server responds - use a simple curl with timeout
|
# Try container IP first (for Docker-in-Docker), then localhost with mapped port
|
||||||
# The SOS server should respond to a basic GET request
|
local http_code="000"
|
||||||
local http_code=$(curl -s --max-time 2 -o /dev/null -w "%{http_code}" "http://localhost:${TEST_PORT}/" 2>/dev/null || echo "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
|
# Debug: Show HTTP code and container status on first few attempts
|
||||||
if [ $attempt -lt 3 ]; then
|
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
|
# Check if container is actually running
|
||||||
if docker ps --format '{{.Names}}' | grep -q "^${CONTAINER_NAME}$"; then
|
if docker ps --format '{{.Names}}' | grep -q "^${CONTAINER_NAME}$"; then
|
||||||
log_info "Container is running, checking logs..."
|
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
|
if [ "$http_code" = "200" ] || [ "$http_code" = "204" ] || [ "$http_code" = "404" ]; then
|
||||||
log_info "Server is ready! (HTTP ${http_code})"
|
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
|
return 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -258,7 +289,16 @@ function test_upload() {
|
|||||||
export SOS_WRITE_TOKEN="${TEST_TOKEN}"
|
export SOS_WRITE_TOKEN="${TEST_TOKEN}"
|
||||||
# Override to use HTTP for local testing
|
# Override to use HTTP for local testing
|
||||||
export SOS_TEST_MODE=1
|
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
|
if [ ${PIPESTATUS[0]} -ne 0 ]; then
|
||||||
log_error "Upload failed for ${file}"
|
log_error "Upload failed for ${file}"
|
||||||
@@ -281,8 +321,9 @@ function test_retrieval() {
|
|||||||
|
|
||||||
log_info "Testing retrieval by ${identifier}"
|
log_info "Testing retrieval by ${identifier}"
|
||||||
|
|
||||||
# Try to retrieve the file
|
# Try to retrieve the file using the determined host
|
||||||
local response=$(curl -s "http://localhost:${TEST_PORT}/${identifier}")
|
local test_host="${SOS_TEST_HOST:-localhost:${TEST_PORT}}"
|
||||||
|
local response=$(curl -s "http://${test_host}/${identifier}")
|
||||||
|
|
||||||
if [ -z "${response}" ]; then
|
if [ -z "${response}" ]; then
|
||||||
log_error "Failed to retrieve by ${identifier}"
|
log_error "Failed to retrieve by ${identifier}"
|
||||||
|
Reference in New Issue
Block a user