Skip to content

Commit

Permalink
Add helper scripts for testing yeet/yoink on shell
Browse files Browse the repository at this point in the history
  • Loading branch information
sunsided committed May 20, 2024
1 parent e645fb1 commit af07bb3
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
41 changes: 41 additions & 0 deletions utils/yeet.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/usr/bin/env bash

set -euo pipefail

host="localhost"
port="8080"
timestamp=$(date +%s)

response=$(curl -i -X POST "http://$host:$port/yeet?file_name=test-dynamic.json" \
-H "Content-Type: application/json" \
-d '{
"some": "field",
"ts": "'"$timestamp"'"
}')

headers=$(echo "$response" | awk '/HTTP\/1.1/,/^\r/{print}')
json=$(echo "$response" | awk '/^\{/,EOF{print}')

# Print the entire response
echo "Headers: $headers"
echo "Body: $json"
echo

# Using 'jq' command-line JSON processor for parsing JSON response
id=$(echo "$json" | jq -r '.id')
file_size=$(echo "$json" | jq -r '.file_size_bytes')
sha256=$(echo "$json" | jq -r '.hashes.sha256')
md5=$(echo "$json" | jq -r '.hashes.md5')

# Print Specific Values
echo "ID: $id"
echo "File Size: $file_size"
echo "SHA-256 Hash: $sha256"
echo "MD5 Hash: $md5"
echo

# Using 'awk' command for processing the response headers
yy_id=$(echo "$headers" | awk -F: '/yy-id/ {print $2}')

# Print header value
echo "yy-id header: $yy_id"
17 changes: 17 additions & 0 deletions utils/yoink.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env bash

set -euo pipefail

host="localhost"
port="8080"
file_id="${1:-}"

if [ -z "$file_id" ]
then
echo "Please provide file_id as an argument."
exit 1
fi

response=$(curl -i -X GET "http://$host:$port/yoink/$file_id")

echo "$response"

0 comments on commit af07bb3

Please sign in to comment.