From c52061a3682b55bdcc5724481b207666db9b0494 Mon Sep 17 00:00:00 2001 From: X1a0t Date: Wed, 18 Oct 2023 22:48:38 +0800 Subject: [PATCH] chore: update object_store unit tests and s3 endpoint docs (#3345) --- core/src/services/s3/backend.rs | 1 + integrations/object_store/src/lib.rs | 42 ++++++++++++++++++++++++++-- 2 files changed, 40 insertions(+), 3 deletions(-) diff --git a/core/src/services/s3/backend.rs b/core/src/services/s3/backend.rs index 0216b19361b..f9e160502e8 100644 --- a/core/src/services/s3/backend.rs +++ b/core/src/services/s3/backend.rs @@ -134,6 +134,7 @@ impl S3Builder { /// Endpoint must be full uri, e.g. /// /// - AWS S3: `https://s3.amazonaws.com` or `https://s3.{region}.amazonaws.com` + /// - Cloudflare R2: `https://.r2.cloudflarestorage.com` /// - Aliyun OSS: `https://{region}.aliyuncs.com` /// - Tencent COS: `https://cos.{region}.myqcloud.com` /// - Minio: `http://127.0.0.1:9000` diff --git a/integrations/object_store/src/lib.rs b/integrations/object_store/src/lib.rs index 6f1822d67c9..0173352289d 100644 --- a/integrations/object_store/src/lib.rs +++ b/integrations/object_store/src/lib.rs @@ -305,11 +305,22 @@ mod tests { let path: Path = "data/test.txt".try_into().unwrap(); let bytes = Bytes::from_static(b"hello, world!"); - object_store.put(&path, bytes).await.unwrap(); + object_store.put(&path, bytes.clone()).await.unwrap(); let meta = object_store.head(&path).await.unwrap(); - assert_eq!(meta.size, 13) + assert_eq!(meta.size, 13); + + assert_eq!( + object_store + .get(&path) + .await + .unwrap() + .bytes() + .await + .unwrap(), + bytes + ); } #[tokio::test] @@ -327,8 +338,33 @@ mod tests { .iter() .map(|x| x.as_ref().unwrap().location.as_ref()) .collect::>(); + + let expected_files = vec![ + ( + "data/nested/test.txt", + Bytes::from_static(b"hello, world! I am nested."), + ), + ("data/test.txt", Bytes::from_static(b"hello, world!")), + ]; + + let expected_locations = expected_files.iter().map(|x| x.0).collect::>(); + locations.sort(); - assert_eq!(locations, &["data/nested/test.txt", "data/test.txt"]); + assert_eq!(locations, expected_locations); + + for (location, bytes) in expected_files { + let path: Path = location.try_into().unwrap(); + assert_eq!( + object_store + .get(&path) + .await + .unwrap() + .bytes() + .await + .unwrap(), + bytes + ); + } } #[tokio::test]