diff --git a/test-docker.sh b/test-docker.sh index 68a6b41..29fd1be 100755 --- a/test-docker.sh +++ b/test-docker.sh @@ -3,7 +3,7 @@ SCRIPT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) # build the executable -${SCRIPT_DIR}/build.sh amd64 +"${SCRIPT_DIR}/build.sh" amd64 # build the docker image docker buildx build --load -t gitea.jde.nz/public/simple-object-storage:test --platform linux/amd64 . @@ -22,6 +22,6 @@ fi docker run --rm \ -p 8123:80 \ --name simple-object-storage-test \ - -v ${DATADIR}:/data/storage \ - -v ${CONFIGFILE}:/data/sos_config.json:ro \ + -v "${DATADIR}":/data/storage \ + -v "${CONFIGFILE}":/data/sos_config.json:ro \ gitea.jde.nz/public/simple-object-storage:test diff --git a/test.sh b/test.sh index 9b0b923..045ade5 100755 --- a/test.sh +++ b/test.sh @@ -1,7 +1,12 @@ #! /bin/bash -SCRIPT_DIR=$(dirname $0) -SCRIPT_NAME=$(basename $0) +set -euo pipefail + + + +#------------------------------------------------------------------------------------------------ +SCRIPT_DIR=$(dirname "$0") +SCRIPT_NAME=$(basename "$0") # FUNCTIONS function title() { @@ -22,6 +27,15 @@ function die() { } +#------------------------------------------------------------------------------------------------ +cat << EOF + + +EOF +# Test 0: Verify the script is running +title "0: Verify the server is running" + + # test jq is installed if ! command -v jq &> /dev/null; then echo "jq could not be found" @@ -41,7 +55,7 @@ HOST=localhost PORT=8123 # extract the first write token from the config -WRITE_TOKEN=$(echo $CONFIG | jq -r '.write_tokens[0]') +WRITE_TOKEN=$(echo "$CONFIG" | jq -r '.write_tokens[0]') BASE_URL="http://${HOST}:${PORT}" @@ -68,6 +82,10 @@ METADATA_JSON=$(cat </dev/null 2>&1; then die "Invalid JSON response from upload: ${UPLOAD_RESPONSE}" fi -OBJECT_HASH=$(echo ${UPLOAD_RESPONSE} | jq -r '.hash') +OBJECT_HASH=$(echo "${UPLOAD_RESPONSE}" | jq -r '.hash') echo "Received hash: ${OBJECT_HASH}" # Verify the object exists @@ -188,12 +217,12 @@ if ! echo "${METADATA_RESPONSE}" | jq -r '.metadata.extra_field2' | grep -q 'val die "extra_field2 not preserved in metadata" fi +#------------------------------------------------------------------------------------------------ +title "6: Test tag versioning behavior" + # Clean up curl -s -H "Authorization: Bearer ${WRITE_TOKEN}" "${BASE_URL}/deleteobject?hash=${OBJECT_HASH}" > /dev/null -# Test 2: Verify tag versioning behavior -title "Testing tag versioning behavior" - # Upload first version with tag 'latest' FIRST_METADATA_JSON=$(cat < /dev/null curl -s -H "Authorization: Bearer ${WRITE_TOKEN}" "${BASE_URL}/deleteobject?hash=${SECOND_HASH}" > /dev/null -# Test 3: Verify rate limiting behavior -title "Testing rate limiting behavior" - # Use a known invalid token INVALID_TOKEN="invalid_token" @@ -306,4 +336,5 @@ if ! curl -s -H "Authorization: Bearer ${WRITE_TOKEN}" "${BASE_URL}/deleteobject die "failed to delete ${TODELHASH}" fi +#------------------------------------------------------------------------------------------------ title "ALL TESTS PASSED"