Skip to content

Commit 50b01a4

Browse files
authored
chore: Ensure lints cover tests (#596)
Adds `--all-targets` to Clippy as our lint target wasn't covering tests. Fixes all failing lints in `auraed/tests/`.
1 parent 288d93e commit 50b01a4

File tree

6 files changed

+41
-39
lines changed

6 files changed

+41
-39
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ $(1): $(GEN_RS) $(GEN_TS) $(1)-lint $(1)-debug ## Lint and install $(1) (for use
192192

193193
.PHONY: $(1)-lint
194194
$(1)-lint: fmt $(GEN_RS) $(GEN_TS)
195-
$$(cargo) clippy $(2) -p $(1) --all-features -- -D clippy::all -D warnings
195+
$$(cargo) clippy $(2) -p $(1) --all-features --all-targets -- -D clippy::all -D warnings
196196

197197
.PHONY: $(1)-test
198198
$(1)-test: $(GEN_RS) $(GEN_TS) $(1)-lint auraed-debug

auraed/src/lib.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -368,8 +368,10 @@ mod tests {
368368
);
369369

370370
let custom_runtime_dir = PathBuf::from("/tmp/aurae-test-runtime");
371-
let mut runtime = AuraedRuntime::default();
372-
runtime.runtime_dir = custom_runtime_dir.clone();
371+
let runtime = AuraedRuntime {
372+
runtime_dir: custom_runtime_dir.clone(),
373+
..Default::default()
374+
};
373375
assert_eq!(
374376
runtime.default_socket_address(),
375377
custom_runtime_dir.join("aurae.sock")

auraed/tests/auraed_nested_should_run_cell_context.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -93,17 +93,17 @@ async fn wait_for_socket_and_connect(
9393
) -> Channel {
9494
let deadline = tokio::time::Instant::now() + timeout;
9595
while tokio::time::Instant::now() < deadline {
96-
if path.exists() {
97-
if let Ok(channel) = connect_unix(path).await {
98-
let meta = std::fs::symlink_metadata(path)
99-
.expect("metadata for socket");
100-
assert!(
101-
meta.file_type().is_socket(),
102-
"expected {:?} to be a Unix socket",
103-
path
104-
);
105-
return channel;
106-
}
96+
if path.exists()
97+
&& let Ok(channel) = connect_unix(path).await
98+
{
99+
let meta =
100+
std::fs::symlink_metadata(path).expect("metadata for socket");
101+
assert!(
102+
meta.file_type().is_socket(),
103+
"expected {:?} to be a Unix socket",
104+
path
105+
);
106+
return channel;
107107
}
108108
sleep(Duration::from_millis(100)).await;
109109
}

auraed/tests/auraed_pid1_should_mount_proc_and_start.rs

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ fn wait_for_tcp_listener(pid: u32, log_path: &Path, timeout: Duration) -> bool {
136136
if logs.contains("TCP Access Socket created") {
137137
return true;
138138
}
139-
if !std::fs::metadata(format!("/proc/{pid}")).is_ok() {
139+
if std::fs::metadata(format!("/proc/{pid}")).is_err() {
140140
panic!("auraed pid {pid} exited early. logs:\n{}", logs);
141141
}
142142
thread::sleep(Duration::from_millis(50));
@@ -150,10 +150,10 @@ fn wait_for_pid_file(dir: &Path, timeout: Duration) -> u32 {
150150
let pidfile = dir.join("runtime").join("auraed.pid");
151151
let start = Instant::now();
152152
while start.elapsed() < timeout {
153-
if let Ok(contents) = std::fs::read_to_string(&pidfile) {
154-
if let Ok(pid) = contents.trim().parse::<u32>() {
155-
return pid;
156-
}
153+
if let Ok(contents) = std::fs::read_to_string(&pidfile)
154+
&& let Ok(pid) = contents.trim().parse::<u32>()
155+
{
156+
return pid;
157157
}
158158
thread::sleep(Duration::from_millis(50));
159159
}
@@ -167,15 +167,13 @@ fn assert_ns_pid1(pid: u32) {
167167
if status.is_empty() {
168168
panic!("status file {status_path} empty or missing");
169169
}
170-
if !std::fs::metadata(format!("/proc/{pid}")).is_ok() {
170+
if std::fs::metadata(format!("/proc/{pid}")).is_err() {
171171
panic!("process {pid} not alive");
172172
}
173-
if let Some(ns_line) = status.lines().find(|l| l.starts_with("NSpid:")) {
174-
if ns_line.split_whitespace().last() != Some("1") {
175-
panic!(
176-
"expected auraed to be pid 1 in its namespace, got {ns_line}"
177-
);
178-
}
173+
if let Some(ns_line) = status.lines().find(|l| l.starts_with("NSpid:"))
174+
&& ns_line.split_whitespace().last() != Some("1")
175+
{
176+
panic!("expected auraed to be pid 1 in its namespace, got {ns_line}");
179177
}
180178
// If NSpid missing, we accept the process as long as it is alive; some kernels omit NSpid.
181179
}

auraed/tests/auraed_spawn_client_tls.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,10 +149,10 @@ async fn wait_for_listener(addr: SocketAddr, child: &mut Child) {
149149
}
150150

151151
fn teardown_child(child: &mut Child) {
152-
if let Err(e) = child.kill() {
153-
if e.kind() != std::io::ErrorKind::InvalidInput {
154-
panic!("failed to kill auraed child: {e}");
155-
}
152+
if let Err(e) = child.kill()
153+
&& e.kind() != std::io::ErrorKind::InvalidInput
154+
{
155+
panic!("failed to kill auraed child: {e}");
156156
}
157157
let _ = child.wait();
158158
}

auraed/tests/daemon_should_bind_only_unix_socket.rs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,17 @@ use test_helpers::*;
3131
fn tcp_addrs_available_before_spawn() -> Vec<SocketAddr> {
3232
["127.0.0.1:8080", "[::1]:8080"]
3333
.into_iter()
34-
.filter_map(|addr| addr.parse::<SocketAddr>().ok())
35-
.filter_map(|addr| match TcpListener::bind(addr) {
36-
Ok(listener) => {
37-
drop(listener);
38-
Some(addr)
34+
.filter_map(|addr| {
35+
let addr = addr.parse::<SocketAddr>().ok()?;
36+
match TcpListener::bind(addr) {
37+
Ok(listener) => {
38+
drop(listener);
39+
Some(addr)
40+
}
41+
Err(e) if e.kind() == io::ErrorKind::AddrInUse => None,
42+
Err(e) if e.kind() == io::ErrorKind::AddrNotAvailable => None,
43+
Err(e) => panic!("unexpected error probing {addr}: {e}"),
3944
}
40-
Err(e) if e.kind() == io::ErrorKind::AddrInUse => None,
41-
Err(e) if e.kind() == io::ErrorKind::AddrNotAvailable => None,
42-
Err(e) => panic!("unexpected error probing {addr}: {e}"),
4345
})
4446
.collect()
4547
}
@@ -90,7 +92,7 @@ fn auraed_daemon_mode_should_bind_only_unix_socket() {
9092
// Default daemon mode should not open the documented TCP endpoint ([::1]:8080 or 127.0.0.1:8080).
9193
// Only check addresses that were free before spawning auraed to avoid false positives from other services.
9294
for addr in tcp_addrs {
93-
let tcp_result = TcpListener::bind(addr).map(|listener| drop(listener));
95+
let tcp_result = TcpListener::bind(addr).map(drop);
9496
assert!(
9597
tcp_result.is_ok(),
9698
"expected no TCP listener at {addr}, but binding failed after starting auraed"

0 commit comments

Comments
 (0)