Skip to content

Commit

Permalink
Fix clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
kvinwang committed Dec 16, 2024
1 parent 1c651da commit a2915e7
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions tappd/src/http_routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ async fn external_prpc_get(
}

#[get("/logs/<container_name>?<since>&<until>&<follow>&<text>&<timestamps>&<bare>&<tail>")]
#[allow(clippy::too_many_arguments)]
fn get_logs(
container_name: String,
since: Option<&str>,
Expand All @@ -149,7 +150,7 @@ fn get_logs(
) -> TextStream![String] {
// default to 1 hour ago
let since = parse_duration(since.unwrap_or("1h"));
let until = until.map_or(Ok(0), |u| parse_duration(u));
let until = until.map_or(Ok(0), parse_duration);
let tail = tail.unwrap_or("1000".to_string());
TextStream! {
let Ok(since) = since else {
Expand Down Expand Up @@ -317,22 +318,28 @@ mod docker_logs {
#[test]
fn test_parse_duration_units() {
let now = SystemTime::now();
let now_secs = now
.duration_since(UNIX_EPOCH)
.unwrap()
.as_secs() as i64;
let now_secs = now.duration_since(UNIX_EPOCH).unwrap().as_secs() as i64;

// Test seconds
assert_eq!(parse_duration_inner("30s", now).unwrap(), now_secs - 30);

// Test minutes
assert_eq!(parse_duration_inner("5m", now).unwrap(), now_secs - (5 * 60));
assert_eq!(
parse_duration_inner("5m", now).unwrap(),
now_secs - (5 * 60)
);

// Test hours
assert_eq!(parse_duration_inner("2h", now).unwrap(), now_secs - (2 * 3600));
assert_eq!(
parse_duration_inner("2h", now).unwrap(),
now_secs - (2 * 3600)
);

// Test days
assert_eq!(parse_duration_inner("1d", now).unwrap(), now_secs - (24 * 3600));
assert_eq!(
parse_duration_inner("1d", now).unwrap(),
now_secs - (24 * 3600)
);
}

#[test]
Expand Down

0 comments on commit a2915e7

Please sign in to comment.