Update test.sh
This commit is contained in:
65
test.sh
65
test.sh
@@ -83,10 +83,11 @@ function setup_test_environment() {
|
|||||||
log_info "Setting up test environment..."
|
log_info "Setting up test environment..."
|
||||||
CLEANUP_NEEDED=true
|
CLEANUP_NEEDED=true
|
||||||
|
|
||||||
# Create test directory
|
# Create test directory structure
|
||||||
rm -rf "${TEST_DIR}"
|
rm -rf "${TEST_DIR}"
|
||||||
mkdir -p "${TEST_DIR}/storage"
|
mkdir -p "${TEST_DIR}/storage"
|
||||||
mkdir -p "${TEST_DIR}/test_files"
|
mkdir -p "${TEST_DIR}/test_files"
|
||||||
|
mkdir -p "${TEST_DIR}/config"
|
||||||
|
|
||||||
# Generate hashed token
|
# Generate hashed token
|
||||||
log_info "Generating authentication token..."
|
log_info "Generating authentication token..."
|
||||||
@@ -96,8 +97,8 @@ function setup_test_environment() {
|
|||||||
die "Failed to generate hashed token"
|
die "Failed to generate hashed token"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Create test configuration
|
# Create test configuration in config directory
|
||||||
cat > "${TEST_DIR}/sos_config.json" <<EOF
|
cat > "${TEST_DIR}/config/sos_config.json" <<EOF
|
||||||
{
|
{
|
||||||
"write_tokens": ["${HASHED_TOKEN}"]
|
"write_tokens": ["${HASHED_TOKEN}"]
|
||||||
}
|
}
|
||||||
@@ -120,33 +121,16 @@ function start_test_server() {
|
|||||||
log_info "Starting SOS test server on port ${TEST_PORT}..."
|
log_info "Starting SOS test server on port ${TEST_PORT}..."
|
||||||
|
|
||||||
# Ensure the config file exists and is readable
|
# Ensure the config file exists and is readable
|
||||||
if [ ! -f "${TEST_DIR}/sos_config.json" ]; then
|
if [ ! -f "${TEST_DIR}/config/sos_config.json" ]; then
|
||||||
die "Config file ${TEST_DIR}/sos_config.json does not exist"
|
die "Config file ${TEST_DIR}/config/sos_config.json does not exist"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Use absolute path for volume mount to avoid issues in CI
|
# Start the container without mounting config file (will use docker cp instead)
|
||||||
# Use realpath if available, otherwise fallback to readlink or pwd
|
# Only mount the storage directory
|
||||||
if command -v realpath &> /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)
|
|
||||||
local container_id=$(docker run -d \
|
local container_id=$(docker run -d \
|
||||||
--name "${CONTAINER_NAME}" \
|
--name "${CONTAINER_NAME}" \
|
||||||
-p "${TEST_PORT}:80" \
|
-p "${TEST_PORT}:80" \
|
||||||
-v "${config_path}:/data/sos_config.json:ro" \
|
-v "${TEST_DIR}/storage:/data/storage" \
|
||||||
-v "${storage_path}:/data/storage" \
|
|
||||||
gitea.jde.nz/public/simple-object-server 2>&1)
|
gitea.jde.nz/public/simple-object-server 2>&1)
|
||||||
|
|
||||||
if [ $? -ne 0 ]; then
|
if [ $? -ne 0 ]; then
|
||||||
@@ -156,8 +140,25 @@ function start_test_server() {
|
|||||||
|
|
||||||
log_info "Container started with ID: ${container_id:0:12}"
|
log_info "Container started with ID: ${container_id:0:12}"
|
||||||
|
|
||||||
# Give container a moment to initialize
|
# Copy the config file into the container using docker cp
|
||||||
sleep 2
|
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
|
# 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
|
||||||
@@ -165,12 +166,10 @@ function start_test_server() {
|
|||||||
docker logs "${CONTAINER_NAME}" 2>&1
|
docker logs "${CONTAINER_NAME}" 2>&1
|
||||||
|
|
||||||
# Additional debugging for CI environment
|
# Additional debugging for CI environment
|
||||||
log_error "Debug: Checking mounted paths in container:"
|
log_error "Debug: Checking /data directory in container:"
|
||||||
docker run --rm -v "${config_path}:/data/sos_config.json:ro" alpine ls -la /data/ 2>&1 || true
|
docker exec "${CONTAINER_NAME}" ls -la /data/ 2>&1 || true
|
||||||
log_error "Debug: Config file on host:"
|
log_error "Debug: Config file in container:"
|
||||||
ls -la "${config_path}" 2>&1 || true
|
docker exec "${CONTAINER_NAME}" cat /data/sos_config.json 2>&1 || true
|
||||||
log_error "Debug: Config file contents:"
|
|
||||||
cat "${config_path}" 2>&1 || true
|
|
||||||
|
|
||||||
die "Container failed to stay running"
|
die "Container failed to stay running"
|
||||||
fi
|
fi
|
||||||
|
Reference in New Issue
Block a user