- Migrate Paper loader from sunset v2 API to v3 (fill.papermc.io) - Fix NeoForge: fall back to beta versions when no stable exists (set -e + grep) - Fix setEula/setperms ordering (was writing eula.txt before /data was writable) - Fix setEula/serverInfoWrite to use absolute paths (/data/server/) - Add VOLUME directive removal (was shadowing bind mounts) - Add comprehensive API test suite (110 tests across 6 suites) - Move test.sh to tests/integration.sh, switch to named volumes - Add Docker build cache to CI workflows - Add .editorconfig, expand .gitignore, improve README docs
244 lines
8.2 KiB
Bash
Executable File
244 lines
8.2 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Tests for Mojang version manifest API
|
|
# Covers: vanilla server downloads, Java version detection
|
|
# Usage: ./tests/test_mojang.sh [mc_version]
|
|
|
|
source "$(dirname "$0")/test_utils.sh"
|
|
|
|
MC_VERSION="${1:-$(get_latest_mc_version)}"
|
|
|
|
if [[ -z "$MC_VERSION" ]]; then
|
|
echo "Could not determine MC version"
|
|
exit 1
|
|
fi
|
|
|
|
echo -e "\n${BOLD}Mojang API Tests (MC ${MC_VERSION})${NC}"
|
|
echo ""
|
|
|
|
# ---------- Mojang manifest ------------------------------------------------
|
|
|
|
test_manifest_reachable() {
|
|
local body
|
|
body=$(api_get "https://launchermeta.mojang.com/mc/game/version_manifest.json")
|
|
assert_not_empty "$body" "Manifest body should not be empty"
|
|
assert_json_valid "$body" "Manifest should be valid JSON"
|
|
}
|
|
|
|
test_manifest_has_latest() {
|
|
local body
|
|
body=$(api_get "https://launchermeta.mojang.com/mc/game/version_manifest.json")
|
|
assert_json_field "$body" '.latest.release' "Manifest should have .latest.release"
|
|
assert_json_field "$body" '.latest.snapshot' "Manifest should have .latest.snapshot"
|
|
}
|
|
|
|
test_manifest_has_versions_array() {
|
|
local body
|
|
body=$(api_get "https://launchermeta.mojang.com/mc/game/version_manifest.json")
|
|
local count
|
|
count=$(echo "$body" | jq '.versions | length')
|
|
if [[ "$count" -gt 0 ]]; then
|
|
return 0
|
|
else
|
|
echo "ASSERT FAILED: versions array should have entries, got ${count}"
|
|
return 1
|
|
fi
|
|
}
|
|
|
|
test_manifest_version_entry_format() {
|
|
local body
|
|
body=$(api_get "https://launchermeta.mojang.com/mc/game/version_manifest.json")
|
|
# Each version entry should have id, type, url, time, releaseTime
|
|
local first_entry
|
|
first_entry=$(echo "$body" | jq '.versions[0]')
|
|
assert_json_field "$body" '.versions[0].id' "Version entry should have .id"
|
|
assert_json_field "$body" '.versions[0].type' "Version entry should have .type"
|
|
assert_json_field "$body" '.versions[0].url' "Version entry should have .url"
|
|
}
|
|
|
|
test_manifest_contains_mc_version() {
|
|
local body
|
|
body=$(api_get "https://launchermeta.mojang.com/mc/game/version_manifest.json")
|
|
local found
|
|
found=$(echo "$body" | jq -r ".versions[] | select(.id == \"${MC_VERSION}\") | .id")
|
|
assert_equals "$found" "$MC_VERSION" "Manifest should contain MC ${MC_VERSION}"
|
|
}
|
|
|
|
# ---------- Version data (per-version manifest) ----------------------------
|
|
|
|
get_version_url() {
|
|
local body
|
|
body=$(api_get "https://launchermeta.mojang.com/mc/game/version_manifest.json")
|
|
echo "$body" | jq -r ".versions[] | select(.id == \"${MC_VERSION}\") | .url"
|
|
}
|
|
|
|
test_version_data_reachable() {
|
|
local version_url
|
|
version_url=$(get_version_url)
|
|
assert_not_empty "$version_url" "Version URL should exist for ${MC_VERSION}"
|
|
|
|
local body
|
|
body=$(api_get "$version_url")
|
|
assert_not_empty "$body" "Version data body should not be empty"
|
|
assert_json_valid "$body" "Version data should be valid JSON"
|
|
}
|
|
|
|
test_version_data_has_downloads() {
|
|
local version_url
|
|
version_url=$(get_version_url)
|
|
local body
|
|
body=$(api_get "$version_url")
|
|
assert_json_field "$body" '.downloads.server.url' "Version data should have .downloads.server.url"
|
|
}
|
|
|
|
test_version_data_has_java_version() {
|
|
local version_url
|
|
version_url=$(get_version_url)
|
|
local body
|
|
body=$(api_get "$version_url")
|
|
assert_json_field "$body" '.javaVersion.majorVersion' "Version data should have .javaVersion.majorVersion"
|
|
}
|
|
|
|
test_version_data_has_client() {
|
|
local version_url
|
|
version_url=$(get_version_url)
|
|
local body
|
|
body=$(api_get "$version_url")
|
|
assert_json_field "$body" '.downloads.client.url' "Version data should have .downloads.client.url"
|
|
}
|
|
|
|
# ---------- Server jar URL validation --------------------------------------
|
|
|
|
test_server_jar_url_format() {
|
|
local version_url
|
|
version_url=$(get_version_url)
|
|
local body
|
|
body=$(api_get "$version_url")
|
|
local server_url
|
|
server_url=$(echo "$body" | jq -r '.downloads.server.url')
|
|
|
|
assert_matches "$server_url" "^https://(.*minecraft\\.net|piston-data\\.mojang\\.com)/" \
|
|
"Server URL should be a Mojang CDN or piston-data URL"
|
|
}
|
|
|
|
test_server_jar_url_reachable() {
|
|
local version_url
|
|
version_url=$(get_version_url)
|
|
local body
|
|
body=$(api_get "$version_url")
|
|
local server_url
|
|
server_url=$(echo "$body" | jq -r '.downloads.server.url')
|
|
|
|
assert_http_ok "$server_url" "Server jar URL should return HTTP 200"
|
|
}
|
|
|
|
# ---------- Java version detection -----------------------------------------
|
|
|
|
test_java_version_is_numeric() {
|
|
local version_url
|
|
version_url=$(get_version_url)
|
|
local body
|
|
body=$(api_get "$version_url")
|
|
local java_major
|
|
java_major=$(echo "$body" | jq -r '.javaVersion.majorVersion')
|
|
|
|
assert_matches "$java_major" "^[0-9]+$" "Java major version should be numeric"
|
|
}
|
|
|
|
test_java_version_known_values() {
|
|
local version_url
|
|
version_url=$(get_version_url)
|
|
local body
|
|
body=$(api_get "$version_url")
|
|
local java_major
|
|
java_major=$(echo "$body" | jq -r '.javaVersion.majorVersion')
|
|
|
|
case "$java_major" in
|
|
8|16|17|21) return 0 ;;
|
|
*)
|
|
echo "ASSERT FAILED: Java version ${java_major} is not a known expected value (8,16,17,21)"
|
|
echo " This may be valid for a new MC release, but verify it."
|
|
return 1
|
|
;;
|
|
esac
|
|
}
|
|
|
|
# ---------- Specific version spot checks -----------------------------------
|
|
|
|
test_known_old_version_java_8() {
|
|
# MC 1.16.5 should use Java 8
|
|
local body
|
|
body=$(api_get "https://launchermeta.mojang.com/mc/game/version_manifest.json")
|
|
local version_url
|
|
version_url=$(echo "$body" | jq -r '.versions[] | select(.id == "1.16.5") | .url')
|
|
|
|
if [[ -z "$version_url" || "$version_url" == "null" ]]; then
|
|
echo "Could not fetch 1.16.5 version data"
|
|
return 1
|
|
fi
|
|
|
|
local vdata
|
|
vdata=$(api_get "$version_url")
|
|
local java_major
|
|
java_major=$(echo "$vdata" | jq -r '.javaVersion.majorVersion')
|
|
assert_equals "$java_major" "8" "MC 1.16.5 should use Java 8"
|
|
}
|
|
|
|
test_known_new_version_java_21() {
|
|
# MC 1.20.5+ should use Java 21
|
|
local body
|
|
body=$(api_get "https://launchermeta.mojang.com/mc/game/version_manifest.json")
|
|
local version_url
|
|
version_url=$(echo "$body" | jq -r '.versions[] | select(.id == "1.21.1") | .url')
|
|
|
|
if [[ -z "$version_url" || "$version_url" == "null" ]]; then
|
|
echo "Could not fetch 1.21.1 version data"
|
|
return 1
|
|
fi
|
|
|
|
local vdata
|
|
vdata=$(api_get "$version_url")
|
|
local java_major
|
|
java_major=$(echo "$vdata" | jq -r '.javaVersion.majorVersion')
|
|
assert_equals "$java_major" "21" "MC 1.21.1 should use Java 21"
|
|
}
|
|
|
|
test_known_1_18_version_java_17() {
|
|
# MC 1.18.x should use Java 17
|
|
local body
|
|
body=$(api_get "https://launchermeta.mojang.com/mc/game/version_manifest.json")
|
|
local version_url
|
|
version_url=$(echo "$body" | jq -r '.versions[] | select(.id == "1.18.2") | .url')
|
|
|
|
if [[ -z "$version_url" || "$version_url" == "null" ]]; then
|
|
echo "Could not fetch 1.18.2 version data"
|
|
return 1
|
|
fi
|
|
|
|
local vdata
|
|
vdata=$(api_get "$version_url")
|
|
local java_major
|
|
java_major=$(echo "$vdata" | jq -r '.javaVersion.majorVersion')
|
|
assert_equals "$java_major" "17" "MC 1.18.2 should use Java 17"
|
|
}
|
|
|
|
# ---------- Run all tests --------------------------------------------------
|
|
|
|
run_test "Mojang manifest is reachable and valid JSON" test_manifest_reachable
|
|
run_test "Manifest has .latest.release and .latest.snapshot" test_manifest_has_latest
|
|
run_test "Manifest .versions array is non-empty" test_manifest_has_versions_array
|
|
run_test "Manifest version entries have required fields" test_manifest_version_entry_format
|
|
run_test "Manifest contains MC ${MC_VERSION}" test_manifest_contains_mc_version
|
|
run_test "Version data for ${MC_VERSION} is reachable" test_version_data_reachable
|
|
run_test "Version data has .downloads.server.url" test_version_data_has_downloads
|
|
run_test "Version data has .javaVersion.majorVersion" test_version_data_has_java_version
|
|
run_test "Version data has .downloads.client.url" test_version_data_has_client
|
|
run_test "Server jar URL matches Mojang CDN pattern" test_server_jar_url_format
|
|
run_test "Server jar URL returns HTTP 200" test_server_jar_url_reachable
|
|
run_test "Java version is numeric" test_java_version_is_numeric
|
|
run_test "Java version is a known value (8/16/17/21)" test_java_version_known_values
|
|
run_test "MC 1.16.5 uses Java 8" test_known_old_version_java_8
|
|
run_test "MC 1.21.1 uses Java 21" test_known_new_version_java_21
|
|
run_test "MC 1.18.2 uses Java 17" test_known_1_18_version_java_17
|
|
|
|
print_summary
|