mirror of
https://github.com/itzg/docker-minecraft-server.git
synced 2026-09-08 06:57:57 +00:00
refactoring a little bit some test script files (#3100)
Co-authored-by: Geoff Bourne <itzgeoff@gmail.com>
This commit is contained in:
+126
-149
@@ -34,18 +34,14 @@ function get_major_version() {
|
|||||||
function isURL() {
|
function isURL() {
|
||||||
local value=$1
|
local value=$1
|
||||||
|
|
||||||
if [[ ${value:0:8} == "https://" || ${value:0:7} == "http://" || ${value:0:6} == "ftp://" ]]; then
|
[[ $value =~ ^(https?|ftp):// ]]
|
||||||
return 0
|
|
||||||
else
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function isValidFileURL() {
|
function isValidFileURL() {
|
||||||
suffix=${1:?Missing required suffix arg}
|
suffix=${1:?Missing required suffix arg}
|
||||||
url=${2:?Missing required url arg}
|
url=${2:?Missing required url arg}
|
||||||
|
|
||||||
[[ "$url" == http*://*.${suffix} || "$url" == http*://*.${suffix}\?* ]]
|
[[ "$url" =~ ^http.*://.*\.${suffix}(\?.*)?$ ]]
|
||||||
}
|
}
|
||||||
|
|
||||||
function resolveEffectiveUrl() {
|
function resolveEffectiveUrl() {
|
||||||
@@ -85,11 +81,7 @@ function isFalse() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function isDebugging() {
|
function isDebugging() {
|
||||||
if isTrue "${DEBUG:-false}"; then
|
isTrue "${DEBUG:-false}"
|
||||||
return 0
|
|
||||||
else
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleDebugMode() {
|
function handleDebugMode() {
|
||||||
@@ -113,11 +105,9 @@ function log() {
|
|||||||
# The return status when listing options is zero if all optnames are enabled, non- zero otherwise.
|
# The return status when listing options is zero if all optnames are enabled, non- zero otherwise.
|
||||||
oldState=$(shopt -po xtrace || true)
|
oldState=$(shopt -po xtrace || true)
|
||||||
shopt -u -o xtrace
|
shopt -u -o xtrace
|
||||||
|
ts=
|
||||||
if isDebugging || isTrue "${LOG_TIMESTAMP:-false}"; then
|
if isDebugging || isTrue "${LOG_TIMESTAMP:-false}"; then
|
||||||
ts=" $(date --rfc-3339=seconds)"
|
ts=" $(date --rfc-3339=seconds)"
|
||||||
else
|
|
||||||
ts=
|
|
||||||
fi
|
fi
|
||||||
echo "[init]${ts} $*"
|
echo "[init]${ts} $*"
|
||||||
eval "$oldState"
|
eval "$oldState"
|
||||||
@@ -162,106 +152,95 @@ function normalizeMemSize() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function compare_version() {
|
function compare_version() {
|
||||||
local left_version=$1
|
local left_version=$1
|
||||||
local comparison=$2
|
local comparison=$2
|
||||||
local right_version=$3
|
local right_version=$3
|
||||||
|
|
||||||
if [[ -z "$left_version" ]]; then
|
if [[ -z "$left_version" ]]; then
|
||||||
echo "Left version is required"
|
echo "Left version is required"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ -z "$right_version" ]]; then
|
if [[ -z "$right_version" ]]; then
|
||||||
echo "Right version is required"
|
echo "Right version is required"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Handle version channels ('a', 'b', or numeric)
|
# Handle version channels ('a', 'b', or numeric)
|
||||||
if [[ $left_version == a* || $left_version == b* ]]; then
|
if [[ $left_version == a* || $left_version == b* ]]; then
|
||||||
left_version=${left_version:1}
|
left_version=${left_version:1}
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ $right_version == a* || $right_version == b* ]]; then
|
|
||||||
right_version=${right_version:1}
|
|
||||||
fi
|
|
||||||
|
|
||||||
|
if [[ $right_version == a* || $right_version == b* ]]; then
|
||||||
|
right_version=${right_version:1}
|
||||||
|
fi
|
||||||
|
|
||||||
local left_version_channel=${left_version:0:1}
|
local left_version_channel=${left_version:0:1}
|
||||||
if [[ $left_version_channel =~ [0-9] ]]; then
|
if [[ $left_version_channel =~ [0-9] ]]; then
|
||||||
left_version_channel='r'
|
left_version_channel='r'
|
||||||
fi
|
fi
|
||||||
|
|
||||||
local right_version_channel=${right_version:0:1}
|
local right_version_channel=${right_version:0:1}
|
||||||
if [[ $right_version_channel =~ [0-9] ]]; then
|
if [[ $right_version_channel =~ [0-9] ]]; then
|
||||||
right_version_channel='r'
|
right_version_channel='r'
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ $comparison == "lt" && $left_version_channel < $right_version_channel ]]; then
|
if [[ $comparison == "lt" && $left_version_channel < $right_version_channel ]]; then
|
||||||
return 0
|
return 0
|
||||||
elif [[ $comparison == "lt" && $left_version_channel > $right_version_channel ]]; then
|
elif [[ $comparison == "lt" && $left_version_channel > $right_version_channel ]]; then
|
||||||
return 1
|
return 1
|
||||||
elif [[ $comparison == "gt" && $left_version_channel > $right_version_channel ]]; then
|
elif [[ $comparison == "gt" && $left_version_channel > $right_version_channel ]]; then
|
||||||
return 0
|
return 0
|
||||||
elif [[ $comparison == "gt" && $left_version_channel < $right_version_channel ]]; then
|
elif [[ $comparison == "gt" && $left_version_channel < $right_version_channel ]]; then
|
||||||
return 1
|
return 1
|
||||||
elif [[ $comparison == "le" && $left_version_channel < $right_version_channel ]]; then
|
elif [[ $comparison == "le" && $left_version_channel < $right_version_channel ]]; then
|
||||||
return 0
|
return 0
|
||||||
elif [[ $comparison == "le" && $left_version_channel == $right_version_channel ]]; then
|
elif [[ $comparison == "le" && $left_version_channel == $right_version_channel ]]; then
|
||||||
return 0
|
return 0
|
||||||
elif [[ $comparison == "ge" && $left_version_channel > $right_version_channel ]]; then
|
elif [[ $comparison == "ge" && $left_version_channel > $right_version_channel ]]; then
|
||||||
return 0
|
return 0
|
||||||
elif [[ $comparison == "ge" && $left_version_channel == $right_version_channel ]]; then
|
elif [[ $comparison == "ge" && $left_version_channel == $right_version_channel ]]; then
|
||||||
return 0
|
return 0
|
||||||
elif [[ $comparison == "eq" && $left_version_channel == $right_version_channel ]]; then
|
elif [[ $comparison == "eq" && $left_version_channel == $right_version_channel ]]; then
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Compare the versions using sort -V
|
# Compare the versions using sort -V
|
||||||
local result
|
local result=1
|
||||||
|
|
||||||
case $comparison in
|
case $comparison in
|
||||||
"lt")
|
"lt")
|
||||||
if [[ $(echo -e "$left_version\n$right_version" | sort -V | head -n1) == "$left_version" && "$left_version" != "$right_version" ]]; then
|
if [[ $(echo -e "$left_version\n$right_version" | sort -V | head -n1) == "$left_version" && "$left_version" != "$right_version" ]]; then
|
||||||
result=0
|
result=0
|
||||||
else
|
fi
|
||||||
result=1
|
;;
|
||||||
fi
|
"le")
|
||||||
;;
|
if [[ $(echo -e "$left_version\n$right_version" | sort -V | head -n1) == "$left_version" ]]; then
|
||||||
"le")
|
result=0
|
||||||
if [[ $(echo -e "$left_version\n$right_version" | sort -V | head -n1) == "$left_version" ]]; then
|
fi
|
||||||
result=0
|
;;
|
||||||
else
|
"eq")
|
||||||
result=1
|
if [[ "$left_version" == "$right_version" ]]; then
|
||||||
fi
|
result=0
|
||||||
;;
|
fi
|
||||||
"eq")
|
;;
|
||||||
if [[ "$left_version" == "$right_version" ]]; then
|
"ge")
|
||||||
result=0
|
if [[ $(echo -e "$left_version\n$right_version" | sort -V | tail -n1) == "$left_version" ]]; then
|
||||||
else
|
result=0
|
||||||
result=1
|
fi
|
||||||
fi
|
;;
|
||||||
;;
|
"gt")
|
||||||
"ge")
|
if [[ $(echo -e "$left_version\n$right_version" | sort -V | tail -n1) == "$left_version" && "$left_version" != "$right_version" ]]; then
|
||||||
if [[ $(echo -e "$left_version\n$right_version" | sort -V | tail -n1) == "$left_version" ]]; then
|
result=0
|
||||||
result=0
|
fi
|
||||||
else
|
;;
|
||||||
result=1
|
*)
|
||||||
fi
|
echo "Unsupported comparison operator: $comparison"
|
||||||
;;
|
return 1
|
||||||
"gt")
|
;;
|
||||||
if [[ $(echo -e "$left_version\n$right_version" | sort -V | tail -n1) == "$left_version" && "$left_version" != "$right_version" ]]; then
|
esac
|
||||||
result=0
|
|
||||||
else
|
|
||||||
result=1
|
|
||||||
fi
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
echo "Unsupported comparison operator: $comparison"
|
|
||||||
return 1
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
|
|
||||||
return $result
|
return $result
|
||||||
}
|
}
|
||||||
|
|
||||||
function versionLessThan() {
|
function versionLessThan() {
|
||||||
@@ -270,14 +249,10 @@ function versionLessThan() {
|
|||||||
oldState=$(shopt -po xtrace || true)
|
oldState=$(shopt -po xtrace || true)
|
||||||
shopt -u -o xtrace
|
shopt -u -o xtrace
|
||||||
|
|
||||||
# Use if-else since strict mode might be enabled
|
eval "$oldState"
|
||||||
if compare_version "${VERSION}" "lt" "${1?}"; then
|
|
||||||
eval "$oldState"
|
# Verify strict mode because it might be enabled
|
||||||
return 0
|
compare_version "${VERSION}" "lt" "${1?}"
|
||||||
else
|
|
||||||
eval "$oldState"
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
}
|
}
|
||||||
|
|
||||||
requireVar() {
|
requireVar() {
|
||||||
@@ -302,7 +277,7 @@ requireEnum() {
|
|||||||
done
|
done
|
||||||
|
|
||||||
log "ERROR: $var must be set to one of $*"
|
log "ERROR: $var must be set to one of $*"
|
||||||
# exit 1
|
# exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
function writeEula() {
|
function writeEula() {
|
||||||
@@ -369,19 +344,19 @@ function extract() {
|
|||||||
|
|
||||||
type=$(file -b --mime-type "${src}")
|
type=$(file -b --mime-type "${src}")
|
||||||
case "${type}" in
|
case "${type}" in
|
||||||
application/zip)
|
application/zip)
|
||||||
unzip -o -q -d "${destDir}" "${src}"
|
unzip -o -q -d "${destDir}" "${src}"
|
||||||
;;
|
;;
|
||||||
application/x-tar|application/gzip|application/x-gzip|application/x-bzip2)
|
application/x-tar | application/gzip | application/x-gzip | application/x-bzip2)
|
||||||
tar -C "${destDir}" -xf "${src}"
|
tar -C "${destDir}" -xf "${src}"
|
||||||
;;
|
;;
|
||||||
application/zstd|application/x-zstd)
|
application/zstd | application/x-zstd)
|
||||||
tar -C "${destDir}" --use-compress-program=unzstd -xf "${src}"
|
tar -C "${destDir}" --use-compress-program=unzstd -xf "${src}"
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
log "ERROR: unsupported archive type: $type"
|
log "ERROR: unsupported archive type: $type"
|
||||||
return 1
|
return 1
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -395,31 +370,33 @@ function checkSum() {
|
|||||||
# Get distro
|
# Get distro
|
||||||
distro=$(getDistro)
|
distro=$(getDistro)
|
||||||
|
|
||||||
if [ "${distro}" == "debian" ] && sha1sum -c "${sum_file}" --status 2> /dev/null; then
|
case "${distro}" in
|
||||||
return 0
|
debian | ubuntu | ol)
|
||||||
elif [ "${distro}" == "ubuntu" ] && sha1sum -c "${sum_file}" --status 2> /dev/null; then
|
sha1sum -c "${sum_file}" --status 2>/dev/null && return 0
|
||||||
return 0
|
;;
|
||||||
elif [ "${distro}" == "alpine" ] && sha1sum -c "${sum_file}" -s 2> /dev/null; then
|
alpine)
|
||||||
return 0
|
sha1sum -c "${sum_file}" -s 2>/dev/null && return 0
|
||||||
elif [ "${distro}" == "ol" ] && sha1sum -c "${sum_file}" --status 2> /dev/null; then
|
;;
|
||||||
return 0
|
*)
|
||||||
else
|
|
||||||
return 1
|
return 1
|
||||||
fi
|
;;
|
||||||
|
esac
|
||||||
}
|
}
|
||||||
|
|
||||||
function usesMods() {
|
function usesMods() {
|
||||||
case "$FAMILY" in
|
case "$FAMILY" in
|
||||||
FORGE|FABRIC|HYBRID|SPONGE)
|
FORGE | FABRIC | HYBRID | SPONGE)
|
||||||
return 0
|
return 0
|
||||||
|
;;
|
||||||
esac
|
esac
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
function usesPlugins() {
|
function usesPlugins() {
|
||||||
case "$FAMILY" in
|
case "$FAMILY" in
|
||||||
SPIGOT|HYBRID)
|
SPIGOT | HYBRID)
|
||||||
return 0
|
return 0
|
||||||
|
;;
|
||||||
esac
|
esac
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
@@ -435,15 +412,15 @@ function resolveVersion() {
|
|||||||
|
|
||||||
function resolveFamily() {
|
function resolveFamily() {
|
||||||
case "$TYPE" in
|
case "$TYPE" in
|
||||||
PAPER|SPIGOT|BUKKIT|CANYON|PUFFERFISH|PURPUR)
|
PAPER | SPIGOT | BUKKIT | CANYON | PUFFERFISH | PURPUR)
|
||||||
FAMILY=SPIGOT
|
FAMILY=SPIGOT
|
||||||
;;
|
;;
|
||||||
FORGE)
|
FORGE)
|
||||||
FAMILY=FORGE
|
FAMILY=FORGE
|
||||||
;;
|
;;
|
||||||
FABRIC|QUILT)
|
FABRIC | QUILT)
|
||||||
FAMILY=FABRIC
|
FAMILY=FABRIC
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
export FAMILY
|
export FAMILY
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,22 +44,20 @@ setupOnlyMinecraftTest(){
|
|||||||
# false positive since it's used in delta calculations below
|
# false positive since it's used in delta calculations below
|
||||||
# shellcheck disable=SC2034
|
# shellcheck disable=SC2034
|
||||||
start=$(date +%s)
|
start=$(date +%s)
|
||||||
|
status=PASSED
|
||||||
|
verify=
|
||||||
if ! logs=$(docker compose run --rm -e SETUP_ONLY=true -e DEBUG="${DEBUG:-false}" mc 2>&1); then
|
if ! logs=$(docker compose run --rm -e SETUP_ONLY=true -e DEBUG="${DEBUG:-false}" mc 2>&1); then
|
||||||
outputContainerLog "$logs"
|
outputContainerLog "$logs"
|
||||||
result=1
|
result=1
|
||||||
elif [ -f verify.sh ]; then
|
elif [ -f verify.sh ]; then
|
||||||
|
verify=" verify"
|
||||||
if ! docker run --rm --entrypoint bash -v "${PWD}/data":/data -v "${PWD}/verify.sh":/verify "${IMAGE_TO_TEST}" -e /verify; then
|
if ! docker run --rm --entrypoint bash -v "${PWD}/data":/data -v "${PWD}/verify.sh":/verify "${IMAGE_TO_TEST}" -e /verify; then
|
||||||
endTime=$(date +%s)
|
status=FAILED
|
||||||
echo "${folder} FAILED verify in $(delta start)"
|
|
||||||
outputContainerLog "$logs"
|
outputContainerLog "$logs"
|
||||||
result=1
|
result=1
|
||||||
else
|
|
||||||
endTime=$(date +%s)
|
|
||||||
echo "${folder} PASSED verify in $(delta start)"
|
|
||||||
fi
|
fi
|
||||||
else
|
|
||||||
echo "${folder} PASSED in $(delta start)"
|
|
||||||
fi
|
fi
|
||||||
|
echo "${folder} ${status}${verify} in $(delta start)"
|
||||||
|
|
||||||
docker compose down -v --remove-orphans >& /dev/null
|
docker compose down -v --remove-orphans >& /dev/null
|
||||||
cd ..
|
cd ..
|
||||||
@@ -67,16 +65,17 @@ setupOnlyMinecraftTest(){
|
|||||||
return $result
|
return $result
|
||||||
}
|
}
|
||||||
|
|
||||||
# go through each folder in setuponly and test setups
|
foldersList=("$@")
|
||||||
if (( $# > 0 )); then
|
image=""
|
||||||
for folder in "$@"; do
|
|
||||||
echo "Starting Tests in ${folder}"
|
# Go through each folder in setuponly and test setups
|
||||||
setupOnlyMinecraftTest "$folder"
|
if (( $# == 0 )); then
|
||||||
done
|
|
||||||
else
|
|
||||||
readarray -t folders < <(find . -maxdepth 2 -mindepth 2 -name docker-compose.yml -printf '%h\n')
|
readarray -t folders < <(find . -maxdepth 2 -mindepth 2 -name docker-compose.yml -printf '%h\n')
|
||||||
for folder in "${folders[@]}"; do
|
foldersList=("${folders[@]}")
|
||||||
echo "Starting Tests in ${folder} using $IMAGE_TO_TEST"
|
image=" using $IMAGE_TO_TEST"
|
||||||
setupOnlyMinecraftTest "$folder"
|
|
||||||
done
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
for folder in "${foldersList[@]}"; do
|
||||||
|
echo "Starting Tests in ${folder}${image}"
|
||||||
|
setupOnlyMinecraftTest "$folder"
|
||||||
|
done
|
||||||
Reference in New Issue
Block a user