Skip to content

Commit 77ed42a

Browse files
vsilentCopilot
andcommitted
fix(tests): clean remaining all-target warnings and invalid literal
- remove useless UID >= 0 assertion (u32) - replace invalid u16 port overflow test with type-safety test - remove redundant serde_json import - fix cfg-sensitive unused vars in enrichment tests - clean monitor test vars in syscall monitor unit tests - remove unused TestRule in rules engine tests - use from_ref instead of cloned slice in sniff discovery test Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 7824052 commit 77ed42a

7 files changed

Lines changed: 23 additions & 51 deletions

File tree

src/collectors/ebpf/syscall_monitor.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ mod tests {
230230

231231
#[test]
232232
fn test_syscall_monitor_not_running_initially() {
233-
let monitor = SyscallMonitor::new();
233+
let _monitor = SyscallMonitor::new();
234234

235235
#[cfg(all(target_os = "linux", feature = "ebpf"))]
236236
{
@@ -241,23 +241,23 @@ mod tests {
241241

242242
#[test]
243243
fn test_poll_events_empty_when_not_running() {
244-
let mut monitor = SyscallMonitor::new();
244+
let _monitor = SyscallMonitor::new();
245245

246246
#[cfg(all(target_os = "linux", feature = "ebpf"))]
247247
{
248-
let mut monitor = monitor.unwrap();
248+
let mut monitor = _monitor.unwrap();
249249
let events = monitor.poll_events();
250250
assert!(events.is_empty());
251251
}
252252
}
253253

254254
#[test]
255255
fn test_event_count() {
256-
let mut monitor = SyscallMonitor::new();
256+
let _monitor = SyscallMonitor::new();
257257

258258
#[cfg(all(target_os = "linux", feature = "ebpf"))]
259259
{
260-
let mut monitor = monitor.unwrap();
260+
let monitor = _monitor.unwrap();
261261
assert_eq!(monitor.event_count(), 0);
262262
}
263263
}

src/rules/engine.rs

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -102,30 +102,6 @@ impl Default for RuleEngine {
102102
mod tests {
103103
use super::*;
104104

105-
struct TestRule {
106-
name: String,
107-
priority: u32,
108-
should_match: bool,
109-
}
110-
111-
impl Rule for TestRule {
112-
fn evaluate(&self, _event: &SecurityEvent) -> RuleResult {
113-
if self.should_match {
114-
RuleResult::Match
115-
} else {
116-
RuleResult::NoMatch
117-
}
118-
}
119-
120-
fn name(&self) -> &str {
121-
&self.name
122-
}
123-
124-
fn priority(&self) -> u32 {
125-
self.priority
126-
}
127-
}
128-
129105
#[test]
130106
fn test_engine_creation() {
131107
let engine = RuleEngine::new();

src/sniff/discovery.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ mod tests {
233233
writeln!(tmp, "test log line").unwrap();
234234
let path = tmp.path().to_string_lossy().to_string();
235235

236-
let sources = discover_custom_sources(&[path.clone()]);
236+
let sources = discover_custom_sources(std::slice::from_ref(&path));
237237
assert_eq!(sources.len(), 1);
238238
assert_eq!(sources[0].source_type, LogSourceType::CustomFile);
239239
assert_eq!(sources[0].path_or_id, path);

tests/collectors/event_enrichment_test.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ fn test_container_detector_creation() {
4242
// Should work on Linux, may fail on other platforms
4343
#[cfg(target_os = "linux")]
4444
assert!(detector.is_ok());
45+
#[cfg(not(target_os = "linux"))]
46+
assert!(detector.is_err());
4547
}
4648

4749
#[test]
@@ -85,6 +87,11 @@ fn test_container_id_invalid_formats() {
8587
assert!(!result, "Should reject invalid container ID: {}", id);
8688
}
8789
}
90+
91+
#[cfg(not(target_os = "linux"))]
92+
{
93+
assert!(detector.is_err());
94+
}
8895
}
8996

9097
#[test]
@@ -104,10 +111,10 @@ fn test_cgroup_parsing() {
104111

105112
#[test]
106113
fn test_process_tree_enrichment() {
107-
let mut enricher = EventEnricher::new().expect("Failed to create enricher");
114+
let enricher = EventEnricher::new().expect("Failed to create enricher");
108115

109116
// Test that we can get parent PID
110-
let ppid = enricher.get_parent_pid(1); // init process
117+
let _ppid = enricher.get_parent_pid(1); // init process
111118

112119
// PID 1 should exist on Linux
113120
#[cfg(target_os = "linux")]
@@ -119,7 +126,7 @@ fn test_process_comm_enrichment() {
119126
let enricher = EventEnricher::new().expect("Failed to create enricher");
120127

121128
// Test that we can get process name
122-
let comm = enricher.get_process_comm(std::process::id());
129+
let _comm = enricher.get_process_comm(std::process::id());
123130

124131
// Should get some process name
125132
#[cfg(target_os = "linux")]

tests/collectors/execve_capture_test.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,8 @@ mod linux_tests {
107107
.filter(|e| e.syscall_type == SyscallType::Execve)
108108
.collect();
109109

110-
// All events should have valid UID
111-
for event in execve_events {
112-
assert!(event.uid >= 0, "UID should be non-negative");
113-
}
110+
// UID is u32, so only verify iterating events is safe and stable.
111+
for _event in execve_events {}
114112
}
115113

116114
#[test]

tests/events/event_serialization_test.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
//! Tests for JSON and binary serialization of events
44
55
use chrono::Utc;
6-
use serde_json;
76
use stackdog::events::security::SecurityEvent;
87
use stackdog::events::syscall::{SyscallEvent, SyscallType};
98

tests/events/event_validation_test.rs

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -76,19 +76,11 @@ fn test_valid_ip_addresses() {
7676
}
7777

7878
#[test]
79-
fn test_invalid_port() {
80-
let event = NetworkEvent {
81-
src_ip: "192.168.1.1".to_string(),
82-
dst_ip: "10.0.0.1".to_string(),
83-
src_port: 70000, // Invalid port (> 65535)
84-
dst_port: 80,
85-
protocol: "TCP".to_string(),
86-
timestamp: Utc::now(),
87-
container_id: None,
88-
};
89-
90-
let result = EventValidator::validate_network(&event);
91-
assert!(!result.is_valid());
79+
fn test_invalid_port_not_representable_for_u16() {
80+
// NetworkEvent ports are u16, so values > 65535 cannot be constructed.
81+
// This test asserts type-level safety explicitly.
82+
let max = u16::MAX;
83+
assert_eq!(max, 65535);
9284
}
9385

9486
#[test]

0 commit comments

Comments
 (0)