Update test.sh
All checks were successful
Build-Test-Publish / build (linux/amd64) (push) Successful in 18s
Build-Test-Publish / build (linux/arm64) (push) Successful in 18s

This commit is contained in:
Your Name
2025-08-24 14:28:49 +12:00
parent c8e81f84ec
commit c2e22a023e

28
test.sh
View File

@@ -360,7 +360,7 @@ function test_retrieval() {
# For hash retrieval, test the actual hash endpoint
if [[ "${identifier}" =~ ^[a-f0-9]{64}$ ]]; then
local meta_response=$(curl -s "http://localhost:${TEST_PORT}/meta/${identifier}")
local meta_response=$(curl -s "http://${test_host}/meta/${identifier}")
if echo "${meta_response}" | jq -e '.metadata' >/dev/null 2>&1; then
log_info "Successfully retrieved metadata for hash ${identifier}"
else
@@ -382,11 +382,14 @@ function test_duplicate_upload() {
export SOS_WRITE_TOKEN="${TEST_TOKEN}"
export SOS_TEST_MODE=1
# Use the determined host
local test_host="${SOS_TEST_HOST:-localhost:${TEST_PORT}}"
# Upload original
"${SCRIPT_DIR}/sos" upload "localhost:${TEST_PORT}" "${TEST_DIR}/test_files/test1.txt" "dup:original" >/dev/null 2>&1
"${SCRIPT_DIR}/sos" upload "${test_host}" "${TEST_DIR}/test_files/test1.txt" "dup:original" >/dev/null 2>&1
# Upload duplicate (should detect existing file)
local output=$("${SCRIPT_DIR}/sos" upload "localhost:${TEST_PORT}" "${TEST_DIR}/test_files/test1_dup.txt" "dup:copy" 2>&1)
local output=$("${SCRIPT_DIR}/sos" upload "${test_host}" "${TEST_DIR}/test_files/test1_dup.txt" "dup:copy" 2>&1)
if echo "${output}" | grep -q "File already exists, skipping upload"; then
log_info "Deduplication working correctly"
@@ -403,11 +406,14 @@ function test_metadata_update() {
export SOS_WRITE_TOKEN="${TEST_TOKEN}"
export SOS_TEST_MODE=1
# Use the determined host
local test_host="${SOS_TEST_HOST:-localhost:${TEST_PORT}}"
# Upload a file
"${SCRIPT_DIR}/sos" upload "localhost:${TEST_PORT}" "${TEST_DIR}/test_files/test2.txt" "meta:v1" >/dev/null 2>&1
"${SCRIPT_DIR}/sos" upload "${test_host}" "${TEST_DIR}/test_files/test2.txt" "meta:v1" >/dev/null 2>&1
# Upload same file with different metadata
local output=$("${SCRIPT_DIR}/sos" upload "localhost:${TEST_PORT}" "${TEST_DIR}/test_files/test2.txt" "meta:v2" "meta:updated" 2>&1)
local output=$("${SCRIPT_DIR}/sos" upload "${test_host}" "${TEST_DIR}/test_files/test2.txt" "meta:v2" "meta:updated" 2>&1)
if echo "${output}" | grep -q "File already exists"; then
log_info "Metadata update successful"
@@ -421,8 +427,11 @@ function test_metadata_update() {
function test_exists_endpoint() {
log_info "Testing exists endpoint..."
# Use the determined host
local test_host="${SOS_TEST_HOST:-localhost:${TEST_PORT}}"
# Get hash of an uploaded file
local hash=$(curl -s "http://localhost:${TEST_PORT}/hash/test:file1" | jq -r '.hash')
local hash=$(curl -s "http://${test_host}/hash/test:file1" | jq -r '.hash')
if [ -z "${hash}" ] || [ "${hash}" = "null" ]; then
log_error "Failed to get hash for exists test"
@@ -430,7 +439,7 @@ function test_exists_endpoint() {
fi
# Test exists endpoint
local exists=$(curl -s "http://localhost:${TEST_PORT}/exists/${hash}" | jq -r '.exists')
local exists=$(curl -s "http://${test_host}/exists/${hash}" | jq -r '.exists')
if [ "${exists}" = "true" ]; then
log_info "Exists endpoint working correctly"
@@ -450,9 +459,12 @@ function test_invalid_auth() {
export SOS_WRITE_TOKEN="invalid-token"
export SOS_TEST_MODE=1
# Use the determined host
local test_host="${SOS_TEST_HOST:-localhost:${TEST_PORT}}"
# Run upload with invalid token and capture output + exit code
set +e # Temporarily disable exit on error
"${SCRIPT_DIR}/sos" upload "localhost:${TEST_PORT}" "${TEST_DIR}/test_files/auth_test.txt" "auth:test" 2>&1 | tee "${TEST_DIR}/auth_test_output.txt"
"${SCRIPT_DIR}/sos" upload "${test_host}" "${TEST_DIR}/test_files/auth_test.txt" "auth:test" 2>&1 | tee "${TEST_DIR}/auth_test_output.txt"
local exit_code=${PIPESTATUS[0]}
set -e # Re-enable exit on error