test: Add 8 and update 14 files
This commit is contained in:
@@ -4,6 +4,10 @@ set -euo pipefail
|
||||
SCRIPT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
|
||||
MAIN_DIR=$(cd "${SCRIPT_DIR}/.." && pwd)
|
||||
|
||||
# Variables for cleanup
|
||||
COMPOSE_FILE="${SCRIPT_DIR}/compose.yaml"
|
||||
CLEANUP_NEEDED=false
|
||||
|
||||
# FUNCTIONS
|
||||
function title() {
|
||||
echo "----------------------------------------"
|
||||
@@ -16,11 +20,34 @@ function title() {
|
||||
echo "----------------------------------------"
|
||||
}
|
||||
|
||||
function cleanup() {
|
||||
if [ "$CLEANUP_NEEDED" = true ]; then
|
||||
echo ""
|
||||
title "Cleaning up containers"
|
||||
|
||||
# Stop and remove the test container
|
||||
docker stop sos-test 2>/dev/null || true
|
||||
docker rm -v sos-test 2>/dev/null || true
|
||||
|
||||
# Use docker compose to clean up
|
||||
if [ -f "${COMPOSE_FILE}" ]; then
|
||||
docker compose -f "${COMPOSE_FILE}" down 2>/dev/null || true
|
||||
docker compose -f "${COMPOSE_FILE}" rm -v -f 2>/dev/null || true
|
||||
fi
|
||||
|
||||
echo "Cleanup completed"
|
||||
fi
|
||||
}
|
||||
|
||||
function die() {
|
||||
title "error: $1"
|
||||
cleanup
|
||||
exit 1
|
||||
}
|
||||
|
||||
# Set up trap to ensure cleanup on exit
|
||||
trap cleanup EXIT INT TERM
|
||||
|
||||
function wait_for_container {
|
||||
container_id="$1"
|
||||
container_name="$(docker inspect "${container_id}" --format '{{ .Name }}')"
|
||||
@@ -50,15 +77,22 @@ ${SCRIPT_DIR}/../build.sh
|
||||
|
||||
|
||||
#------------------------------------------------------------------------------------------------
|
||||
# Generate test configuration with random tokens
|
||||
title "Generating test configuration"
|
||||
${SCRIPT_DIR}/generate_test_config.sh
|
||||
# Use static test configuration with known tokens for Docker testing
|
||||
title "Setting up test configuration"
|
||||
# Use the static Docker config with known hashes
|
||||
cp ${SCRIPT_DIR}/sos_config_docker.json ${SCRIPT_DIR}/sos_config.json
|
||||
|
||||
# Export the known plaintext tokens that correspond to the hashes in sos_config_docker.json
|
||||
export TEST_TOKEN1="t570H7DmK2VBfCwUmtFaUXyzVklL90E1"
|
||||
export TEST_TOKEN2="U3x9V39Y7rjXdRK0oxZsCz5lD6jFFDtm"
|
||||
export TEST_TOKEN3="UhtchhGDEGXlJ37GumimFtPe0imjAvak"
|
||||
|
||||
echo "Using static test configuration with known tokens"
|
||||
|
||||
#------------------------------------------------------------------------------------------------
|
||||
# run the docker container
|
||||
title "Running docker container"
|
||||
export LOCALCONFIG="${SCRIPT_DIR}/sos_config.json"
|
||||
export COMPOSE_FILE="${SCRIPT_DIR}/compose.yaml"
|
||||
|
||||
[ -f "${LOCALCONFIG}" ] || die "Config file not found: ${LOCALCONFIG}"
|
||||
[ -f "${COMPOSE_FILE}" ] || die "Compose file not found: ${COMPOSE_FILE}"
|
||||
@@ -69,12 +103,17 @@ title "Running tests"
|
||||
PREV_DIR=$(pwd)
|
||||
cd "${SCRIPT_DIR}"
|
||||
|
||||
docker stop sos-test || true
|
||||
docker rm -v sos-test || true
|
||||
# Clean up any existing containers before starting
|
||||
docker stop sos-test 2>/dev/null || true
|
||||
docker rm -v sos-test 2>/dev/null || true
|
||||
|
||||
# Start the container and mark that cleanup is needed
|
||||
LOCALCONFIG=${LOCALCONFIG} docker compose \
|
||||
-f "${COMPOSE_FILE}" up -d
|
||||
|
||||
# Mark that we need cleanup from this point on
|
||||
CLEANUP_NEEDED=true
|
||||
|
||||
# wait until healthy.
|
||||
if ! wait_for_container "sos-test"; then
|
||||
echo "----------------------------------------"
|
||||
@@ -86,17 +125,16 @@ fi
|
||||
|
||||
# run the tests. Docker inside docker support!
|
||||
docker exec -i sos-test ls /testing || true
|
||||
docker exec -i sos-test /bin/bash -c "cd /testing && ./test.sh http://127.0.0.1:7703"
|
||||
# Pass the plaintext tokens as environment variables to the test script
|
||||
docker exec -i \
|
||||
-e TEST_TOKEN1="${TEST_TOKEN1:-}" \
|
||||
-e TEST_TOKEN2="${TEST_TOKEN2:-}" \
|
||||
-e TEST_TOKEN3="${TEST_TOKEN3:-}" \
|
||||
sos-test /bin/bash -c "cd /testing && ./test.sh http://127.0.0.1:7703"
|
||||
RESULT=$?
|
||||
|
||||
# clean up.
|
||||
docker compose \
|
||||
-f "${COMPOSE_FILE}" down
|
||||
|
||||
docker compose \
|
||||
-f "${COMPOSE_FILE}" rm -v
|
||||
|
||||
cd "${PREV_DIR}"
|
||||
|
||||
# Cleanup will be handled by the trap
|
||||
exit $RESULT
|
||||
|
||||
|
Reference in New Issue
Block a user