#! /bin/bash SCRIPT_DIR=$(dirname $0) SCRIPT_NAME=$(basename $0) # FUNCTIONS function title() { echo "----------------------------------------" # Center the text local text="$1" local line_length=40 local text_length=${#text} local padding=$(( (line_length - text_length) / 2 )) printf "%*s%s%*s\n" $padding "" "$text" $padding "" echo "----------------------------------------" } function die() { title "error: $1" exit 1 } # test jq is installed if ! command -v jq &> /dev/null; then echo "jq could not be found" echo "sudo apt-get install jq" exit 1 fi # read ~/.config/simple_object_storage/config.json CONFIG_PATH="${SCRIPT_DIR}/.docker/config.json" if [ ! -f "${CONFIG_PATH}" ]; then echo "config file not found at ${CONFIG_PATH}" exit 1 fi CONFIG=$(cat "${CONFIG_PATH}") HOST=localhost PORT=8123 # extract the first write token from the config WRITE_TOKEN=$(echo $CONFIG | jq -r '.write_tokens[0]') BASE_URL="http://${HOST}:${PORT}" BASE_TAG="autotest" # test if server is running if ! curl -s "${BASE_URL}/status" | jq -r '.result' | grep -q 'success'; then die "server is not running" fi echo "Simple Object Storage server is running at ${BASE_URL}" # test every action in the README.md file, leaving the system in the same state it was found # and print the output of each action # Construct metadata JSON 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') echo "Received hash: ${OBJECT_HASH}" # Verify the object exists echo "Verifying object exists..." EXISTS_RESPONSE=$(curl -s "${BASE_URL}/exists/${BASE_TAG}:test2") echo "Exists response: ${EXISTS_RESPONSE}" # Get metadata and verify extra fields are preserved echo "Retrieving metadata for ${BASE_TAG}:test2" METADATA_RESPONSE=$(curl -s "${BASE_URL}/meta/${BASE_TAG}:test2") CURL_EXIT_CODE=$? echo "Curl exit code: ${CURL_EXIT_CODE}" echo "Full metadata response: ${METADATA_RESPONSE}" if [ ${CURL_EXIT_CODE} -ne 0 ]; then die "Failed to retrieve metadata: curl returned ${CURL_EXIT_CODE}" fi if ! echo "${METADATA_RESPONSE}" | jq -e . >/dev/null 2>&1; then die "Invalid JSON response: ${METADATA_RESPONSE}" fi if ! echo "${METADATA_RESPONSE}" | jq -r '.metadata.extra_field1' | grep -q 'value1'; then die "extra_field1 not preserved in metadata" fi if ! echo "${METADATA_RESPONSE}" | jq -r '.metadata.extra_field2' | grep -q 'value2'; then die "extra_field2 not preserved in metadata" fi # 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 title "ALL TESTS PASSED"