From 6b1434ebee93e8a0f84dc3e72f40d392f6bb7365 Mon Sep 17 00:00:00 2001 From: Cylae <13425054+Cylae@users.noreply.github.com> Date: Wed, 9 Sep 2026 00:51:00 +0000 Subject: [PATCH] test: add unit test for root privilege check functions Added unit tests in `server_manager/src/core/system.rs` for `is_root` and `check_root` to verify root privilege checking behavior and error messaging. --- server_manager/src/core/system.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/server_manager/src/core/system.rs b/server_manager/src/core/system.rs index d3ef19f..dfc6488 100644 --- a/server_manager/src/core/system.rs +++ b/server_manager/src/core/system.rs @@ -309,3 +309,25 @@ net.core.wmem_max=1048576 Ok(()) } + +#[cfg(test)] +#[allow(clippy::unwrap_used, clippy::expect_used, clippy::panic)] +mod tests { + use super::*; + + #[test] + fn test_is_root_and_check_root() { + let expected_root = nix::unistd::Uid::effective().is_root(); + assert_eq!(is_root(), expected_root); + + let result = check_root(); + if expected_root { + assert!(result.is_ok()); + } else { + assert!(result.is_err()); + if let Err(e) = result { + assert_eq!(e.to_string(), "This application must be run as root."); + } + } + } +}