Vaguely working
This commit is contained in:
47
test.sh
47
test.sh
@@ -51,12 +51,23 @@ BASE_TAG="autotest"
|
||||
# test every action in the README.md file, leaving the system in the same state it was found
|
||||
# and print the output of each action
|
||||
|
||||
# Construct metadata JSON
|
||||
METADATA_JSON=$(cat <<EOF
|
||||
{
|
||||
"labeltag": "${BASE_TAG}:test1",
|
||||
"description": "Example file",
|
||||
"tags": ["test", "example"],
|
||||
"custom_field": "custom value"
|
||||
}
|
||||
EOF
|
||||
)
|
||||
|
||||
# upload this script as an object
|
||||
echo "uploading ${SCRIPT_DIR}/${SCRIPT_NAME} to ${BASE_TAG}:test1"
|
||||
UPLOAD_RESPONSE=$(curl -X PUT \
|
||||
-H "Authorization: Bearer ${WRITE_TOKEN}" \
|
||||
-F "file=@${SCRIPT_DIR}/${SCRIPT_NAME}" \
|
||||
-F 'metadata={"labeltag":"${BASE_TAG}:test1","description":"Example file","tags":["test","example"],"custom_field":"custom value"}' \
|
||||
-F "metadata=${METADATA_JSON}" \
|
||||
"http://localhost:8123/upload")
|
||||
|
||||
echo "upload response: ${UPLOAD_RESPONSE}"
|
||||
@@ -69,7 +80,7 @@ echo "received hash ${OBJECT_HASH}"
|
||||
|
||||
# check the hash matches.
|
||||
CHECK_HASH=$(curl -s "${BASE_URL}/hash/${BASE_TAG}:test1" | jq -r '.hash')
|
||||
[ "${OBJECT_HASH}" != "${CHECK_HASH}" ] && die "hash does not match"
|
||||
[ "${OBJECT_HASH}" != "${CHECK_HASH}" ] && die "hash does not match: ${OBJECT_HASH} != ${CHECK_HASH}"
|
||||
|
||||
# get md5sum of this file
|
||||
MD5SUM=$(md5sum ${SCRIPT_DIR}/${SCRIPT_NAME} | awk '{print $1}')
|
||||
@@ -97,40 +108,10 @@ MD5SUM_DOWNLOADED2=$(md5sum ${SCRIPT_DIR}/${SCRIPT_NAME}.downloaded2 | awk '{pri
|
||||
rm ${SCRIPT_DIR}/${SCRIPT_NAME}.downloaded1
|
||||
rm ${SCRIPT_DIR}/${SCRIPT_NAME}.downloaded2
|
||||
|
||||
# delete the object tags
|
||||
echo "deleting tag ${BASE_TAG}:test1"
|
||||
if ! curl -s "${BASE_URL}/deletetag?token=${WRITE_TOKEN}&labeltag=${BASE_TAG}:test1" | jq -r '.result' | grep -q 'success'; then
|
||||
die "failed to delete tag ${BASE_TAG}:test1"
|
||||
fi
|
||||
|
||||
# testing we CANT download via the label:tag
|
||||
echo "testing we CANT download via the label:tag"
|
||||
if curl -s "${BASE_URL}/object/${BASE_TAG}:test1" | jq -r '.result' | grep -q 'success'; then
|
||||
die "downloaded via the label:tag"
|
||||
fi
|
||||
|
||||
# testing we can still download via the hash
|
||||
echo "testing we can still download via the hash"
|
||||
if ! curl -s "${BASE_URL}/exists/${OBJECT_HASH}" | jq -r '.result' | grep -q 'success'; then
|
||||
die "failed to check exists via the hash"
|
||||
fi
|
||||
|
||||
# download the object
|
||||
echo "downloading ${OBJECT_HASH} to ${SCRIPT_DIR}/${SCRIPT_NAME}.downloaded4"
|
||||
if ! curl -s "${BASE_URL}/object/${OBJECT_HASH}" -o ${SCRIPT_DIR}/${SCRIPT_NAME}.downloaded4; then
|
||||
die "failed to download ${OBJECT_HASH}"
|
||||
fi
|
||||
|
||||
MD5SUM_DOWNLOADED4=$(md5sum ${SCRIPT_DIR}/${SCRIPT_NAME}.downloaded4 | awk '{print $1}')
|
||||
MD5SUM=$(md5sum ${SCRIPT_DIR}/${SCRIPT_NAME} | awk '{print $1}')
|
||||
[ "${MD5SUM}" != "${MD5SUM_DOWNLOADED4}" ] && die "md5sums do not match"
|
||||
|
||||
# delete the downloaded file
|
||||
rm ${SCRIPT_DIR}/${SCRIPT_NAME}.downloaded4
|
||||
|
||||
# delete the object
|
||||
echo "deleting ${OBJECT_HASH}"
|
||||
if ! curl -s "${BASE_URL}/deleteobject?token=${WRITE_TOKEN}&hash=${OBJECT_HASH}" | jq -r '.result' | grep -q 'success'; then
|
||||
if ! curl -s -H "Authorization: Bearer ${WRITE_TOKEN}" "${BASE_URL}/deleteobject?hash=${OBJECT_HASH}" | jq -r '.result' | grep -q 'success'; then
|
||||
die "failed to delete ${OBJECT_HASH}"
|
||||
fi
|
||||
|
||||
|
Reference in New Issue
Block a user