added: tests for retry envelope, manager rename, mod precedence, time buckets
Audit identified six high-priority coverage gaps. This commit closes them with 30 net new passing tests. - tests/net_retry.rs (new): 5 wiremock-based tests for the retry envelope in net/mod.rs. Covers get_json + download_file across: 5xx retry-then-succeed, 4xx fail-fast (asserted via wiremock expect(1) so any retry attempt fails the test), and exhaust at MAX_RETRIES = 3 (asserted via expect(4)). The exhaust test takes ~3.5s of wall time because the production code sleeps 500 + 1000 + 2000 ms between attempts; this is unavoidable without making the delays configurable. - tests/launch_pipeline.rs: 3 new error-path tests against build_launch_invocation. merged_profile_missing_main_class_fails surfaces the LaunchError::Parse branch when meta.json deserialises cleanly but lacks mainClass. legacy_loader_profile_missing_loader_version_errors and legacy_loader_profile_missing_installer_json_errors exercise the two Parse branches inside migrate_legacy_loader_profile_if_needed. - instance/manager.rs: 6 tests for rename (happy path, noop on same name, empty target rejected, missing source, target collision) and touch_last_played (sets the field to a stamp within 5 seconds of now). The InstanceManager rename surface had no coverage before; mutating the validation order or the std::fs::rename target would not have failed any existing test. - instance/content/mods.rs: 4 new precedence-chain tests. The reader chain is fabric > quilt > forge-toml (which itself tries neoforge.mods.toml before mods.toml) > mcmod.info. Only the fabric-over-forge precedence had a test before. Adds quilt > forge, forge_toml > mcmod_info, neoforge.mods.toml > mods.toml, and a test that a mods.toml carrying only logoFile (no [[mods]] array) still resolves the icon. - tui/widgets/instances.rs: 12 new tests for format_last_played. One case for the None input (returns "Never played"), then an rstest covering each bucket boundary in the match (0/59 just-now, 60/3599 minutes, 3600/86399 hours, 86400/2591999 days, 2592000/31535999 months, >=31536000 over-a-year). A mutation that bumps any boundary by one second, or swaps a unit suffix, fails at least one case.
This commit is contained in:
1 parent
7a9dfa850d
commit
623acd9e2c
5 files changed
+438
No files matched your search
@@ -419,4 +419,98 @@ mod tests {
|
||||
assert!(matches!(result, Err(InstanceError::NotFound(_))));
|
||||
std::fs::remove_dir_all(&tmp).ok();
|
||||
}
|
||||
|
||||
fn dummy_config(name: &str) -> InstanceConfig {
|
||||
InstanceConfig {
|
||||
name: name.to_string(),
|
||||
game_version: "1.20.1".to_string(),
|
||||
loader: ModLoader::Vanilla,
|
||||
loader_version: None,
|
||||
created: chrono::Utc::now(),
|
||||
last_played: None,
|
||||
java_path: None,
|
||||
memory_max: None,
|
||||
memory_min: None,
|
||||
jvm_args: vec![],
|
||||
resolution: None,
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rename_moves_dir_and_updates_config_name() {
|
||||
let (manager, tmp) = test_manager();
|
||||
let old_dir = tmp.join("old-name");
|
||||
std::fs::create_dir_all(&old_dir).ok();
|
||||
manager.save(&dummy_config("old-name")).expect("save");
|
||||
|
||||
manager.rename("old-name", "new-name").expect("rename");
|
||||
|
||||
assert!(!old_dir.exists(), "old dir should be gone");
|
||||
let new_dir = tmp.join("new-name");
|
||||
assert!(new_dir.exists(), "new dir should exist");
|
||||
let reloaded = manager.load_one("new-name").expect("load_one new-name");
|
||||
assert_eq!(reloaded.name, "new-name");
|
||||
std::fs::remove_dir_all(&tmp).ok();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rename_to_same_name_is_noop() {
|
||||
let (manager, tmp) = test_manager();
|
||||
let dir = tmp.join("same");
|
||||
std::fs::create_dir_all(&dir).ok();
|
||||
manager.save(&dummy_config("same")).expect("save");
|
||||
manager.rename("same", "same").expect("noop rename");
|
||||
assert!(dir.exists());
|
||||
std::fs::remove_dir_all(&tmp).ok();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rename_empty_target_rejects() {
|
||||
let (manager, tmp) = test_manager();
|
||||
std::fs::create_dir_all(tmp.join("orig")).ok();
|
||||
manager.save(&dummy_config("orig")).expect("save");
|
||||
let err = manager.rename("orig", " ").unwrap_err();
|
||||
assert!(matches!(err, InstanceError::InvalidName(_)));
|
||||
std::fs::remove_dir_all(&tmp).ok();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rename_missing_source_errors() {
|
||||
let (manager, tmp) = test_manager();
|
||||
let err = manager.rename("ghost", "anything").unwrap_err();
|
||||
assert!(matches!(err, InstanceError::NotFound(_)));
|
||||
std::fs::remove_dir_all(&tmp).ok();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rename_target_exists_errors() {
|
||||
let (manager, tmp) = test_manager();
|
||||
std::fs::create_dir_all(tmp.join("source")).ok();
|
||||
std::fs::create_dir_all(tmp.join("collision")).ok();
|
||||
manager.save(&dummy_config("source")).expect("save src");
|
||||
manager.save(&dummy_config("collision")).expect("save dst");
|
||||
let err = manager.rename("source", "collision").unwrap_err();
|
||||
assert!(matches!(err, InstanceError::AlreadyExists(_)));
|
||||
std::fs::remove_dir_all(&tmp).ok();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn touch_last_played_updates_field() {
|
||||
let (manager, tmp) = test_manager();
|
||||
std::fs::create_dir_all(tmp.join("ticker")).ok();
|
||||
manager.save(&dummy_config("ticker")).expect("save");
|
||||
// sanity: last_played starts as None
|
||||
assert!(manager.load_one("ticker").unwrap().last_played.is_none());
|
||||
|
||||
manager.touch_last_played("ticker").expect("touch");
|
||||
let reloaded = manager.load_one("ticker").unwrap();
|
||||
let stamp = reloaded.last_played.expect("last_played should be Some now");
|
||||
// and it must be recent (within 5 seconds of now)
|
||||
let age = chrono::Utc::now() - stamp;
|
||||
assert!(
|
||||
age.num_seconds().abs() < 5,
|
||||
"last_played should be roughly now, got age {age:?}"
|
||||
);
|
||||
std::fs::remove_dir_all(&tmp).ok();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user