added: tests for patches helpers, forge installer detection, url_encode, profile fetchers
Closes the seven remaining tractable coverage gaps the final review flagged. All tests-only or tiny *_from variants matching the existing pattern. 18 new tests. - src/instance/launch/patches.rs: seven inline tests for the lwjgl3ify patch helpers that were entirely untested before. strip_replaced_libs has happy + no-op cases. parse_add_opens covers the basic Add-Opens extraction, the MANIFEST.MF continuation-line case (the tricky one: jar manifests wrap lines with a trailing space + leading-space marker that gets stripped on join), missing manifest, and missing file. add_lwjgl3 verifies that only jars that actually exist in lib_dir end up on the classpath. - src/net/forge.rs: three inline tests for has_legacy_install_profile. Builds synthetic forge installer zips in a tempdir with and without the versionInfo key in install_profile.json; covers the missing-jar branch with a path that doesn't exist. - src/net/modrinth.rs: five-case rstest for url_encode covering the unreserved set, space, RFC 3986 reserved characters, multi-byte UTF-8 (the encoder operates per-byte so emoji exercises the multi-byte path), and empty input. - src/net/fabric.rs / src/net/quilt.rs: added fetch_*_profile_from and fetch_*_profile_with_raw_from variants mirroring the existing pattern. Existing fetch_*_profile and *_with_raw delegate to them with the upstream constants. - tests/net_loaders.rs: two new wiremock tests (fabric_fetch_profile parses libraries, quilt_fetch_profile parses libraries) using the new _from variants. - src/tui/widgets/popups/import_modpack/render.rs: extra snapshot for the Confirm step when loader_version is None (vanilla pack or old mmc pack). The previous Confirm snapshot covered Some(_) only. Production touches stay minimal: the four new pub fn delegators in fabric.rs and quilt.rs, all behaviour-preserving.
This commit is contained in:
1 parent
0eb47fd7b4
commit
5f43128a80
8 files changed
+351
-6
No files matched your search
+21
-2
@@ -87,10 +87,19 @@ pub async fn fetch_fabric_profile(
|
||||
client: &HttpClient,
|
||||
game_version: &str,
|
||||
loader_version: &str,
|
||||
) -> Result<FabricProfile, NetError> {
|
||||
fetch_fabric_profile_from(client, FABRIC_META_BASE, game_version, loader_version).await
|
||||
}
|
||||
|
||||
pub async fn fetch_fabric_profile_from(
|
||||
client: &HttpClient,
|
||||
meta_base: &str,
|
||||
game_version: &str,
|
||||
loader_version: &str,
|
||||
) -> Result<FabricProfile, NetError> {
|
||||
let url = format!(
|
||||
"{}/versions/loader/{}/{}/profile/json",
|
||||
FABRIC_META_BASE, game_version, loader_version
|
||||
meta_base, game_version, loader_version
|
||||
);
|
||||
client.get_json(&url).await
|
||||
}
|
||||
@@ -103,10 +112,20 @@ pub async fn fetch_fabric_profile_with_raw(
|
||||
client: &HttpClient,
|
||||
game_version: &str,
|
||||
loader_version: &str,
|
||||
) -> Result<(FabricProfile, Vec<u8>), NetError> {
|
||||
fetch_fabric_profile_with_raw_from(client, FABRIC_META_BASE, game_version, loader_version)
|
||||
.await
|
||||
}
|
||||
|
||||
pub async fn fetch_fabric_profile_with_raw_from(
|
||||
client: &HttpClient,
|
||||
meta_base: &str,
|
||||
game_version: &str,
|
||||
loader_version: &str,
|
||||
) -> Result<(FabricProfile, Vec<u8>), NetError> {
|
||||
let url = format!(
|
||||
"{}/versions/loader/{}/{}/profile/json",
|
||||
FABRIC_META_BASE, game_version, loader_version
|
||||
meta_base, game_version, loader_version
|
||||
);
|
||||
client.get_json_with_raw(&url, "Fabric profile").await
|
||||
}
|
||||
|
||||
@@ -333,4 +333,57 @@ mod tests {
|
||||
Err(e) => panic!("fetch_forge_game_versions failed: {}", e),
|
||||
}
|
||||
}
|
||||
|
||||
// builds an in-memory zip in a tempdir with the given json as
|
||||
// install_profile.json. lets the legacy-install-profile detector be
|
||||
// tested without an actual forge installer.
|
||||
fn make_installer_zip(tmp: &std::path::Path, json: &serde_json::Value) -> std::path::PathBuf {
|
||||
use std::io::Write;
|
||||
let path = tmp.join("installer.jar");
|
||||
let file = std::fs::File::create(&path).unwrap();
|
||||
let mut zip = zip::ZipWriter::new(file);
|
||||
let opts: zip::write::SimpleFileOptions = Default::default();
|
||||
zip.start_file("install_profile.json", opts).unwrap();
|
||||
zip.write_all(serde_json::to_string(json).unwrap().as_bytes())
|
||||
.unwrap();
|
||||
zip.finish().unwrap();
|
||||
path
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn has_legacy_install_profile_true_when_version_info_present() {
|
||||
let tmp = tempfile::tempdir().unwrap();
|
||||
let jar = make_installer_zip(
|
||||
tmp.path(),
|
||||
&serde_json::json!({
|
||||
"install": {},
|
||||
"versionInfo": {
|
||||
"id": "1.7.10-Forge10.13.4.1614-1.7.10",
|
||||
"mainClass": "net.minecraft.launchwrapper.Launch"
|
||||
}
|
||||
}),
|
||||
);
|
||||
assert!(has_legacy_install_profile(&jar));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn has_legacy_install_profile_false_when_version_info_absent() {
|
||||
let tmp = tempfile::tempdir().unwrap();
|
||||
let jar = make_installer_zip(
|
||||
tmp.path(),
|
||||
&serde_json::json!({
|
||||
"spec": 1,
|
||||
"minecraft": "1.20.1",
|
||||
"data": {}
|
||||
}),
|
||||
);
|
||||
assert!(!has_legacy_install_profile(&jar));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn has_legacy_install_profile_false_for_missing_jar() {
|
||||
assert!(!has_legacy_install_profile(std::path::Path::new(
|
||||
"/nonexistent/installer.jar"
|
||||
)));
|
||||
}
|
||||
}
|
||||
@@ -157,6 +157,20 @@ pub fn parse_mrpack(path: &std::path::Path) -> Result<MrpackIndex, String> {
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
// covers each branch of url_encode: unreserved bytes pass through; the
|
||||
// reserved set + spaces + non-ascii bytes get percent-encoded. emoji
|
||||
// exercises multi-byte UTF-8 since the encoder operates on bytes, not
|
||||
// chars, so each byte of the codepoint encodes separately.
|
||||
#[rstest::rstest]
|
||||
#[case::ascii_unreserved("abcXYZ0-9_.~", "abcXYZ0-9_.~")]
|
||||
#[case::space("hello world", "hello%20world")]
|
||||
#[case::reserved("/?&=#", "%2F%3F%26%3D%23")]
|
||||
#[case::utf8_emoji("\u{2603}", "%E2%98%83")]
|
||||
#[case::empty("", "")]
|
||||
fn url_encode_handles(#[case] input: &str, #[case] expected: &str) {
|
||||
assert_eq!(url_encode(input), expected);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn loader_from_fabric_deps() {
|
||||
let mut deps = HashMap::new();
|
||||
|
||||
+20
-2
@@ -83,10 +83,19 @@ pub async fn fetch_quilt_profile(
|
||||
client: &HttpClient,
|
||||
game_version: &str,
|
||||
loader_version: &str,
|
||||
) -> Result<QuiltProfile, NetError> {
|
||||
fetch_quilt_profile_from(client, QUILT_META_BASE, game_version, loader_version).await
|
||||
}
|
||||
|
||||
pub async fn fetch_quilt_profile_from(
|
||||
client: &HttpClient,
|
||||
meta_base: &str,
|
||||
game_version: &str,
|
||||
loader_version: &str,
|
||||
) -> Result<QuiltProfile, NetError> {
|
||||
let url = format!(
|
||||
"{}/versions/loader/{}/{}/profile/json",
|
||||
QUILT_META_BASE, game_version, loader_version
|
||||
meta_base, game_version, loader_version
|
||||
);
|
||||
client.get_json(&url).await
|
||||
}
|
||||
@@ -99,10 +108,19 @@ pub async fn fetch_quilt_profile_with_raw(
|
||||
client: &HttpClient,
|
||||
game_version: &str,
|
||||
loader_version: &str,
|
||||
) -> Result<(QuiltProfile, Vec<u8>), NetError> {
|
||||
fetch_quilt_profile_with_raw_from(client, QUILT_META_BASE, game_version, loader_version).await
|
||||
}
|
||||
|
||||
pub async fn fetch_quilt_profile_with_raw_from(
|
||||
client: &HttpClient,
|
||||
meta_base: &str,
|
||||
game_version: &str,
|
||||
loader_version: &str,
|
||||
) -> Result<(QuiltProfile, Vec<u8>), NetError> {
|
||||
let url = format!(
|
||||
"{}/versions/loader/{}/{}/profile/json",
|
||||
QUILT_META_BASE, game_version, loader_version
|
||||
meta_base, game_version, loader_version
|
||||
);
|
||||
client.get_json_with_raw(&url, "Quilt profile").await
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user