test: tighten weak assertions and isolate global state
Assert the full InstanceConfig on JSON roundtrip (adds PartialEq to the derive), verify kill signal delivery, check defaults in the missing-config test, and take TEST_LOCK plus clear progress state in the mrpack unsafe-path test like its siblings.
This commit is contained in:
1 parent
7a6145342d
commit
e99e307790
5 files changed
+30
-8
No files matched your search
@@ -1,3 +1,6 @@
|
|||||||
|
// SPDX-FileCopyrightText: 2026 Constantin Bauer
|
||||||
|
// SPDX-License-Identifier: GPL-3.0-only
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@@ -30,7 +33,9 @@ fn load_config_from_empty_file() {
|
|||||||
fn load_config_missing_file_uses_defaults() {
|
fn load_config_missing_file_uses_defaults() {
|
||||||
let tmp = tempfile::tempdir().unwrap();
|
let tmp = tempfile::tempdir().unwrap();
|
||||||
let path = tmp.path().join("nonexistent.toml");
|
let path = tmp.path().join("nonexistent.toml");
|
||||||
load_config(&path).unwrap();
|
let config = load_config(&path).unwrap();
|
||||||
|
assert_eq!(config.defaults.memory_max, "2G");
|
||||||
|
assert_eq!(config.defaults.memory_min, "512M");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|||||||
@@ -1,3 +1,6 @@
|
|||||||
|
// SPDX-FileCopyrightText: 2026 Constantin Bauer
|
||||||
|
// SPDX-License-Identifier: GPL-3.0-only
|
||||||
|
|
||||||
// core data types for an instance: what loader it uses, what version, memory
|
// core data types for an instance: what loader it uses, what version, memory
|
||||||
// settings, etc. this is what gets persisted to instance.json
|
// settings, etc. this is what gets persisted to instance.json
|
||||||
|
|
||||||
@@ -28,7 +31,7 @@ impl fmt::Display for ModLoader {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||||
pub struct InstanceConfig {
|
pub struct InstanceConfig {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub game_version: String,
|
pub game_version: String,
|
||||||
|
|||||||
@@ -1,3 +1,6 @@
|
|||||||
|
// SPDX-FileCopyrightText: 2026 Constantin Bauer
|
||||||
|
// SPDX-License-Identifier: GPL-3.0-only
|
||||||
|
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
@@ -219,6 +222,11 @@ fn mod_file_without_a_download_url_fails_without_creating_a_file() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn mod_file_rejects_paths_outside_the_instance() {
|
fn mod_file_rejects_paths_outside_the_instance() {
|
||||||
|
// download_mod_files writes global progress state before validating
|
||||||
|
// paths, so isolate like the sibling tests do.
|
||||||
|
let _guard = crate::tests::TEST_LOCK
|
||||||
|
.lock()
|
||||||
|
.unwrap_or_else(|error| error.into_inner());
|
||||||
let runtime = tokio::runtime::Builder::new_current_thread()
|
let runtime = tokio::runtime::Builder::new_current_thread()
|
||||||
.enable_all()
|
.enable_all()
|
||||||
.build()
|
.build()
|
||||||
@@ -243,6 +251,7 @@ fn mod_file_rejects_paths_outside_the_instance() {
|
|||||||
|
|
||||||
assert!(error.to_string().contains("Unsafe .mrpack file path"));
|
assert!(error.to_string().contains("Unsafe .mrpack file path"));
|
||||||
assert!(!tmp.path().parent().unwrap().join("escape.jar").exists());
|
assert!(!tmp.path().parent().unwrap().join("escape.jar").exists());
|
||||||
|
crate::feedback::progress::clear();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,6 @@
|
|||||||
|
// SPDX-FileCopyrightText: 2026 Constantin Bauer
|
||||||
|
// SPDX-License-Identifier: GPL-3.0-only
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@@ -23,11 +26,9 @@ fn instance_config_roundtrips_through_json() {
|
|||||||
};
|
};
|
||||||
let json = serde_json::to_string_pretty(&config).expect("serialize");
|
let json = serde_json::to_string_pretty(&config).expect("serialize");
|
||||||
let parsed: InstanceConfig = serde_json::from_str(&json).expect("deserialize");
|
let parsed: InstanceConfig = serde_json::from_str(&json).expect("deserialize");
|
||||||
assert_eq!(parsed.name, config.name);
|
// full-struct comparison: a serde skip/rename regression on any field
|
||||||
assert_eq!(parsed.game_version, config.game_version);
|
// (loader_version, created, memory, jvm_args, ...) must fail this test.
|
||||||
assert_eq!(parsed.loader, config.loader);
|
assert_eq!(parsed, config);
|
||||||
assert_eq!(parsed.resolution, config.resolution);
|
|
||||||
assert_eq!(parsed.modpack_source, config.modpack_source);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|||||||
@@ -1,3 +1,6 @@
|
|||||||
|
// SPDX-FileCopyrightText: 2026 Constantin Bauer
|
||||||
|
// SPDX-License-Identifier: GPL-3.0-only
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@@ -63,7 +66,8 @@ fn register_and_send_kill() {
|
|||||||
let (tx, mut rx) = tokio::sync::oneshot::channel::<()>();
|
let (tx, mut rx) = tokio::sync::oneshot::channel::<()>();
|
||||||
register_kill("run_test_kill", tx);
|
register_kill("run_test_kill", tx);
|
||||||
assert!(send_kill("run_test_kill"));
|
assert!(send_kill("run_test_kill"));
|
||||||
let _ = rx.try_recv();
|
// the kill signal itself must arrive, not just report success
|
||||||
|
assert!(rx.try_recv().is_ok());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|||||||
Reference in new issue
Block a user