diff --git a/Makefile b/Makefile index a373754c8..74a31cda3 100644 --- a/Makefile +++ b/Makefile @@ -192,7 +192,7 @@ $(1): $(GEN_RS) $(GEN_TS) $(1)-lint $(1)-debug ## Lint and install $(1) (for use .PHONY: $(1)-lint $(1)-lint: fmt $(GEN_RS) $(GEN_TS) - $$(cargo) clippy $(2) -p $(1) --all-features -- -D clippy::all -D warnings + $$(cargo) clippy $(2) -p $(1) --all-features --all-targets -- -D clippy::all -D warnings .PHONY: $(1)-test $(1)-test: $(GEN_RS) $(GEN_TS) $(1)-lint auraed-debug diff --git a/auraed/src/lib.rs b/auraed/src/lib.rs index a32acd27c..4648f3cdd 100644 --- a/auraed/src/lib.rs +++ b/auraed/src/lib.rs @@ -368,8 +368,10 @@ mod tests { ); let custom_runtime_dir = PathBuf::from("/tmp/aurae-test-runtime"); - let mut runtime = AuraedRuntime::default(); - runtime.runtime_dir = custom_runtime_dir.clone(); + let runtime = AuraedRuntime { + runtime_dir: custom_runtime_dir.clone(), + ..Default::default() + }; assert_eq!( runtime.default_socket_address(), custom_runtime_dir.join("aurae.sock") diff --git a/auraed/tests/auraed_nested_should_run_cell_context.rs b/auraed/tests/auraed_nested_should_run_cell_context.rs index d7b270b09..96a5cea06 100644 --- a/auraed/tests/auraed_nested_should_run_cell_context.rs +++ b/auraed/tests/auraed_nested_should_run_cell_context.rs @@ -93,17 +93,17 @@ async fn wait_for_socket_and_connect( ) -> Channel { let deadline = tokio::time::Instant::now() + timeout; while tokio::time::Instant::now() < deadline { - if path.exists() { - if let Ok(channel) = connect_unix(path).await { - let meta = std::fs::symlink_metadata(path) - .expect("metadata for socket"); - assert!( - meta.file_type().is_socket(), - "expected {:?} to be a Unix socket", - path - ); - return channel; - } + if path.exists() + && let Ok(channel) = connect_unix(path).await + { + let meta = + std::fs::symlink_metadata(path).expect("metadata for socket"); + assert!( + meta.file_type().is_socket(), + "expected {:?} to be a Unix socket", + path + ); + return channel; } sleep(Duration::from_millis(100)).await; } diff --git a/auraed/tests/auraed_pid1_should_mount_proc_and_start.rs b/auraed/tests/auraed_pid1_should_mount_proc_and_start.rs index 750ab24f6..3fd3e2596 100644 --- a/auraed/tests/auraed_pid1_should_mount_proc_and_start.rs +++ b/auraed/tests/auraed_pid1_should_mount_proc_and_start.rs @@ -136,7 +136,7 @@ fn wait_for_tcp_listener(pid: u32, log_path: &Path, timeout: Duration) -> bool { if logs.contains("TCP Access Socket created") { return true; } - if !std::fs::metadata(format!("/proc/{pid}")).is_ok() { + if std::fs::metadata(format!("/proc/{pid}")).is_err() { panic!("auraed pid {pid} exited early. logs:\n{}", logs); } thread::sleep(Duration::from_millis(50)); @@ -150,10 +150,10 @@ fn wait_for_pid_file(dir: &Path, timeout: Duration) -> u32 { let pidfile = dir.join("runtime").join("auraed.pid"); let start = Instant::now(); while start.elapsed() < timeout { - if let Ok(contents) = std::fs::read_to_string(&pidfile) { - if let Ok(pid) = contents.trim().parse::() { - return pid; - } + if let Ok(contents) = std::fs::read_to_string(&pidfile) + && let Ok(pid) = contents.trim().parse::() + { + return pid; } thread::sleep(Duration::from_millis(50)); } @@ -167,15 +167,13 @@ fn assert_ns_pid1(pid: u32) { if status.is_empty() { panic!("status file {status_path} empty or missing"); } - if !std::fs::metadata(format!("/proc/{pid}")).is_ok() { + if std::fs::metadata(format!("/proc/{pid}")).is_err() { panic!("process {pid} not alive"); } - if let Some(ns_line) = status.lines().find(|l| l.starts_with("NSpid:")) { - if ns_line.split_whitespace().last() != Some("1") { - panic!( - "expected auraed to be pid 1 in its namespace, got {ns_line}" - ); - } + if let Some(ns_line) = status.lines().find(|l| l.starts_with("NSpid:")) + && ns_line.split_whitespace().last() != Some("1") + { + panic!("expected auraed to be pid 1 in its namespace, got {ns_line}"); } // If NSpid missing, we accept the process as long as it is alive; some kernels omit NSpid. } diff --git a/auraed/tests/auraed_spawn_client_tls.rs b/auraed/tests/auraed_spawn_client_tls.rs index 7eebb55f9..2c1d589c0 100644 --- a/auraed/tests/auraed_spawn_client_tls.rs +++ b/auraed/tests/auraed_spawn_client_tls.rs @@ -149,10 +149,10 @@ async fn wait_for_listener(addr: SocketAddr, child: &mut Child) { } fn teardown_child(child: &mut Child) { - if let Err(e) = child.kill() { - if e.kind() != std::io::ErrorKind::InvalidInput { - panic!("failed to kill auraed child: {e}"); - } + if let Err(e) = child.kill() + && e.kind() != std::io::ErrorKind::InvalidInput + { + panic!("failed to kill auraed child: {e}"); } let _ = child.wait(); } diff --git a/auraed/tests/daemon_should_bind_only_unix_socket.rs b/auraed/tests/daemon_should_bind_only_unix_socket.rs index c400f31c3..d7707eda7 100644 --- a/auraed/tests/daemon_should_bind_only_unix_socket.rs +++ b/auraed/tests/daemon_should_bind_only_unix_socket.rs @@ -31,15 +31,17 @@ use test_helpers::*; fn tcp_addrs_available_before_spawn() -> Vec { ["127.0.0.1:8080", "[::1]:8080"] .into_iter() - .filter_map(|addr| addr.parse::().ok()) - .filter_map(|addr| match TcpListener::bind(addr) { - Ok(listener) => { - drop(listener); - Some(addr) + .filter_map(|addr| { + let addr = addr.parse::().ok()?; + match TcpListener::bind(addr) { + Ok(listener) => { + drop(listener); + Some(addr) + } + Err(e) if e.kind() == io::ErrorKind::AddrInUse => None, + Err(e) if e.kind() == io::ErrorKind::AddrNotAvailable => None, + Err(e) => panic!("unexpected error probing {addr}: {e}"), } - Err(e) if e.kind() == io::ErrorKind::AddrInUse => None, - Err(e) if e.kind() == io::ErrorKind::AddrNotAvailable => None, - Err(e) => panic!("unexpected error probing {addr}: {e}"), }) .collect() } @@ -90,7 +92,7 @@ fn auraed_daemon_mode_should_bind_only_unix_socket() { // Default daemon mode should not open the documented TCP endpoint ([::1]:8080 or 127.0.0.1:8080). // Only check addresses that were free before spawning auraed to avoid false positives from other services. for addr in tcp_addrs { - let tcp_result = TcpListener::bind(addr).map(|listener| drop(listener)); + let tcp_result = TcpListener::bind(addr).map(drop); assert!( tcp_result.is_ok(), "expected no TCP listener at {addr}, but binding failed after starting auraed"