2022-01-20 23:09:34 +00:00
|
|
|
#!/bin/bash
|
2022-01-24 04:19:25 +00:00
|
|
|
set -euo pipefail
|
|
|
|
IFS=$'\n\t'
|
2022-01-20 23:09:34 +00:00
|
|
|
|
|
|
|
# go to script root directory
|
|
|
|
cd "$(dirname "$0")" || exit 1
|
|
|
|
|
2022-02-14 00:02:09 +00:00
|
|
|
outputContainerLog() {
|
|
|
|
logs=${1?}
|
|
|
|
|
|
|
|
echo "${folder} test scenario FAILED"
|
|
|
|
echo ":::::::::::: LOGS ::::::::::::::::
|
|
|
|
$logs
|
|
|
|
::::::::::::::::::::::::::::::::::
|
|
|
|
"
|
|
|
|
}
|
|
|
|
|
2022-01-24 04:19:25 +00:00
|
|
|
# tests that only run the setup files for things like downloads and configuration.
|
2022-01-20 23:09:34 +00:00
|
|
|
setupOnlyMinecraftTest(){
|
|
|
|
folder=$1
|
|
|
|
cd "$folder"
|
2022-01-24 04:19:25 +00:00
|
|
|
result=0
|
|
|
|
|
2022-01-28 00:42:33 +00:00
|
|
|
if [ -f require.sh ]; then
|
|
|
|
# require.sh scripts can check for environment variables, etc that are required for the test.
|
|
|
|
# The script should exit with a non-zero status to indicate the test requirements are missing
|
|
|
|
# and the test should be skipped
|
|
|
|
if ! bash require.sh; then
|
|
|
|
echo "${folder} SKIP"
|
|
|
|
cd ..
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2022-01-27 02:25:52 +00:00
|
|
|
if ! logs=$(docker-compose run mc 2>&1); then
|
2022-02-14 00:02:09 +00:00
|
|
|
outputContainerLog "$logs"
|
2022-01-24 04:19:25 +00:00
|
|
|
result=1
|
|
|
|
elif [ -f verify.sh ]; then
|
2022-02-01 03:44:18 +00:00
|
|
|
if ! docker run --rm --entrypoint bash -v "${PWD}/data":/data -v "${PWD}/verify.sh":/verify "${IMAGE_TO_TEST:-itzg/minecraft-server}" -e /verify; then
|
2022-03-06 02:22:08 +00:00
|
|
|
echo "Verify ${folder} FAILED"
|
2022-02-14 00:02:09 +00:00
|
|
|
outputContainerLog "$logs"
|
2022-01-24 04:19:25 +00:00
|
|
|
result=1
|
|
|
|
else
|
2022-03-06 02:22:08 +00:00
|
|
|
echo "Verify ${folder} PASS"
|
2022-01-24 04:19:25 +00:00
|
|
|
fi
|
|
|
|
else
|
|
|
|
echo "${folder} PASS"
|
|
|
|
fi
|
|
|
|
|
2022-02-12 03:00:24 +00:00
|
|
|
docker-compose down -v --remove-orphans > /dev/null
|
2022-01-20 23:09:34 +00:00
|
|
|
cd ..
|
2022-01-24 04:19:25 +00:00
|
|
|
|
|
|
|
return $result
|
2022-01-20 23:09:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# go through each folder in setuponly and test setups
|
2022-01-24 04:19:25 +00:00
|
|
|
if (( $# > 0 )); then
|
|
|
|
for folder in "$@"; do
|
|
|
|
echo "Starting Tests in ${folder}"
|
|
|
|
setupOnlyMinecraftTest "$folder"
|
|
|
|
done
|
|
|
|
else
|
|
|
|
readarray -t folders < <(find . -maxdepth 2 -mindepth 2 -name docker-compose.yml -printf '%h\n')
|
|
|
|
for folder in "${folders[@]}"; do
|
|
|
|
echo "Starting Tests in ${folder}"
|
|
|
|
setupOnlyMinecraftTest "$folder"
|
|
|
|
done
|
|
|
|
fi
|