Files
dockercraft/tests/test_fabric.sh
T
jeremy 5688b30892 fix: migrate PaperMC to v3 API, fix NeoForge beta fallback, add test suite
- 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
2026-08-21 12:49:27 -04:00

206 lines
7.8 KiB
Bash
Executable File

#!/usr/bin/env bash
# Tests for Fabric meta API
# Covers: Fabric loader version resolution, installer version, download URL
# Usage: ./tests/test_fabric.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}Fabric API Tests (MC ${MC_VERSION})${NC}"
echo ""
# ---------- Fabric loader meta API -----------------------------------------
test_fabric_meta_reachable() {
local body
body=$(api_get "https://meta.fabricmc.net/v2/versions/loader/${MC_VERSION}")
assert_not_empty "$body" "Fabric meta body should not be empty"
assert_json_valid "$body" "Fabric meta should be valid JSON"
}
test_fabric_meta_is_array() {
local body
body=$(api_get "https://meta.fabricmc.net/v2/versions/loader/${MC_VERSION}")
local type
type=$(echo "$body" | jq -r 'type')
assert_equals "$type" "array" "Response should be a JSON array"
}
test_fabric_meta_has_entries() {
local body
body=$(api_get "https://meta.fabricmc.net/v2/versions/loader/${MC_VERSION}")
local count
count=$(echo "$body" | jq 'length')
if [[ "$count" -gt 0 ]]; then
return 0
else
echo "ASSERT FAILED: Loader array should have entries, got ${count}"
return 1
fi
}
test_fabric_loader_entry_has_version() {
local body
body=$(api_get "https://meta.fabricmc.net/v2/versions/loader/${MC_VERSION}")
assert_json_field "$body" '.[0].loader.version' "Loader entry should have .loader.version"
}
test_fabric_loader_version_is_semver() {
local body
body=$(api_get "https://meta.fabricmc.net/v2/versions/loader/${MC_VERSION}")
local version
version=$(echo "$body" | jq -r '.[0].loader.version')
assert_matches "$version" "^[0-9]+\.[0-9]+\.[0-9]+" \
"Loader version '${version}' should be semver-like"
}
test_fabric_entry_has_required_fields() {
local body
body=$(api_get "https://meta.fabricmc.net/v2/versions/loader/${MC_VERSION}")
assert_json_field "$body" '.[0].loader.version' "Should have loader version"
assert_json_field "$body" '.[0].loader.maven' "Should have loader maven coordinate"
}
test_fabric_loader_maven_coordinate() {
local body
body=$(api_get "https://meta.fabricmc.net/v2/versions/loader/${MC_VERSION}")
local maven
maven=$(echo "$body" | jq -r '.[0].loader.maven')
assert_matches "$maven" "^net.fabricmc:fabric-loader:" \
"Maven coordinate should be net.fabricmc:fabric-loader:{version}"
}
test_fabric_loader_has_stable_flag() {
local body
body=$(api_get "https://meta.fabricmc.net/v2/versions/loader/${MC_VERSION}")
local stable
stable=$(echo "$body" | jq -r '.[0].loader.stable')
assert_matches "$stable" "^(true|false)$" "Stable flag should be true or false"
}
test_fabric_has_intermediary() {
local body
body=$(api_get "https://meta.fabricmc.net/v2/versions/loader/${MC_VERSION}")
assert_json_field "$body" '.[0].intermediary.version' "Should have intermediary version"
}
# ---------- Fabric installer metadata (Maven XML) -------------------------
test_fabric_installer_metadata_reachable() {
local body
body=$(api_get "https://maven.fabricmc.net/net/fabricmc/fabric-installer/maven-metadata.xml")
assert_not_empty "$body" "Installer metadata should not be empty"
}
test_fabric_installer_metadata_is_xml() {
local body
body=$(api_get "https://maven.fabricmc.net/net/fabricmc/fabric-installer/maven-metadata.xml")
assert_contains "$body" "<metadata>" "Should be valid XML with <metadata> root"
}
test_fabric_installer_has_latest() {
local body
body=$(api_get "https://maven.fabricmc.net/net/fabricmc/fabric-installer/maven-metadata.xml")
local latest
latest=$(echo "$body" | xmllint --xpath "/metadata/versioning/latest/text()" - 2>/dev/null)
assert_not_empty "$latest" "Installer should have a latest version"
}
test_fabric_installer_latest_is_semver() {
local body
body=$(api_get "https://maven.fabricmc.net/net/fabricmc/fabric-installer/maven-metadata.xml")
local latest
latest=$(echo "$body" | xmllint --xpath "/metadata/versioning/latest/text()" - 2>/dev/null)
assert_matches "$latest" "^[0-9]+\.[0-9]+\.[0-9]+" \
"Installer version '${latest}' should be semver-like"
}
# ---------- Fabric server jar download URL ---------------------------------
test_fabric_download_url_format() {
local body
body=$(api_get "https://meta.fabricmc.net/v2/versions/loader/${MC_VERSION}")
local loader_version
loader_version=$(echo "$body" | jq -r '.[0].loader.version')
local installer_body
installer_body=$(api_get "https://maven.fabricmc.net/net/fabricmc/fabric-installer/maven-metadata.xml")
local installer_version
installer_version=$(echo "$installer_body" | xmllint --xpath "/metadata/versioning/latest/text()" - 2>/dev/null)
local expected_url="https://meta.fabricmc.net/v2/versions/loader/${MC_VERSION}/${loader_version}/${installer_version}/server/jar"
assert_not_empty "$expected_url" "Constructed URL should not be empty"
assert_matches "$expected_url" "^https://meta.fabricmc.net/v2/versions/loader/" \
"URL should start with Fabric meta base"
}
test_fabric_download_url_reachable() {
local body
body=$(api_get "https://meta.fabricmc.net/v2/versions/loader/${MC_VERSION}")
local loader_version
loader_version=$(echo "$body" | jq -r '.[0].loader.version')
local installer_body
installer_body=$(api_get "https://maven.fabricmc.net/net/fabricmc/fabric-installer/maven-metadata.xml")
local installer_version
installer_version=$(echo "$installer_body" | xmllint --xpath "/metadata/versioning/latest/text()" - 2>/dev/null)
local url="https://meta.fabricmc.net/v2/versions/loader/${MC_VERSION}/${loader_version}/${installer_version}/server/jar"
assert_http_ok "$url" "Fabric server jar URL should return HTTP 200"
}
# ---------- Specific version spot checks -----------------------------------
test_fabric_known_1_20_4() {
local body
body=$(api_get "https://meta.fabricmc.net/v2/versions/loader/1.20.4")
local count
count=$(echo "$body" | jq 'length')
if [[ "$count" -gt 0 ]]; then
return 0
else
echo "ASSERT FAILED: Fabric should support MC 1.20.4"
return 1
fi
}
test_fabric_latest_loader_version_gte() {
# The latest loader version should be >= 0.14.0 (a known old version)
local body
body=$(api_get "https://meta.fabricmc.net/v2/versions/loader/${MC_VERSION}")
local version
version=$(echo "$body" | jq -r '.[0].loader.version')
assert_version_gte "$version" "0.14.0" "Latest loader version should be >= 0.14.0"
}
# ---------- Run all tests --------------------------------------------------
run_test "Fabric meta API is reachable and valid JSON" test_fabric_meta_reachable
run_test "Response is a JSON array" test_fabric_meta_is_array
run_test "Loader array has entries" test_fabric_meta_has_entries
run_test "Loader entry has .loader.version" test_fabric_loader_entry_has_version
run_test "Loader version is semver format" test_fabric_loader_version_is_semver
run_test "Loader entry has required fields (version, maven)" test_fabric_entry_has_required_fields
run_test "Loader maven coordinate is correct" test_fabric_loader_maven_coordinate
run_test "Loader has stable flag" test_fabric_loader_has_stable_flag
run_test "Entry has intermediary version" test_fabric_has_intermediary
run_test "Installer maven-metadata.xml is reachable" test_fabric_installer_metadata_reachable
run_test "Metadata is valid XML" test_fabric_installer_metadata_is_xml
run_test "Metadata has latest version" test_fabric_installer_has_latest
run_test "Installer latest version is semver" test_fabric_installer_latest_is_semver
run_test "Download URL format is correct" test_fabric_download_url_format
run_test "Download URL returns HTTP 200" test_fabric_download_url_reachable
run_test "Fabric supports MC 1.20.4" test_fabric_known_1_20_4
run_test "Latest loader version >= 0.14.0" test_fabric_latest_loader_version_gte
print_summary