This commit is contained in:
Your Name
2025-05-25 11:43:16 +12:00
parent ed9725208d
commit 8997440b20

112
test.sh
View File

@@ -122,4 +122,116 @@ if ! echo "${DELETE_RESPONSE}" | jq -r '.result' | grep -q 'error'; then
die "failed to verify ${OBJECT_HASH} is deleted"
fi
# Test 1: Verify extra metadata fields are preserved
title "Testing metadata field preservation"
# Upload with extra metadata fields
EXTRA_METADATA_JSON=$(cat <<EOF
{
"labeltag": "${BASE_TAG}:test2",
"description": "Test with extra fields",
"tags": ["test", "extra"],
"custom_field": "custom value",
"extra_field1": "value1",
"extra_field2": "value2"
}
EOF
)
echo "uploading with extra metadata fields"
UPLOAD_RESPONSE=$(curl -X PUT \
-H "Authorization: Bearer ${WRITE_TOKEN}" \
-F "file=@${SCRIPT_DIR}/${SCRIPT_NAME}" \
-F "metadata=${EXTRA_METADATA_JSON}" \
"http://localhost:8123/upload")
OBJECT_HASH=$(echo ${UPLOAD_RESPONSE} | jq -r '.hash')
# Get metadata and verify extra fields are preserved
METADATA_RESPONSE=$(curl -s "${BASE_URL}/metadata/${BASE_TAG}:test2")
if ! echo "${METADATA_RESPONSE}" | jq -r '.extra_field1' | grep -q 'value1'; then
die "extra_field1 not preserved in metadata"
fi
if ! echo "${METADATA_RESPONSE}" | jq -r '.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 <<EOF
{
"labeltag": "${BASE_TAG}:latest",
"description": "First version",
"tags": ["test", "v1"]
}
EOF
)
echo "uploading first version with tag 'latest'"
UPLOAD_RESPONSE=$(curl -X PUT \
-H "Authorization: Bearer ${WRITE_TOKEN}" \
-F "file=@${SCRIPT_DIR}/${SCRIPT_NAME}" \
-F "metadata=${FIRST_METADATA_JSON}" \
"http://localhost:8123/upload")
FIRST_HASH=$(echo ${UPLOAD_RESPONSE} | jq -r '.hash')
# Upload second version with same tag 'latest'
SECOND_METADATA_JSON=$(cat <<EOF
{
"labeltag": "${BASE_TAG}:latest",
"description": "Second version",
"tags": ["test", "v2"]
}
EOF
)
echo "uploading second version with tag 'latest'"
UPLOAD_RESPONSE=$(curl -X PUT \
-H "Authorization: Bearer ${WRITE_TOKEN}" \
-F "file=@${SCRIPT_DIR}/${SCRIPT_NAME}" \
-F "metadata=${SECOND_METADATA_JSON}" \
"http://localhost:8123/upload")
SECOND_HASH=$(echo ${UPLOAD_RESPONSE} | jq -r '.hash')
# Verify first version's metadata still has v1 tag
FIRST_METADATA=$(curl -s "${BASE_URL}/metadata/${FIRST_HASH}")
if ! echo "${FIRST_METADATA}" | jq -r '.tags[]' | grep -q 'v1'; then
die "First version does not have v1 tag"
fi
# Verify first version's metadata no longer has the latest or test tags.
FIRST_METADATA=$(curl -s "${BASE_URL}/metadata/${FIRST_HASH}")
if echo "${FIRST_METADATA}" | jq -r '.tags[]' | grep -q 'latest'; then
die "First version still has latest tag"
fi
if echo "${FIRST_METADATA}" | jq -r '.tags[]' | grep -q 'test'; then
die "First version still has test tag"
fi
# Verify second version has the correct tags: v2, latest, test!
SECOND_METADATA=$(curl -s "${BASE_URL}/metadata/${BASE_TAG}:latest")
if ! echo "${SECOND_METADATA}" | jq -r '.tags[]' | grep -q 'v2'; then
die "Second version does not have v2 tag"
fi
if ! echo "${SECOND_METADATA}" | jq -r '.tags[]' | grep -q 'latest'; then
die "Second version does not have latest tag"
fi
if ! echo "${SECOND_METADATA}" | jq -r '.tags[]' | grep -q 'test'; then
die "Second version does not have test tag"
fi
# Clean up
curl -s -H "Authorization: Bearer ${WRITE_TOKEN}" "${BASE_URL}/deleteobject?hash=${FIRST_HASH}" > /dev/null
curl -s -H "Authorization: Bearer ${WRITE_TOKEN}" "${BASE_URL}/deleteobject?hash=${SECOND_HASH}" > /dev/null
title "ALL TESTS PASSED"