From 8f4ada196559f6db17628842bd90e0023b7a4e77 Mon Sep 17 00:00:00 2001 From: Quentin Date: Sat, 7 Nov 2020 13:53:32 +0100 Subject: [PATCH] Add a test for parse_bucket_key --- src/api/api_server.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/api/api_server.rs b/src/api/api_server.rs index 6221d784..dfdd4687 100644 --- a/src/api/api_server.rs +++ b/src/api/api_server.rs @@ -250,6 +250,10 @@ async fn handler_inner(garage: Arc, req: Request) -> Result Result<(&str, Option<&str>), Error> { let path = path.trim_start_matches('/'); @@ -265,3 +269,16 @@ fn parse_bucket_key(path: &str) -> Result<(&str, Option<&str>), Error> { None => Ok((path, None)), } } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn parse_bucket_with_key() -> Result<(), Error> { + let (bucket,key) = parse_bucket_key("/my_bucket/a/super/file.jpg")?; + assert_eq!(bucket, "my_bucket"); + assert_eq!(key.expect("key must be set"), "a/super/file.jpg"); + Ok(()) + } +}