Files
simple-object-server/test_1GB_file_upload.sh
Your Name a7ece306cd Big.
2025-05-03 15:58:38 +12:00

56 lines
1.6 KiB
Bash
Executable File

#!/bin/bash
# Create a temporary test file (100MB)
echo "Creating test file..."
dd if=/dev/urandom of=test_file.bin bs=1M count=1024
# read ~/.config/simple_object_storage/config.json
CONFIG_PATH="${HOME}/.config/simple_object_storage/config.json"
if [ ! -f "${CONFIG_PATH}" ]; then
echo "config file not found at ${CONFIG_PATH}"
exit 1
fi
CONFIG=$(cat "${CONFIG_PATH}")
# get the host and port from the config
HOST=$(echo $CONFIG | jq -r '.host')
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")
echo "Upload response: $RESPONSE"
# Extract the hash from the response
HASH=$(echo $RESPONSE | jq -r '.hash')
echo "Hash: $HASH"
# Check if the file exists by hash
echo "Checking if file exists by hash..."
EXISTS_HASH=$(curl "http://${HOST}:${PORT}/exists/$HASH")
echo "Exists by hash response: $EXISTS_HASH"
# Check if the file exists by label:tag
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"
# delete the file!
echo "Deleting file..."
DELETE_RESPONSE=$(curl "http://${HOST}:${PORT}/deleteobject?token=${TOKEN}&hash=${HASH}")
echo "Delete response: $DELETE_RESPONSE"
# Clean up
echo "Cleaning up..."
rm test_file.bin
echo "Test completed."