test(net): make retry and loader coverage deterministic

This commit is contained in:
objz committed 2026-07-27 01:10:04 +02:00
1 parent 45ce7ef84b
commit dc13746841
5 files changed
+96 -53

No files matched your search

+49 -8
View File
@@ -20,14 +20,7 @@ impl ModLoaderInstaller for VanillaInstaller {
async fn get_game_versions(&self, client: &HttpClient) -> Result<Vec<GameVersion>, NetError> {
let manifest = mojang::fetch_version_manifest(client).await?;
Ok(manifest
.versions
.into_iter()
.map(|v| GameVersion {
id: v.id,
stable: v.version_type == "release",
})
.collect())
Ok(game_versions_from_manifest(manifest))
}
async fn get_versions(
@@ -49,3 +42,51 @@ impl ModLoaderInstaller for VanillaInstaller {
Ok(())
}
}
fn game_versions_from_manifest(manifest: mojang::VersionManifest) -> Vec<GameVersion> {
manifest
.versions
.into_iter()
.map(|version| GameVersion {
id: version.id,
stable: version.version_type == "release",
})
.collect()
}
#[cfg(test)]
mod tests {
use super::*;
use crate::net::mojang::{LatestVersions, VersionEntry, VersionManifest};
#[test]
fn manifest_types_map_to_stable_game_versions() {
let manifest = VersionManifest {
latest: LatestVersions {
release: "1.21.1".to_owned(),
snapshot: "24w01a".to_owned(),
},
versions: vec![
VersionEntry {
id: "1.21.1".to_owned(),
version_type: "release".to_owned(),
url: String::new(),
sha1: String::new(),
},
VersionEntry {
id: "24w01a".to_owned(),
version_type: "snapshot".to_owned(),
url: String::new(),
sha1: String::new(),
},
],
};
let versions = game_versions_from_manifest(manifest);
assert_eq!(versions[0].id, "1.21.1");
assert!(versions[0].stable);
assert_eq!(versions[1].id, "24w01a");
assert!(!versions[1].stable);
}
}
+6
View File
@@ -39,6 +39,12 @@ impl Default for HttpClient {
}
}
impl From<Client> for HttpClient {
fn from(inner: Client) -> Self {
Self { inner }
}
}
impl NetError {
pub(crate) fn is_retryable(&self) -> bool {
matches!(self, Self::StatusError { status: 429, .. }) || is_retryable(self)