diff --git a/test.sh b/test.sh index 9526bee..428f848 100755 --- a/test.sh +++ b/test.sh @@ -83,10 +83,11 @@ function setup_test_environment() { log_info "Setting up test environment..." CLEANUP_NEEDED=true - # Create test directory + # Create test directory structure rm -rf "${TEST_DIR}" mkdir -p "${TEST_DIR}/storage" mkdir -p "${TEST_DIR}/test_files" + mkdir -p "${TEST_DIR}/config" # Generate hashed token log_info "Generating authentication token..." @@ -96,8 +97,8 @@ function setup_test_environment() { die "Failed to generate hashed token" fi - # Create test configuration - cat > "${TEST_DIR}/sos_config.json" < "${TEST_DIR}/config/sos_config.json" < /dev/null; then - local config_path=$(realpath "${TEST_DIR}/sos_config.json") - local storage_path=$(realpath "${TEST_DIR}/storage") - elif command -v readlink &> /dev/null; then - local config_path=$(readlink -f "${TEST_DIR}/sos_config.json") - local storage_path=$(readlink -f "${TEST_DIR}/storage") - else - # Fallback to constructing absolute path manually - local config_path="$(cd "${TEST_DIR}" && pwd)/sos_config.json" - local storage_path="$(cd "${TEST_DIR}" && pwd)/storage" - fi - - log_info "Using config path: ${config_path}" - log_info "Using storage path: ${storage_path}" - - # Start the container (server runs on port 80 inside container) + # Start the container without mounting config file (will use docker cp instead) + # Only mount the storage directory local container_id=$(docker run -d \ --name "${CONTAINER_NAME}" \ -p "${TEST_PORT}:80" \ - -v "${config_path}:/data/sos_config.json:ro" \ - -v "${storage_path}:/data/storage" \ + -v "${TEST_DIR}/storage:/data/storage" \ gitea.jde.nz/public/simple-object-server 2>&1) if [ $? -ne 0 ]; then @@ -156,8 +140,25 @@ function start_test_server() { log_info "Container started with ID: ${container_id:0:12}" - # Give container a moment to initialize - sleep 2 + # Copy the config file into the container using docker cp + log_info "Copying config file into container..." + docker cp "${TEST_DIR}/config/sos_config.json" "${CONTAINER_NAME}:/data/sos_config.json" + if [ $? -ne 0 ]; then + log_error "Failed to copy config file into container" + docker logs "${CONTAINER_NAME}" 2>&1 + die "Failed to copy config file" + fi + + # Restart the container to pick up the config file + log_info "Restarting container to load config..." + docker restart "${CONTAINER_NAME}" >/dev/null 2>&1 + if [ $? -ne 0 ]; then + log_error "Failed to restart container" + die "Failed to restart container" + fi + + # Give container a moment to initialize after restart + sleep 3 # Check if container is still running if ! docker ps --format '{{.Names}}' | grep -q "^${CONTAINER_NAME}$"; then @@ -165,12 +166,10 @@ function start_test_server() { docker logs "${CONTAINER_NAME}" 2>&1 # Additional debugging for CI environment - log_error "Debug: Checking mounted paths in container:" - docker run --rm -v "${config_path}:/data/sos_config.json:ro" alpine ls -la /data/ 2>&1 || true - log_error "Debug: Config file on host:" - ls -la "${config_path}" 2>&1 || true - log_error "Debug: Config file contents:" - cat "${config_path}" 2>&1 || true + log_error "Debug: Checking /data directory in container:" + docker exec "${CONTAINER_NAME}" ls -la /data/ 2>&1 || true + log_error "Debug: Config file in container:" + docker exec "${CONTAINER_NAME}" cat /data/sos_config.json 2>&1 || true die "Container failed to stay running" fi