diff --git a/.test/config.json b/.test/config.json deleted file mode 100644 index 733029f..0000000 --- a/.test/config.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "write_tokens": [ - "fizzle1", - "fizzle2", - "fizzle3" - ], - "port": 8123, - "object_store_path": "/tmp/temp-test-path", - "rate_limiting": { - "auth_rate_limit": 5, - "auth_window_seconds": 2 - } -} diff --git a/.test-docker/compose.yaml b/testing/compose.yaml similarity index 80% rename from .test-docker/compose.yaml rename to testing/compose.yaml index 57e2bfb..6a4ec7d 100644 --- a/.test-docker/compose.yaml +++ b/testing/compose.yaml @@ -3,14 +3,14 @@ services: image: gitea.jde.nz/public/simple-object-storage:test container_name: sos-test ports: - - 7703:80 + - 7703:7703 volumes: - ${LOCALCONFIG}:/data/sos_config.json:ro environment: - SOS_CONFIG=/data/sos_config.json restart: no healthcheck: - test: ["CMD", "wget", "-qO-", "http://0.0.0.0/status"] + test: ["CMD", "wget", "-qO-", "http://127.0.0.1:7703/status"] interval: 1s timeout: 1s retries: 3 diff --git a/.test-docker/config.json b/testing/config.json similarity index 87% rename from .test-docker/config.json rename to testing/config.json index 8a2730b..85e7f75 100644 --- a/.test-docker/config.json +++ b/testing/config.json @@ -7,5 +7,6 @@ "rate_limiting": { "auth_rate_limit": 5, "auth_window_seconds": 2 - } + }, + "port": 7703 } diff --git a/test-docker.sh b/testing/test-docker.sh similarity index 80% rename from test-docker.sh rename to testing/test-docker.sh index 5ef9762..16f5136 100755 --- a/test-docker.sh +++ b/testing/test-docker.sh @@ -1,7 +1,9 @@ #!/bin/bash set -euo pipefail +set -x SCRIPT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) +MAIN_DIR=$(cd "${SCRIPT_DIR}/.." && pwd) # FUNCTIONS function title() { @@ -46,34 +48,21 @@ function wait_for_container { #------------------------------------------------------------------------------------------------ # build the executable title "Building amd64 executable" -"${SCRIPT_DIR}/build.sh" amd64 +"${MAIN_DIR}/build.sh" amd64 #------------------------------------------------------------------------------------------------ # build the docker image title "Building docker image" -docker buildx build --no-cache --load -t gitea.jde.nz/public/simple-object-storage:test --platform linux/amd64 "${SCRIPT_DIR}" +docker buildx build --no-cache --load -t gitea.jde.nz/public/simple-object-storage:test --platform linux/amd64 "${MAIN_DIR}" #------------------------------------------------------------------------------------------------ # run the docker container title "Running docker container" -export LOCALCONFIG="${SCRIPT_DIR}/.test-docker/config.json" -ls -l "$LOCALCONFIG" +export LOCALCONFIG="${SCRIPT_DIR}/config.json" +export COMPOSE_FILE="${SCRIPT_DIR}/compose.yaml" -if [ ! -f "${LOCALCONFIG}" ]; then - echo "PWD = $(pwd)" - echo "SCRIPT_DIR = ${SCRIPT_DIR}" - ls -la "${SCRIPT_DIR}" - ls -la "${SCRIPT_DIR}/.test-docker" - echo "Config file not found: ${LOCALCONFIG}" - exit 1 -fi - -COMPOSE_FILE="${SCRIPT_DIR}/.test-docker/compose.yaml" - -if [ ! -f "${COMPOSE_FILE}" ]; then - echo "Compose file not found: ${COMPOSE_FILE}" - exit 1 -fi +[ -f "${LOCALCONFIG}" ] || die "Config file not found: ${LOCALCONFIG}" +[ -f "${COMPOSE_FILE}" ] || die "Compose file not found: ${COMPOSE_FILE}" #------------------------------------------------------------------------------------------------ title "Running tests" @@ -82,11 +71,7 @@ title "Running tests" docker compose -f "${COMPOSE_FILE}" down docker compose -f "${COMPOSE_FILE}" rm -v -# run the container. -docker compose -f "${COMPOSE_FILE}" up -d - -# wait a bit. -sleep 1 +LOCALCONFIG=${LOCALCONFIG} docker compose -f "${COMPOSE_FILE}" up -d # wait until healthy. if ! wait_for_container "sos-test"; then diff --git a/test.sh b/testing/test.sh similarity index 88% rename from test.sh rename to testing/test.sh index 3d1bf8e..aed6ea7 100755 --- a/test.sh +++ b/testing/test.sh @@ -3,7 +3,7 @@ set -euo pipefail -HOSTURL="${1:-http://localhost:8123}" +HOSTURL="${1:-http://127.0.0.1:7703}" #------------------------------------------------------------------------------------------------ @@ -54,7 +54,7 @@ if ! command -v jq &> /dev/null; then fi # read ~/.config/simple_object_storage/config.json -CONFIG_PATH="${SCRIPT_DIR}/.test-docker/config.json" +CONFIG_PATH="${SCRIPT_DIR}/config.json" if [ ! -f "${CONFIG_PATH}" ]; then echo "config file not found at ${CONFIG_PATH}" exit 1 @@ -91,11 +91,13 @@ EOF # Test 1: Verify extra metadata fields are preserved title "1: Upload script to ${BASE_TAG}:test1" +TEST_FILE="${SCRIPT_DIR}/${SCRIPT_NAME}" + # upload this script as an object -echo "uploading ${SCRIPT_DIR}/${SCRIPT_NAME} to ${BASE_TAG}:test1" +echo "uploading ${TEST_FILE} to ${BASE_TAG}:test1" UPLOAD_RESPONSE=$(curl -X PUT \ -H "Authorization: Bearer ${WRITE_TOKEN}" \ - -F "file=@${SCRIPT_DIR}/${SCRIPT_NAME}" \ + -F "file=@${TEST_FILE}" \ -F "metadata=${METADATA_JSON}" \ "${HOSTURL}/upload") @@ -117,30 +119,31 @@ CHECK_HASH=$(curl -s "${CMD}" | jq -r '.hash') title "3: Check MD5Sum matches, for both label:tag and hash downloads" # get md5sum of this file -MD5SUM=$(md5sum "${SCRIPT_DIR}/${SCRIPT_NAME}" | awk '{print $1}') -echo "md5sum of ${SCRIPT_DIR}/${SCRIPT_NAME} is ${MD5SUM}" +MD5SUM=$(md5sum "${TEST_FILE}" | awk '{print $1}') +echo "md5sum of ${TEST_FILE} is ${MD5SUM}" # download the object -echo "downloading ${OBJECT_HASH} to ${SCRIPT_DIR}/${SCRIPT_NAME}.downloaded1" -if ! curl -s "${HOSTURL}/${OBJECT_HASH}" -o "${SCRIPT_DIR}/${SCRIPT_NAME}.downloaded1"; then - die "failed to download ${OBJECT_HASH}" +DOWNLOAD_FILE="_${TEST_FILE}.downloaded" +echo "downloading ${OBJECT_HASH} to ${DOWNLOAD_FILE}1" +if ! curl -s "${HOSTURL}/${OBJECT_HASH}" -o "${DOWNLOAD_FILE}1"; then + die "failed to download ${HOSTURL}/${OBJECT_HASH} to ${DOWNLOAD_FILE}1" fi # download the object again via the label:tag -echo "downloading ${BASE_TAG}:test1 to ${SCRIPT_DIR}/${SCRIPT_NAME}.downloaded2" -if ! curl -s "${HOSTURL}/${BASE_TAG}:test1" -o "${SCRIPT_DIR}/${SCRIPT_NAME}.downloaded2"; then +echo "downloading ${BASE_TAG}:test1 to ${DOWNLOAD_FILE}2" +if ! curl -s "${HOSTURL}/${BASE_TAG}:test1" -o "${DOWNLOAD_FILE}2"; then die "failed to download ${BASE_TAG}:test1" fi # get md5sum of the downloaded file -MD5SUM_DOWNLOADED1=$(md5sum "${SCRIPT_DIR}/${SCRIPT_NAME}.downloaded1" | awk '{print $1}') -echo "md5sum of ${SCRIPT_DIR}/${SCRIPT_NAME}.downloaded1 is ${MD5SUM_DOWNLOADED1}" +MD5SUM_DOWNLOADED1=$(md5sum "${DOWNLOAD_FILE}1" | awk '{print $1}') +echo "md5sum of ${DOWNLOAD_FILE}1 is ${MD5SUM_DOWNLOADED1}" [ "${MD5SUM}" != "${MD5SUM_DOWNLOADED1}" ] && die "md5sums do not match" -MD5SUM_DOWNLOADED2=$(md5sum "${SCRIPT_DIR}/${SCRIPT_NAME}.downloaded2" | awk '{print $1}') +MD5SUM_DOWNLOADED2=$(md5sum "${DOWNLOAD_FILE}2" | awk '{print $1}') [ "${MD5SUM}" != "${MD5SUM_DOWNLOADED2}" ] && die "md5sums do not match" -rm "${SCRIPT_DIR}/${SCRIPT_NAME}.downloaded1" -rm "${SCRIPT_DIR}/${SCRIPT_NAME}.downloaded2" +rm "${DOWNLOAD_FILE}1" +rm "${DOWNLOAD_FILE}2" #------------------------------------------------------------------------------------------------ LABELTAG="finangle-wrangler:fuzzy_test" @@ -156,10 +159,10 @@ METADATA_JSON=$(cat <