You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@opendal.apache.org by su...@apache.org on 2023/04/22 10:20:57 UTC
[incubator-opendal] 01/01: feat(core): test for read_with_override_content_composition
This is an automated email from the ASF dual-hosted git repository.
suyanhanx pushed a commit to branch test-for-read-with-override-content-composition
in repository https://gitbox.apache.org/repos/asf/incubator-opendal.git
commit af437c7e8ee147020cbe373ed884efafa2c2ee8d
Author: suyanhanx <su...@gmail.com>
AuthorDate: Sat Apr 22 18:20:23 2023 +0800
feat(core): test for read_with_override_content_composition
Signed-off-by: suyanhanx <su...@gmail.com>
---
core/src/types/operator/metadata.rs | 4 ++++
core/tests/behavior/write.rs | 31 +++++++++++++++++++++++++++++++
2 files changed, 35 insertions(+)
diff --git a/core/src/types/operator/metadata.rs b/core/src/types/operator/metadata.rs
index 599ac753..3b664f9d 100644
--- a/core/src/types/operator/metadata.rs
+++ b/core/src/types/operator/metadata.rs
@@ -51,6 +51,10 @@ impl OperatorInfo {
pub fn can_read(&self) -> bool {
self.0.capability().read
}
+
+ pub fn can_read_with_override_content_disposition(&self) -> bool {
+ self.0.capability().read_with_override_content_disposition
+ }
/// Check if current backend supports [`Accessor::write`] or not.
pub fn can_write(&self) -> bool {
diff --git a/core/tests/behavior/write.rs b/core/tests/behavior/write.rs
index 10082b57..8571726a 100644
--- a/core/tests/behavior/write.rs
+++ b/core/tests/behavior/write.rs
@@ -24,6 +24,7 @@ use log::warn;
use opendal::EntryMode;
use opendal::ErrorKind;
use opendal::Operator;
+use opendal::ops::OpRead;
use sha2::Digest;
use sha2::Sha256;
@@ -580,6 +581,36 @@ pub async fn test_read_with_special_chars(op: Operator) -> Result<()> {
Ok(())
}
+pub async fn test_read_with_override_content_disposition(op: Operator) -> Result<()> {
+ if op.info().can_read_with_override_content_disposition() {
+ let path = uuid::Uuid::new_v4().to_string();
+ let (content, _) = gen_bytes();
+
+ op.write(&path, content.clone())
+ .await
+ .expect("write must succeed");
+
+ let target_content_disposition = "attachment; filename=foo.txt";
+
+ let op_read = OpRead::default();
+ op_read.with_override_content_disposition(target_content_disposition.clone());
+
+ let mut reader = op.reader_with(&path, op_read)
+ .await
+ .expect("reader must succeed");
+
+ let mut buf = Vec::new();
+ reader.read_to_end(&mut buf).await?;
+
+ assert_eq!(buf, content);
+ assert_eq!(reader.content_disposition(), Some("attachment; filename=foo.txt"));
+
+ op.delete(&path).await.expect("delete must succeed");
+ }
+
+ Ok(())
+}
+
// Delete existing file should succeed.
pub async fn test_writer_abort(op: Operator) -> Result<()> {
let path = uuid::Uuid::new_v4().to_string();