From fc01a3c2d063d63ca0b1df86b436f3b37789d569 Mon Sep 17 00:00:00 2001 From: Reactor Scram Date: Mon, 4 Mar 2024 10:58:46 -0600 Subject: [PATCH] test(gui-client): fix missed mutations (#3753) I added unit tests for these pure or mostly-pure functions that `cargo-mutants` said were not covered. It also picked up a lot of I/O-performing functions that I ignored for now. (They're hard to test) --- rust/gui-client/src-tauri/src/client/about.rs | 14 ++++++++++++++ rust/gui-client/src-tauri/src/client/auth.rs | 8 ++++++++ .../src-tauri/src/client/deep_link/windows.rs | 11 +++++++++++ .../gui-client/src-tauri/src/client/known_dirs.rs | 15 +++++++++++++++ 4 files changed, 48 insertions(+) diff --git a/rust/gui-client/src-tauri/src/client/about.rs b/rust/gui-client/src-tauri/src/client/about.rs index e7c1cce9a..6b28cee97 100644 --- a/rust/gui-client/src-tauri/src/client/about.rs +++ b/rust/gui-client/src-tauri/src/client/about.rs @@ -10,3 +10,17 @@ pub(crate) fn get_cargo_version() -> String { pub(crate) fn get_git_version() -> String { GIT_VERSION.to_string() } + +#[cfg(test)] +mod tests { + #[test] + fn version() { + let cargo = super::get_cargo_version(); + let git = super::get_git_version(); + + assert!(cargo != "Unknown", "{}", cargo); + assert!(git != "Unknown", "{}", git); + assert!(cargo.len() >= 2, "{}", cargo); + assert!(git.len() >= 6, "{}", git); + } +} diff --git a/rust/gui-client/src-tauri/src/client/auth.rs b/rust/gui-client/src-tauri/src/client/auth.rs index b09f4e90b..c24244861 100644 --- a/rust/gui-client/src-tauri/src/client/auth.rs +++ b/rust/gui-client/src-tauri/src/client/auth.rs @@ -267,6 +267,14 @@ mod tests { SecretString::new(x.into()) } + #[test] + fn actor_name_path() { + assert!(super::actor_name_path() + .expect("`actor_name_path` should return Ok") + .components() + .any(|x| x == std::path::Component::Normal("dev.firezone.client".as_ref()))); + } + /// Runs everything in one test so that `cargo test` can't multi-thread it /// This should work around a bug we had #[test] diff --git a/rust/gui-client/src-tauri/src/client/deep_link/windows.rs b/rust/gui-client/src-tauri/src/client/deep_link/windows.rs index 8683a511a..dea37c68c 100644 --- a/rust/gui-client/src-tauri/src/client/deep_link/windows.rs +++ b/rust/gui-client/src-tauri/src/client/deep_link/windows.rs @@ -162,3 +162,14 @@ fn set_registry_values(id: &str, exe: &str) -> Result<(), io::Error> { fn named_pipe_path(id: &str) -> String { format!(r"\\.\pipe\{}", id) } + +#[cfg(test)] +mod tests { + #[test] + fn named_pipe_path() { + assert_eq!( + super::named_pipe_path("dev.firezone.client"), + r"\\.\pipe\dev.firezone.client" + ); + } +} diff --git a/rust/gui-client/src-tauri/src/client/known_dirs.rs b/rust/gui-client/src-tauri/src/client/known_dirs.rs index a3bdb054b..0ae032e07 100644 --- a/rust/gui-client/src-tauri/src/client/known_dirs.rs +++ b/rust/gui-client/src-tauri/src/client/known_dirs.rs @@ -118,3 +118,18 @@ mod imp { ) } } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn smoke() { + for dir in [device_id(), logs(), runtime(), session(), settings()] { + let dir = dir.expect("should have gotten Some(path)"); + assert!(dir + .components() + .any(|x| x == std::path::Component::Normal("dev.firezone.client".as_ref()))); + } + } +}