1GB test updated.

This commit is contained in:
Your Name
2025-05-25 11:37:43 +12:00
parent 52dcaada2d
commit ed9725208d
2 changed files with 72 additions and 26 deletions

View File

@@ -1,9 +1,13 @@
#!/bin/bash
# Create a temporary test file (100MB)
# Create a temporary test file (1024MB!)
echo "Creating test file..."
dd if=/dev/urandom of=test_file.bin bs=1M count=1024
# Calculate original file hash
echo "Calculating original file hash..."
ORIGINAL_HASH=$(sha256sum test_file.bin | cut -d' ' -f1)
echo "Original hash: $ORIGINAL_HASH"
# read ~/.config/simple_object_storage/config.json
CONFIG_PATH="${HOME}/.config/simple_object_storage/config.json"
@@ -20,14 +24,13 @@ PORT=$(echo $CONFIG | jq -r '.port')
# extract the first write token from the config
WRITE_TOKEN=$(echo $CONFIG | jq -r '.write_tokens[0]')
# Get a write token (assuming a write token 'test_token' is configured)
TOKEN=${WRITE_TOKEN}
# Upload the file
echo "Uploading file..."
RESPONSE=$(curl -X PUT -T test_file.bin "http://${HOST}:${PORT}/upload?token=${TOKEN}&labeltag=test:latest&filename=test_file.bin")
RESPONSE=$(curl -X PUT \
-H "Authorization: Bearer ${WRITE_TOKEN}" \
-F "file=@test_file.bin" \
-F 'metadata={"labeltag":"test:latest","description":"Test file","tags":["test","large"]}' \
"http://${HOST}:${PORT}/upload")
echo "Upload response: $RESPONSE"
# Extract the hash from the response
@@ -44,13 +47,38 @@ echo "Checking if file exists by label:tag..."
EXISTS_TAG=$(curl "http://${HOST}:${PORT}/exists/test:latest")
echo "Exists by label:tag response: $EXISTS_TAG"
# Download the file by hash
echo "Downloading file by hash..."
curl -o downloaded_by_hash.bin "http://${HOST}:${PORT}/object/$HASH"
# Download the file by label:tag
echo "Downloading file by label:tag..."
curl -o downloaded_by_tag.bin "http://${HOST}:${PORT}/object/test:latest"
# Verify downloaded files
echo "Verifying downloaded files..."
HASH_BY_HASH=$(sha256sum downloaded_by_hash.bin | cut -d' ' -f1)
HASH_BY_TAG=$(sha256sum downloaded_by_tag.bin | cut -d' ' -f1)
echo "Original hash: $ORIGINAL_HASH"
echo "Hash of file downloaded by hash: $HASH_BY_HASH"
echo "Hash of file downloaded by tag: $HASH_BY_TAG"
if [ "$ORIGINAL_HASH" = "$HASH_BY_HASH" ] && [ "$ORIGINAL_HASH" = "$HASH_BY_TAG" ]; then
echo "Hash verification successful!"
else
echo "Hash verification failed!"
exit 1
fi
# delete the file!
echo "Deleting file..."
DELETE_RESPONSE=$(curl "http://${HOST}:${PORT}/deleteobject?token=${TOKEN}&hash=${HASH}")
DELETE_RESPONSE=$(curl -H "Authorization: Bearer ${WRITE_TOKEN}" \
"http://${HOST}:${PORT}/deleteobject?hash=${HASH}")
echo "Delete response: $DELETE_RESPONSE"
# Clean up
echo "Cleaning up..."
rm test_file.bin
rm test_file.bin downloaded_by_hash.bin downloaded_by_tag.bin
echo "Test completed."