This is an automated email from the ASF dual-hosted git repository. suyanhanx pushed a commit to branch test-for-read-if-none-match in repository https://gitbox.apache.org/repos/asf/incubator-opendal.git
commit 54a416afe643173181fc5c97921f9b30c5b65fee Author: suyanhanx <[email protected]> AuthorDate: Fri Apr 28 14:10:48 2023 +0800 test for read_with_override_cache_control Signed-off-by: suyanhanx <[email protected]> --- core/src/services/s3/backend.rs | 1 + core/tests/behavior/write.rs | 56 +++++++++++++++++++++++++++++++++++++++-- 2 files changed, 55 insertions(+), 2 deletions(-) diff --git a/core/src/services/s3/backend.rs b/core/src/services/s3/backend.rs index c718460e..9b2c13b3 100644 --- a/core/src/services/s3/backend.rs +++ b/core/src/services/s3/backend.rs @@ -921,6 +921,7 @@ impl Accessor for S3Backend { read_can_next: true, read_with_if_match: true, read_with_if_none_match: true, + read_with_override_cache_control: true, read_with_override_content_disposition: true, write: true, diff --git a/core/tests/behavior/write.rs b/core/tests/behavior/write.rs index d15b8b25..f98d8642 100644 --- a/core/tests/behavior/write.rs +++ b/core/tests/behavior/write.rs @@ -19,6 +19,7 @@ use anyhow::Result; use futures::AsyncReadExt; use futures::AsyncSeekExt; use futures::StreamExt; +use http::StatusCode; use log::debug; use log::warn; use opendal::ops::OpRead; @@ -101,6 +102,7 @@ macro_rules! behavior_write_tests { test_fuzz_part_reader, test_read_with_dir_path, test_read_with_special_chars, + test_read_with_override_cache_control, test_read_with_override_content_disposition, test_delete, test_delete_empty_dir, @@ -791,6 +793,54 @@ pub async fn test_read_with_special_chars(op: Operator) -> Result<()> { Ok(()) } +/// Read file with override-cache-control should succeed. +pub async fn test_read_with_override_cache_control(op: Operator) -> Result<()> { + if !(op.info().capability().read_with_override_cache_control && op.info().can_presign()) { + return Ok(()); + } + + let path = uuid::Uuid::new_v4().to_string(); + let (content, _) = gen_bytes(); + + op.write(&path, content.clone()) + .await + .expect("write must succeed"); + + let target_cache_control = "no-cache, no-store, must-revalidate"; + + let mut op_read = OpRead::default(); + op_read = op_read.with_override_cache_control(target_cache_control); + + let signed_req = op + .presign_read_with(&path, op_read, Duration::from_secs(60)) + .await + .expect("sign must succeed"); + + let client = reqwest::Client::new(); + let mut req = client.request( + signed_req.method().clone(), + Url::from_str(&signed_req.uri().to_string()).expect("must be valid url"), + ); + for (k, v) in signed_req.header() { + req = req.header(k, v); + } + + let resp = req.send().await.expect("send must succeed"); + + assert_eq!(resp.status(), StatusCode::OK); + assert_eq!( + resp.headers() + .get("cache-control") + .expect("cache-control header must exist") + .to_str() + .expect("cache-control header must be string"), + target_cache_control + ); + + op.delete(&path).await.expect("delete must succeed"); + Ok(()) +} + /// Read file with override_content_disposition should succeed. pub async fn test_read_with_override_content_disposition(op: Operator) -> Result<()> { if !(op @@ -830,11 +880,13 @@ pub async fn test_read_with_override_content_disposition(op: Operator) -> Result let resp = req.send().await.expect("send must succeed"); - assert_eq!(resp.status(), http::StatusCode::OK); + assert_eq!(resp.status(), StatusCode::OK); assert_eq!( resp.headers() .get(http::header::CONTENT_DISPOSITION) - .unwrap(), + .expect("content-disposition header must exist") + .to_str() + .expect("content-disposition header must be string"), target_content_disposition ); assert_eq!(resp.bytes().await?, content);
