pulled out tests and validated them

This commit is contained in:
ari committed 2026-10-20 21:58:33 -04:00
1 parent dc8d62da30
commit 435a54a02d
67 files changed
+6927 -6957

No files matched your search

+2 -125
View File
@@ -455,128 +455,5 @@ fn parse_line(stream: LogStream, raw: &[u8]) -> LogLine {
}
#[cfg(test)]
mod tests {
use super::*;
fn frame_out(s: &str) -> LogOutput {
LogOutput::StdOut {
message: s.to_owned().into(),
}
}
#[test]
fn names() {
assert_eq!(normalize_name("/web-1").unwrap(), "web-1");
assert_eq!(normalize_name("web.1_x").unwrap(), "web.1_x");
assert!(normalize_name("").is_err());
assert!(normalize_name("a/b").is_err());
assert!(normalize_name("..").is_err());
assert!(normalize_name("-x").is_err());
assert!(normalize_name("a?b").is_err());
}
#[test]
fn line_parsing_and_splitting() {
let mut sp = LineSplitter::default();
let mut got = Vec::new();
sp.push(frame_out("2026-10-15T12:00:00.123456789Z hel"), &mut |l| {
got.push(l)
});
assert!(got.is_empty());
sp.push(
frame_out("lo\n2026-10-15T12:00:01Z two\npartial"),
&mut |l| got.push(l),
);
assert_eq!(got.len(), 2);
assert_eq!(got[0].message, "hello");
assert!(got[0].ts.is_some());
assert_eq!(got[1].message, "two");
sp.finish(&mut |l| got.push(l));
assert_eq!(got[2].message, "partial");
assert_eq!(got[2].ts, None);
}
#[test]
fn error_mapping() {
let nf = BollardError::DockerResponseServerError {
status_code: 404,
message: "no such".into(),
};
assert!(matches!(
map_container_error(&nf, "s", "c"),
AppError::NotFound(_)
));
let denied = BollardError::IOError {
err: std::io::Error::from(ErrorKind::PermissionDenied),
};
assert!(matches!(map_error(&denied, "s"), AppError::Unavailable(_)));
let refused = BollardError::IOError {
err: std::io::Error::from(ErrorKind::ConnectionRefused),
};
assert!(matches!(map_error(&refused, "s"), AppError::Unavailable(_)));
}
#[test]
fn summary_mapping() {
use bollard::models::{ContainerState, Health, HealthStatusEnum};
let i = ContainerInspectResponse {
id: Some("abc".into()),
name: Some("/web".into()),
restart_count: Some(2),
state: Some(ContainerState {
status: Some(ContainerStateStatusEnum::RUNNING),
started_at: Some("2026-10-15T12:00:00Z".into()),
health: Some(Health {
status: Some(HealthStatusEnum::HEALTHY),
..Default::default()
}),
..Default::default()
}),
..Default::default()
};
let now: Timestamp = "2026-10-15T12:01:00Z".parse().unwrap();
let s = summary_from_inspect(&i, now);
assert_eq!(s.name, "web");
assert_eq!(s.state, "running");
assert_eq!(s.health.as_deref(), Some("healthy"));
assert_eq!(s.uptime_seconds, Some(60));
assert_eq!(s.restart_count, Some(2));
}
#[test]
fn log_driver_check() {
let mut i = ContainerInspectResponse::default();
assert!(check_log_driver(&i, "c").is_ok());
i.host_config = Some(bollard::models::HostConfig {
log_config: Some(bollard::models::HostConfigLogConfig {
typ: Some("syslog".into()),
config: None,
}),
..Default::default()
});
match check_log_driver(&i, "c") {
Err(AppError::BadRequest(m)) => assert!(m.contains("syslog")),
other => panic!("unexpected {other:?}"),
}
}
#[tokio::test]
async fn missing_socket_is_unavailable() {
let mut cfg = Config::default();
cfg.sources.docker_socket = PathBuf::from("/nonexistent/docker.sock");
let d = BollardDocker::new(&cfg, CancellationToken::new());
assert!(matches!(d.ps(true).await, Err(AppError::Unavailable(_))));
assert!(matches!(
d.container_status("x").await,
Err(AppError::Unavailable(_))
));
assert!(matches!(
d.logs("x", &LogOptions::default()).await,
Err(AppError::Unavailable(_))
));
assert!(matches!(
d.follow_logs("x", &LogOptions::default()).await,
Err(AppError::Unavailable(_))
));
}
}
#[path = "docker_tests.rs"]
mod tests;