test-sim: improve integration test scripts
* integration tests have now a trap that will display where script failed, line and message * functions from uplink tests moved to utils.sh to reuse them Change-Id: Ib2311775fd70ce784aa986328969d75eefc5ac36
This commit is contained in:
parent
f6c9b8d4f1
commit
0b7c288155
@ -2,6 +2,8 @@
|
||||
set -ueo pipefail
|
||||
|
||||
SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
|
||||
source $SCRIPTDIR/utils.sh
|
||||
trap 'failure ${LINENO} "$BASH_COMMAND"' ERR
|
||||
|
||||
: "${STORJ_NETWORK_DIR?Environment variable STORJ_NETWORK_DIR needs to be set}"
|
||||
|
||||
@ -29,11 +31,6 @@ set -x
|
||||
if [[ "$1" == "upload" ]]; then
|
||||
mkdir -p "$PRISTINE_FILES_DIR" "$DOWNLOAD_FILES_DIR"
|
||||
|
||||
random_bytes_file () {
|
||||
size=$1
|
||||
output=$2
|
||||
head -c "$size" </dev/urandom > "$output"
|
||||
}
|
||||
random_bytes_file "2KiB" "$PRISTINE_FILES_DIR/small-upload-testfile" # create 2kb file of random bytes (inline)
|
||||
random_bytes_file "5MiB" "$PRISTINE_FILES_DIR/big-upload-testfile" # create 5mb file of random bytes (remote)
|
||||
random_bytes_file "12MiB" "$PRISTINE_FILES_DIR/multisegment-upload-testfile" # create 12mb file of random bytes (remote)
|
||||
@ -52,29 +49,9 @@ if [[ "$1" == "download" ]]; then
|
||||
uplink --config-dir "$GATEWAY_0_DIR" cp --progress=false "sj://$BUCKET/big-upload-testfile" "$DOWNLOAD_FILES_DIR"
|
||||
uplink --config-dir "$GATEWAY_0_DIR" cp --progress=false "sj://$BUCKET/multisegment-upload-testfile" "$DOWNLOAD_FILES_DIR"
|
||||
|
||||
if cmp "$PRISTINE_FILES_DIR/small-upload-testfile" "$DOWNLOAD_FILES_DIR/small-upload-testfile"
|
||||
then
|
||||
echo "download test: small upload testfile matches uploaded file"
|
||||
else
|
||||
echo "download test: small upload testfile does not match uploaded file"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if cmp "$PRISTINE_FILES_DIR/big-upload-testfile" "$DOWNLOAD_FILES_DIR/big-upload-testfile"
|
||||
then
|
||||
echo "download test: big upload testfile matches uploaded file"
|
||||
else
|
||||
echo "download test: big upload testfile does not match uploaded file"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if cmp "$PRISTINE_FILES_DIR/multisegment-upload-testfile" "$DOWNLOAD_FILES_DIR/multisegment-upload-testfile"
|
||||
then
|
||||
echo "download test: multisegment upload testfile matches uploaded file"
|
||||
else
|
||||
echo "download test: multisegment upload testfile does not match uploaded file"
|
||||
exit 1
|
||||
fi
|
||||
compare_files "$PRISTINE_FILES_DIR/small-upload-testfile" "$DOWNLOAD_FILES_DIR/small-upload-testfile"
|
||||
compare_files "$PRISTINE_FILES_DIR/big-upload-testfile" "$DOWNLOAD_FILES_DIR/big-upload-testfile"
|
||||
compare_files "$PRISTINE_FILES_DIR/multisegment-upload-testfile" "$DOWNLOAD_FILES_DIR/multisegment-upload-testfile"
|
||||
|
||||
rm "$DOWNLOAD_FILES_DIR/small-upload-testfile"
|
||||
rm "$DOWNLOAD_FILES_DIR/big-upload-testfile"
|
||||
|
@ -4,6 +4,8 @@ set +x
|
||||
|
||||
# constants
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"
|
||||
source $SCRIPT_DIR/utils.sh
|
||||
|
||||
readonly SCRIPT_DIR
|
||||
BUCKET="bucket-123"
|
||||
readonly BUCKET
|
||||
@ -23,22 +25,7 @@ cleanup() {
|
||||
echo "cleaned up test successfully"
|
||||
}
|
||||
trap cleanup EXIT
|
||||
|
||||
random_bytes_file() {
|
||||
size="${1}"
|
||||
output="${2}"
|
||||
head -c "${size}" </dev/urandom >"${output}"
|
||||
}
|
||||
|
||||
compare_files() {
|
||||
name=$(basename "${2}")
|
||||
if cmp "${1}" "${2}"; then
|
||||
echo "${name} matches uploaded file"
|
||||
else
|
||||
echo "${name} does not match uploaded file"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
trap 'failure ${LINENO} "$BASH_COMMAND"' ERR
|
||||
|
||||
uplink_test() {
|
||||
local temp_dir
|
||||
|
@ -1,5 +1,8 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
|
||||
source $SCRIPTDIR/utils.sh
|
||||
|
||||
TMPDIR=$(mktemp -d -t tmp.XXXXXXXXXX)
|
||||
|
||||
cleanup(){
|
||||
@ -12,21 +15,7 @@ cleanup(){
|
||||
echo "cleaned up test successfully"
|
||||
}
|
||||
trap cleanup EXIT
|
||||
|
||||
require_error_exit_code(){
|
||||
if [ $1 -eq 0 ]; then
|
||||
echo "Result of copying does not match expectations. Test FAILED"
|
||||
exit 1
|
||||
else
|
||||
echo "Copy file without permission: PASSED" # Expect unsuccessful exit code
|
||||
fi
|
||||
}
|
||||
|
||||
random_bytes_file () {
|
||||
size=$1
|
||||
output=$2
|
||||
head -c $size </dev/urandom > $output
|
||||
}
|
||||
trap 'failure ${LINENO} "$BASH_COMMAND"' ERR
|
||||
|
||||
BUCKET_WITHOUT_ACCESS=bucket1
|
||||
BUCKET_WITH_ACCESS=bucket2
|
||||
@ -72,9 +61,4 @@ fi
|
||||
|
||||
uplink cp "sj://$BUCKET_WITH_ACCESS/$FOLDER_TO_SHARE_FILE/testfile" "$DST_DIR" --access $SHARED_ACCESS
|
||||
|
||||
if cmp "$SRC_DIR/testfile" "$DST_DIR/testfile"; then
|
||||
echo "Testfile matches uploaded file: PASSED"
|
||||
else
|
||||
echo "Download test: FAILED"
|
||||
exit 1
|
||||
fi
|
||||
compare_files "$SRC_DIR/testfile" "$DST_DIR/testfile"
|
@ -1,14 +1,17 @@
|
||||
#!/usr/bin/env bash
|
||||
set -ueo pipefail
|
||||
|
||||
SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
|
||||
source $SCRIPTDIR/utils.sh
|
||||
|
||||
TMPDIR=$(mktemp -d -t tmp.XXXXXXXXXX)
|
||||
|
||||
cleanup(){
|
||||
rm -rf "$TMPDIR"
|
||||
echo "cleaned up test successfully"
|
||||
}
|
||||
|
||||
trap cleanup EXIT
|
||||
trap 'failure ${LINENO} "$BASH_COMMAND"' ERR
|
||||
|
||||
BUCKET=bucket-123
|
||||
SRC_DIR=$TMPDIR/source
|
||||
@ -17,23 +20,6 @@ UPLINK_DIR=$TMPDIR/uplink
|
||||
|
||||
mkdir -p "$SRC_DIR" "$DST_DIR"
|
||||
|
||||
random_bytes_file () {
|
||||
size=$1
|
||||
output=$2
|
||||
head -c $size </dev/urandom > $output
|
||||
}
|
||||
|
||||
compare_files () {
|
||||
name=$(basename $2)
|
||||
if cmp "$1" "$2"
|
||||
then
|
||||
echo "$name matches uploaded file"
|
||||
else
|
||||
echo "$name does not match uploaded file"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
random_bytes_file "2KiB" "$SRC_DIR/small-upload-testfile" # create 2KiB file of random bytes (inline)
|
||||
random_bytes_file "5MiB" "$SRC_DIR/big-upload-testfile" # create 5MiB file of random bytes (remote)
|
||||
# this is special case where we need to test at least one remote segment and inline segment of exact size 0
|
||||
|
@ -113,3 +113,35 @@ log_list() {
|
||||
echo ${f}
|
||||
done
|
||||
}
|
||||
|
||||
failure() {
|
||||
local lineno=$1
|
||||
local msg=$2
|
||||
echo "Failed at $lineno: $msg"
|
||||
}
|
||||
|
||||
random_bytes_file () {
|
||||
size=$1
|
||||
output=$2
|
||||
head -c $size </dev/urandom > $output
|
||||
}
|
||||
|
||||
compare_files () {
|
||||
name=$(basename $2)
|
||||
if cmp "$1" "$2"
|
||||
then
|
||||
echo "$name matches uploaded file"
|
||||
else
|
||||
echo "$name does not match uploaded file"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
require_error_exit_code(){
|
||||
if [ $1 -eq 0 ]; then
|
||||
echo "Result of copying does not match expectations. Test FAILED"
|
||||
exit 1
|
||||
else
|
||||
echo "Copy file without permission: PASSED" # Expect unsuccessful exit code
|
||||
fi
|
||||
}
|
Loading…
Reference in New Issue
Block a user