mirror of
https://git.deuxfleurs.fr/Deuxfleurs/garage.git
synced 2024-11-24 17:11:01 +00:00
Add a test for parse_bucket_key
This commit is contained in:
parent
c9c699d377
commit
8f4ada1965
1 changed files with 17 additions and 0 deletions
|
@ -250,6 +250,10 @@ async fn handler_inner(garage: Arc<Garage>, req: Request<Body>) -> Result<Respon
|
|||
}
|
||||
}
|
||||
|
||||
/// Extract the bucket name and the key name from an HTTP path
|
||||
///
|
||||
/// S3 internally manages only buckets and keys. This function splits
|
||||
/// an HTTP path to get the corresponding bucket name and key.
|
||||
fn parse_bucket_key(path: &str) -> 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(())
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue