test: guard joinir strict env usage

This commit is contained in:
2025-12-30 07:42:52 +09:00
parent bb84612ac4
commit c87bdad59d
4 changed files with 89 additions and 55 deletions

View File

@ -197,6 +197,7 @@ fn candidate_paths(base: &Path) -> Vec<PathBuf> {
mod tests {
use super::*;
use crate::config::nyash_toml_v2::{NyashConfigV2, PluginPaths};
use crate::tests::helpers::joinir_env::with_joinir_env_lock;
use std::env;
struct EnvGuard {
@ -228,6 +229,15 @@ mod tests {
}
}
fn ensure_ring0_initialized() {
use crate::runtime::ring0::{default_ring0, GLOBAL_RING0};
use std::sync::Arc;
if GLOBAL_RING0.get().is_none() {
let _ = GLOBAL_RING0.set(Arc::new(default_ring0()));
}
}
fn loader_with_missing_library(path: &str) -> PluginLoaderV2 {
let mut libraries = HashMap::new();
libraries.insert(
@ -250,22 +260,31 @@ mod tests {
#[test]
fn load_all_plugins_strict_fails_on_missing_library() {
let _guard = EnvGuard::set("HAKO_JOINIR_STRICT", "1");
let loader = loader_with_missing_library("/nonexistent/libnyash_filebox_plugin");
with_joinir_env_lock(|| {
ensure_ring0_initialized();
let _guard = EnvGuard::set("HAKO_JOINIR_STRICT", "1");
let loader = loader_with_missing_library("/nonexistent/libnyash_filebox_plugin");
let result = load_all_plugins(&loader);
assert!(result.is_err(), "strict mode must fail when library is missing");
let result = load_all_plugins(&loader);
assert!(
result.is_err(),
"strict mode must fail when library is missing"
);
});
}
#[test]
fn load_all_plugins_best_effort_continues_on_missing_library() {
let _guard = EnvGuard::unset("HAKO_JOINIR_STRICT");
let loader = loader_with_missing_library("/nonexistent/libnyash_filebox_plugin");
with_joinir_env_lock(|| {
ensure_ring0_initialized();
let _guard = EnvGuard::unset("HAKO_JOINIR_STRICT");
let loader = loader_with_missing_library("/nonexistent/libnyash_filebox_plugin");
let result = load_all_plugins(&loader);
assert!(
result.is_ok(),
"non-strict mode should continue even when a library is missing"
);
let result = load_all_plugins(&loader);
assert!(
result.is_ok(),
"non-strict mode should continue even when a library is missing"
);
});
}
}