refactored: move public-API filesystem tests to tests/

Per Phase C of the test overhaul: tests that touch the filesystem and
exercise the public API surface (scan_screenshots, scan_shaders,
scan_worlds, scan_resource_packs, log_files) move from inline mod tests
into tests/. They now consume rmcl as an external crate, mirroring how
real callers would.

AccountStore::store_save_and_reload stays inline because the helper it
needs (constructing AccountStore directly with a tempdir path) requires
reaching into a private field; exposing that just for tests would leak
implementation detail. The other accounts tests are in-memory and stay
inline regardless.

The extract_description_* tests in resource_packs stay inline since
they are pure logic on serde_json::Value (no filesystem).

image is added to dev-dependencies so integration tests can fabricate
1x1 PNG fixtures (already a regular dep of the lib).
This commit is contained in:
objz committed 2026-05-26 21:11:38 +02:00
1 parent c6fce8592a
commit cc0dde106a
10 files changed
+349 -353

No files matched your search

-61
View File
@@ -201,65 +201,4 @@ mod tests {
let val = serde_json::json!(true);
assert_eq!(extract_description(&val), "");
}
fn setup_packs_dir(tmp: &std::path::Path, instance: &str) -> std::path::PathBuf {
let dir = tmp.join(instance).join(".minecraft").join("resourcepacks");
std::fs::create_dir_all(&dir).unwrap();
dir
}
#[test]
fn scan_resource_packs_empty_dir() {
let tmp = tempfile::tempdir().unwrap();
setup_packs_dir(tmp.path(), "inst");
let packs = scan_resource_packs(tmp.path(), "inst");
assert!(packs.is_empty());
}
#[test]
fn scan_resource_packs_missing_dir_returns_empty() {
let tmp = tempfile::tempdir().unwrap();
let packs = scan_resource_packs(tmp.path(), "ghost");
assert!(packs.is_empty());
}
#[test]
fn scan_resource_packs_finds_zips_and_dirs() {
let tmp = tempfile::tempdir().unwrap();
let dir = setup_packs_dir(tmp.path(), "inst");
std::fs::write(dir.join("pack-a.zip"), b"PK\x03\x04").unwrap();
std::fs::create_dir(dir.join("pack-b")).unwrap();
let packs = scan_resource_packs(tmp.path(), "inst");
assert_eq!(packs.len(), 2);
}
#[test]
fn scan_resource_packs_disabled_variants() {
let tmp = tempfile::tempdir().unwrap();
let dir = setup_packs_dir(tmp.path(), "inst");
std::fs::write(dir.join("on.zip"), b"PK\x03\x04").unwrap();
std::fs::write(dir.join("off.zip.disabled"), b"PK\x03\x04").unwrap();
std::fs::create_dir(dir.join("diron")).unwrap();
std::fs::create_dir(dir.join("diroff.disabled")).unwrap();
let packs = scan_resource_packs(tmp.path(), "inst");
assert_eq!(packs.len(), 4);
let on_zip = packs.iter().find(|p| p.file_stem == "on").unwrap();
let off_zip = packs.iter().find(|p| p.file_stem == "off").unwrap();
let on_dir = packs.iter().find(|p| p.file_stem == "diron").unwrap();
let off_dir = packs.iter().find(|p| p.file_stem == "diroff").unwrap();
assert!(on_zip.enabled);
assert!(!off_zip.enabled);
assert!(on_dir.enabled);
assert!(!off_dir.enabled);
}
#[test]
fn scan_resource_packs_ignores_non_pack_files() {
let tmp = tempfile::tempdir().unwrap();
let dir = setup_packs_dir(tmp.path(), "inst");
std::fs::write(dir.join("notes.txt"), "not a pack").unwrap();
std::fs::write(dir.join("valid.zip"), b"PK\x03\x04").unwrap();
let packs = scan_resource_packs(tmp.path(), "inst");
assert_eq!(packs.len(), 1);
}
}