diff options
author | Quentin Dufour <quentin@deuxfleurs.fr> | 2022-02-09 18:29:08 +0100 |
---|---|---|
committer | Quentin Dufour <quentin@deuxfleurs.fr> | 2022-03-07 17:32:07 +0100 |
commit | 1e639ec67c72730fda370e1c3dfe9cbba0b4fa63 (patch) | |
tree | f782305f3de7f53178f9b57de93ab4aa96c58d0c /src | |
parent | cfea1e0315a2e2ad72ce05dffb44ed355e880e46 (diff) | |
download | garage-1e639ec67c72730fda370e1c3dfe9cbba0b4fa63.tar.gz garage-1e639ec67c72730fda370e1c3dfe9cbba0b4fa63.zip |
Functional test for ListMultipartUploads
Diffstat (limited to 'src')
-rw-r--r-- | src/garage/tests/bucket.rs | 23 | ||||
-rw-r--r-- | src/garage/tests/list.rs | 183 |
2 files changed, 199 insertions, 7 deletions
diff --git a/src/garage/tests/bucket.rs b/src/garage/tests/bucket.rs index 2c3af542..1a534042 100644 --- a/src/garage/tests/bucket.rs +++ b/src/garage/tests/bucket.rs @@ -23,12 +23,14 @@ async fn test_bucket_all() { { // List buckets let r = ctx.client.list_buckets().send().await.unwrap(); - - assert_eq!(r.buckets.as_ref().unwrap().len(), 1); - assert_eq!( - r.buckets.unwrap().first().unwrap().name.as_ref().unwrap(), - bucket_name - ); + assert!(r + .buckets + .as_ref() + .unwrap() + .into_iter() + .filter(|x| x.name.as_ref().is_some()) + .find(|x| x.name.as_ref().unwrap() == "hello") + .is_some()); } { // Get its location @@ -73,6 +75,13 @@ async fn test_bucket_all() { { // Check bucket is deleted with List buckets let r = ctx.client.list_buckets().send().await.unwrap(); - assert_eq!(r.buckets.as_ref().unwrap().len(), 0); + assert!(r + .buckets + .as_ref() + .unwrap() + .into_iter() + .filter(|x| x.name.as_ref().is_some()) + .find(|x| x.name.as_ref().unwrap() == "hello") + .is_none()); } } diff --git a/src/garage/tests/list.rs b/src/garage/tests/list.rs index 72492a89..6e092a3f 100644 --- a/src/garage/tests/list.rs +++ b/src/garage/tests/list.rs @@ -1,6 +1,7 @@ use crate::common; const KEYS: [&str; 8] = ["a", "a/a", "a/b", "a/c", "a/d/a", "a/é", "b", "c"]; +const KEYS_MULTIPART: [&str; 5] = ["a", "a", "c", "c/a", "c/b"]; #[tokio::test] async fn test_listobjectsv2() { @@ -430,3 +431,185 @@ async fn test_listobjectsv1() { assert!(r.common_prefixes.is_none()); } } + +#[tokio::test] +async fn test_listmultipart() { + let ctx = common::context(); + let bucket = ctx.create_bucket("listmultipartuploads"); + + for k in KEYS_MULTIPART { + ctx.client + .create_multipart_upload() + .bucket(&bucket) + .key(k) + .send() + .await + .unwrap(); + } + + { + // Default + let r = ctx + .client + .list_multipart_uploads() + .bucket(&bucket) + .send() + .await + .unwrap(); + + assert_eq!(r.uploads.unwrap().len(), 5); + assert!(r.common_prefixes.is_none()); + } + { + // With pagination + let mut next = None; + let mut upnext = None; + let last_idx = KEYS_MULTIPART.len() - 1; + + for i in 0..KEYS_MULTIPART.len() { + let r = ctx + .client + .list_multipart_uploads() + .bucket(&bucket) + .set_key_marker(next) + .set_upload_id_marker(upnext) + .max_uploads(1) + .send() + .await + .unwrap(); + + next = r.next_key_marker; + upnext = r.next_upload_id_marker; + + assert_eq!(r.uploads.unwrap().len(), 1); + assert!(r.common_prefixes.is_none()); + if i != last_idx { + assert!(next.is_some()); + } + } + } + { + // With delimiter + let r = ctx + .client + .list_multipart_uploads() + .bucket(&bucket) + .delimiter("/") + .send() + .await + .unwrap(); + + assert_eq!(r.uploads.unwrap().len(), 3); + assert_eq!(r.common_prefixes.unwrap().len(), 1); + } + { + // With delimiter and pagination + let mut next = None; + let mut upnext = None; + let mut upcnt = 0; + let mut pfxcnt = 0; + let mut loopcnt = 0; + + while loopcnt < KEYS_MULTIPART.len() { + let r = ctx + .client + .list_multipart_uploads() + .bucket(&bucket) + .delimiter("/") + .max_uploads(1) + .set_key_marker(next) + .set_upload_id_marker(upnext) + .send() + .await + .unwrap(); + + next = r.next_key_marker; + upnext = r.next_upload_id_marker; + + loopcnt += 1; + upcnt += r.uploads.unwrap_or(vec![]).len(); + pfxcnt += r.common_prefixes.unwrap_or(vec![]).len(); + + if next.is_none() { + break; + } + } + + assert_eq!(upcnt + pfxcnt, loopcnt); + assert_eq!(upcnt, 3); + assert_eq!(pfxcnt, 1); + } + { + // With prefix + let r = ctx + .client + .list_multipart_uploads() + .bucket(&bucket) + .prefix("c") + .send() + .await + .unwrap(); + + assert_eq!(r.uploads.unwrap().len(), 3); + assert!(r.common_prefixes.is_none()); + } + { + // With prefix and delimiter + let r = ctx + .client + .list_multipart_uploads() + .bucket(&bucket) + .prefix("c") + .delimiter("/") + .send() + .await + .unwrap(); + + assert_eq!(r.uploads.unwrap().len(), 1); + assert_eq!(r.common_prefixes.unwrap().len(), 1); + } + { + // With prefix, delimiter and max keys + let r = ctx + .client + .list_multipart_uploads() + .bucket(&bucket) + .prefix("c") + .delimiter("/") + .max_uploads(1) + .send() + .await + .unwrap(); + + assert_eq!(r.uploads.unwrap().len(), 1); + assert!(r.common_prefixes.is_none()); + } + { + // With starting token before the first element + let r = ctx + .client + .list_multipart_uploads() + .bucket(&bucket) + .key_marker("ZZZZZ") + .send() + .await + .unwrap(); + + assert_eq!(r.uploads.unwrap().len(), 5); + assert!(r.common_prefixes.is_none()); + } + { + // With starting token after the last element + let r = ctx + .client + .list_multipart_uploads() + .bucket(&bucket) + .key_marker("d") + .send() + .await + .unwrap(); + + assert!(r.uploads.is_none()); + assert!(r.common_prefixes.is_none()); + } +} |