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/07/09 10:01:06 UTC
[incubator-opendal] 01/01: try to remove parent folder
This is an automated email from the ASF dual-hosted git repository.
suyanhanx pushed a commit to branch test-remove-parents-folder
in repository https://gitbox.apache.org/repos/asf/incubator-opendal.git
commit e2cad8531bb6d5fe7d2efdad475afa3ff519e078
Author: suyanhanx <su...@gmail.com>
AuthorDate: Sun Jul 9 18:00:36 2023 +0800
try to remove parent folder
Signed-off-by: suyanhanx <su...@gmail.com>
---
core/tests/behavior/append.rs | 7 +++--
core/tests/behavior/blocking_copy.rs | 27 ++++++++++-------
core/tests/behavior/blocking_list.rs | 11 +++++--
core/tests/behavior/blocking_rename.rs | 29 ++++++++++--------
core/tests/behavior/blocking_write.rs | 28 +++++++++--------
core/tests/behavior/copy.rs | 23 ++++++++------
core/tests/behavior/list.rs | 20 +++++++++----
core/tests/behavior/presign.rs | 6 ++--
core/tests/behavior/rename.rs | 29 ++++++++++--------
core/tests/behavior/write.rs | 55 ++++++++++++++++++++++------------
10 files changed, 146 insertions(+), 89 deletions(-)
diff --git a/core/tests/behavior/append.rs b/core/tests/behavior/append.rs
index 0e5cf8801..10a0e5666 100644
--- a/core/tests/behavior/append.rs
+++ b/core/tests/behavior/append.rs
@@ -36,7 +36,7 @@ pub fn behavior_append_tests(op: &Operator) -> Vec<Trial> {
async_trials!(
op,
test_append_create_append,
- test_append_with_dir_path,
+ test_append_to_dir_path,
test_append_with_cache_control,
test_append_with_content_type,
test_append_with_content_disposition,
@@ -71,7 +71,7 @@ pub async fn test_append_create_append(op: Operator) -> Result<()> {
}
/// Test append to a directory path must fail.
-pub async fn test_append_with_dir_path(op: Operator) -> Result<()> {
+pub async fn test_append_to_dir_path(op: Operator) -> Result<()> {
let path = format!("{}/", uuid::Uuid::new_v4());
let (content, _) = gen_bytes();
@@ -79,6 +79,8 @@ pub async fn test_append_with_dir_path(op: Operator) -> Result<()> {
assert!(res.is_err());
assert_eq!(res.unwrap_err().kind(), ErrorKind::IsADirectory);
+ op.delete(&path).await.expect("delete file must success");
+
Ok(())
}
@@ -194,6 +196,7 @@ pub async fn test_appender_futures_copy(op: Operator) -> Result<()> {
);
op.delete(&path).await.expect("delete must succeed");
+
Ok(())
}
diff --git a/core/tests/behavior/blocking_copy.rs b/core/tests/behavior/blocking_copy.rs
index 43d0faec5..749370e6d 100644
--- a/core/tests/behavior/blocking_copy.rs
+++ b/core/tests/behavior/blocking_copy.rs
@@ -54,6 +54,7 @@ pub fn test_blocking_copy_file(op: BlockingOperator) -> Result<()> {
op.delete(&source_path).expect("delete must succeed");
op.delete(&target_path).expect("delete must succeed");
+
Ok(())
}
@@ -66,6 +67,7 @@ pub fn test_blocking_copy_non_existing_source(op: BlockingOperator) -> Result<()
.copy(&source_path, &target_path)
.expect_err("copy must fail");
assert_eq!(err.kind(), ErrorKind::NotFound);
+
Ok(())
}
@@ -80,6 +82,9 @@ pub fn test_blocking_copy_source_dir(op: BlockingOperator) -> Result<()> {
.copy(&source_path, &target_path)
.expect_err("copy must fail");
assert_eq!(err.kind(), ErrorKind::IsADirectory);
+
+ op.delete(&source_path).expect("delete must succeed");
+
Ok(())
}
@@ -101,6 +106,7 @@ pub fn test_blocking_copy_target_dir(op: BlockingOperator) -> Result<()> {
op.delete(&source_path).expect("delete must succeed");
op.delete(&target_path).expect("delete must succeed");
+
Ok(())
}
@@ -117,30 +123,28 @@ pub fn test_blocking_copy_self(op: BlockingOperator) -> Result<()> {
assert_eq!(err.kind(), ErrorKind::IsSameFile);
op.delete(&source_path).expect("delete must succeed");
+
Ok(())
}
/// Copy to a nested path, parent path should be created successfully.
pub fn test_blocking_copy_nested(op: BlockingOperator) -> Result<()> {
- let source_path = uuid::Uuid::new_v4().to_string();
+ let dir = &format!("{}/", uuid::Uuid::new_v4());
+
+ let source_path = &format!("{}{}/{}", dir, uuid::Uuid::new_v4(), uuid::Uuid::new_v4());
let (source_content, _) = gen_bytes();
- op.write(&source_path, source_content.clone())?;
+ op.write(source_path, source_content.clone())?;
- let target_path = format!(
- "{}/{}/{}",
- uuid::Uuid::new_v4(),
- uuid::Uuid::new_v4(),
- uuid::Uuid::new_v4()
- );
+ let target_path = format!("{}{}/{}", dir, uuid::Uuid::new_v4(), uuid::Uuid::new_v4());
- op.copy(&source_path, &target_path)?;
+ op.copy(source_path, &target_path)?;
let target_content = op.read(&target_path).expect("read must succeed");
assert_eq!(target_content, source_content);
- op.delete(&source_path).expect("delete must succeed");
- op.delete(&target_path).expect("delete must succeed");
+ op.remove_all(dir).expect("remove_all must succeed");
+
Ok(())
}
@@ -164,5 +168,6 @@ pub fn test_blocking_copy_overwrite(op: BlockingOperator) -> Result<()> {
op.delete(&source_path).expect("delete must succeed");
op.delete(&target_path).expect("delete must succeed");
+
Ok(())
}
diff --git a/core/tests/behavior/blocking_list.rs b/core/tests/behavior/blocking_list.rs
index 745396848..bb26f1c4d 100644
--- a/core/tests/behavior/blocking_list.rs
+++ b/core/tests/behavior/blocking_list.rs
@@ -43,7 +43,6 @@ pub fn behavior_blocking_list_tests(op: &Operator) -> Vec<Trial> {
pub fn test_blocking_list_dir(op: BlockingOperator) -> Result<()> {
let parent = uuid::Uuid::new_v4().to_string();
let path = format!("{parent}/{}", uuid::Uuid::new_v4());
- debug!("Generate a random file: {}", &path);
let (content, size) = gen_bytes();
op.write(&path, content).expect("write must succeed");
@@ -63,7 +62,9 @@ pub fn test_blocking_list_dir(op: BlockingOperator) -> Result<()> {
}
assert!(found, "file should be found in list");
- op.delete(&path).expect("delete must succeed");
+ op.remove_all(&format!("{parent}/"))
+ .expect("remove must succeed");
+
Ok(())
}
@@ -80,6 +81,7 @@ pub fn test_blocking_list_non_exist_dir(op: BlockingOperator) -> Result<()> {
debug!("got objects: {:?}", objects);
assert_eq!(objects.len(), 0, "dir should only return empty");
+
Ok(())
}
@@ -116,6 +118,9 @@ pub fn test_blocking_scan(op: BlockingOperator) -> Result<()> {
assert!(actual.contains("x/y"));
assert!(actual.contains("x/x/y"));
assert!(actual.contains("x/x/x/y"));
+
+ op.remove_all(&format!("{parent}/"))?;
+
Ok(())
}
@@ -135,7 +140,7 @@ pub fn test_blocking_remove_all(op: BlockingOperator) -> Result<()> {
}
}
- op.remove_all(&format!("{parent}/x/"))?;
+ op.remove_all(&format!("{parent}/"))?;
for path in expected.iter() {
if path.ends_with('/') {
diff --git a/core/tests/behavior/blocking_rename.rs b/core/tests/behavior/blocking_rename.rs
index 4506c2c5c..e1d7d2b73 100644
--- a/core/tests/behavior/blocking_rename.rs
+++ b/core/tests/behavior/blocking_rename.rs
@@ -57,6 +57,7 @@ pub fn test_blocking_rename_file(op: BlockingOperator) -> Result<()> {
op.delete(&source_path).expect("delete must succeed");
op.delete(&target_path).expect("delete must succeed");
+
Ok(())
}
@@ -69,6 +70,7 @@ pub fn test_blocking_rename_non_existing_source(op: BlockingOperator) -> Result<
.rename(&source_path, &target_path)
.expect_err("rename must fail");
assert_eq!(err.kind(), ErrorKind::NotFound);
+
Ok(())
}
@@ -83,6 +85,9 @@ pub fn test_blocking_rename_source_dir(op: BlockingOperator) -> Result<()> {
.rename(&source_path, &target_path)
.expect_err("rename must fail");
assert_eq!(err.kind(), ErrorKind::IsADirectory);
+
+ op.delete(&source_path).expect("delete must succeed");
+
Ok(())
}
@@ -104,6 +109,7 @@ pub fn test_blocking_rename_target_dir(op: BlockingOperator) -> Result<()> {
op.delete(&source_path).expect("delete must succeed");
op.delete(&target_path).expect("delete must succeed");
+
Ok(())
}
@@ -120,33 +126,31 @@ pub fn test_blocking_rename_self(op: BlockingOperator) -> Result<()> {
assert_eq!(err.kind(), ErrorKind::IsSameFile);
op.delete(&source_path).expect("delete must succeed");
+
Ok(())
}
/// Rename to a nested path, parent path should be created successfully.
pub fn test_blocking_rename_nested(op: BlockingOperator) -> Result<()> {
- let source_path = uuid::Uuid::new_v4().to_string();
+ let dir = &format!("{}/", uuid::Uuid::new_v4());
+
+ let source_path = &format!("{}{}/{}", dir, uuid::Uuid::new_v4(), uuid::Uuid::new_v4());
let (source_content, _) = gen_bytes();
- op.write(&source_path, source_content.clone())?;
+ op.write(source_path, source_content.clone())?;
- let target_path = format!(
- "{}/{}/{}",
- uuid::Uuid::new_v4(),
- uuid::Uuid::new_v4(),
- uuid::Uuid::new_v4()
- );
+ let target_path = format!("{}{}/{}", dir, uuid::Uuid::new_v4(), uuid::Uuid::new_v4());
- op.rename(&source_path, &target_path)?;
+ op.rename(source_path, &target_path)?;
- let err = op.stat(&source_path).expect_err("stat must fail");
+ let err = op.stat(source_path).expect_err("stat must fail");
assert_eq!(err.kind(), ErrorKind::NotFound);
let target_content = op.read(&target_path).expect("read must succeed");
assert_eq!(target_content, source_content);
- op.delete(&source_path).expect("delete must succeed");
- op.delete(&target_path).expect("delete must succeed");
+ op.remove_all(dir).expect("delete must succeed");
+
Ok(())
}
@@ -173,5 +177,6 @@ pub fn test_blocking_rename_overwrite(op: BlockingOperator) -> Result<()> {
op.delete(&source_path).expect("delete must succeed");
op.delete(&target_path).expect("delete must succeed");
+
Ok(())
}
diff --git a/core/tests/behavior/blocking_write.rs b/core/tests/behavior/blocking_write.rs
index 3775509c2..efc1a568f 100644
--- a/core/tests/behavior/blocking_write.rs
+++ b/core/tests/behavior/blocking_write.rs
@@ -19,7 +19,7 @@ use std::io::Read;
use std::io::Seek;
use anyhow::Result;
-use log::debug;
+
use sha2::Digest;
use sha2::Sha256;
@@ -65,6 +65,7 @@ pub fn test_blocking_create_dir(op: BlockingOperator) -> Result<()> {
assert_eq!(meta.mode(), EntryMode::DIR);
op.delete(&path).expect("delete must succeed");
+
Ok(())
}
@@ -80,13 +81,13 @@ pub fn test_blocking_create_dir_existing(op: BlockingOperator) -> Result<()> {
assert_eq!(meta.mode(), EntryMode::DIR);
op.delete(&path).expect("delete must succeed");
+
Ok(())
}
/// Write a single file and test with stat.
pub fn test_blocking_write_file(op: BlockingOperator) -> Result<()> {
let path = uuid::Uuid::new_v4().to_string();
- debug!("Generate a random file: {}", &path);
let (content, size) = gen_bytes();
op.write(&path, content)?;
@@ -95,6 +96,7 @@ pub fn test_blocking_write_file(op: BlockingOperator) -> Result<()> {
assert_eq!(meta.content_length(), size as u64);
op.delete(&path).expect("delete must succeed");
+
Ok(())
}
@@ -107,13 +109,14 @@ pub fn test_blocking_write_with_dir_path(op: BlockingOperator) -> Result<()> {
assert!(result.is_err());
assert_eq!(result.unwrap_err().kind(), ErrorKind::IsADirectory);
+ op.delete(&path).expect("delete must succeed");
+
Ok(())
}
/// Write a single file with special chars should succeed.
pub fn test_blocking_write_with_special_chars(op: BlockingOperator) -> Result<()> {
let path = format!("{} !@#$%^&()_+-=;',.txt", uuid::Uuid::new_v4());
- debug!("Generate a random file: {}", &path);
let (content, size) = gen_bytes();
op.write(&path, content)?;
@@ -122,13 +125,13 @@ pub fn test_blocking_write_with_special_chars(op: BlockingOperator) -> Result<()
assert_eq!(meta.content_length(), size as u64);
op.delete(&path).expect("delete must succeed");
+
Ok(())
}
/// Stat existing file should return metadata
pub fn test_blocking_stat_file(op: BlockingOperator) -> Result<()> {
let path = uuid::Uuid::new_v4().to_string();
- debug!("Generate a random file: {}", &path);
let (content, size) = gen_bytes();
op.write(&path, content).expect("write must succeed");
@@ -138,6 +141,7 @@ pub fn test_blocking_stat_file(op: BlockingOperator) -> Result<()> {
assert_eq!(meta.content_length(), size as u64);
op.delete(&path).expect("delete must succeed");
+
Ok(())
}
@@ -151,13 +155,13 @@ pub fn test_blocking_stat_dir(op: BlockingOperator) -> Result<()> {
assert_eq!(meta.mode(), EntryMode::DIR);
op.delete(&path).expect("delete must succeed");
+
Ok(())
}
/// Stat existing file with special chars should return metadata
pub fn test_blocking_stat_with_special_chars(op: BlockingOperator) -> Result<()> {
let path = format!("{} !@#$%^&()_+-=;',.txt", uuid::Uuid::new_v4());
- debug!("Generate a random file: {}", &path);
let (content, size) = gen_bytes();
op.write(&path, content).expect("write must succeed");
@@ -167,6 +171,7 @@ pub fn test_blocking_stat_with_special_chars(op: BlockingOperator) -> Result<()>
assert_eq!(meta.content_length(), size as u64);
op.delete(&path).expect("delete must succeed");
+
Ok(())
}
@@ -184,7 +189,6 @@ pub fn test_blocking_stat_not_exist(op: BlockingOperator) -> Result<()> {
/// Read full content should match.
pub fn test_blocking_read_full(op: BlockingOperator) -> Result<()> {
let path = uuid::Uuid::new_v4().to_string();
- debug!("Generate a random file: {}", &path);
let (content, size) = gen_bytes();
op.write(&path, content.clone())
@@ -199,13 +203,13 @@ pub fn test_blocking_read_full(op: BlockingOperator) -> Result<()> {
);
op.delete(&path).expect("delete must succeed");
+
Ok(())
}
/// Read range content should match.
pub fn test_blocking_read_range(op: BlockingOperator) -> Result<()> {
let path = uuid::Uuid::new_v4().to_string();
- debug!("Generate a random file: {}", &path);
let (content, size) = gen_bytes();
let (offset, length) = gen_offset_length(size);
@@ -224,13 +228,13 @@ pub fn test_blocking_read_range(op: BlockingOperator) -> Result<()> {
);
op.delete(&path).expect("delete must succeed");
+
Ok(())
}
/// Read large range content should match.
pub fn test_blocking_read_large_range(op: BlockingOperator) -> Result<()> {
let path = uuid::Uuid::new_v4().to_string();
- debug!("Generate a random file: {}", &path);
let (content, size) = gen_bytes();
let (offset, _) = gen_offset_length(size);
@@ -250,6 +254,7 @@ pub fn test_blocking_read_large_range(op: BlockingOperator) -> Result<()> {
);
op.delete(&path).expect("delete must succeed");
+
Ok(())
}
@@ -266,7 +271,6 @@ pub fn test_blocking_read_not_exist(op: BlockingOperator) -> Result<()> {
pub fn test_blocking_fuzz_range_reader(op: BlockingOperator) -> Result<()> {
let path = uuid::Uuid::new_v4().to_string();
- debug!("Generate a random file: {}", &path);
let (content, _) = gen_bytes();
op.write(&path, content.clone())
@@ -294,12 +298,12 @@ pub fn test_blocking_fuzz_range_reader(op: BlockingOperator) -> Result<()> {
}
op.delete(&path).expect("delete must succeed");
+
Ok(())
}
pub fn test_blocking_fuzz_offset_reader(op: BlockingOperator) -> Result<()> {
let path = uuid::Uuid::new_v4().to_string();
- debug!("Generate a random file: {}", &path);
let (content, _) = gen_bytes();
op.write(&path, content.clone())
@@ -327,12 +331,12 @@ pub fn test_blocking_fuzz_offset_reader(op: BlockingOperator) -> Result<()> {
}
op.delete(&path).expect("delete must succeed");
+
Ok(())
}
pub fn test_blocking_fuzz_part_reader(op: BlockingOperator) -> Result<()> {
let path = uuid::Uuid::new_v4().to_string();
- debug!("Generate a random file: {}", &path);
let (content, size) = gen_bytes();
let (offset, length) = gen_offset_length(size);
@@ -361,13 +365,13 @@ pub fn test_blocking_fuzz_part_reader(op: BlockingOperator) -> Result<()> {
}
op.delete(&path).expect("delete must succeed");
+
Ok(())
}
// Delete existing file should succeed.
pub fn test_blocking_delete_file(op: BlockingOperator) -> Result<()> {
let path = uuid::Uuid::new_v4().to_string();
- debug!("Generate a random file: {}", &path);
let (content, _) = gen_bytes();
op.write(&path, content).expect("write must succeed");
diff --git a/core/tests/behavior/copy.rs b/core/tests/behavior/copy.rs
index 086fa160e..5f20640ac 100644
--- a/core/tests/behavior/copy.rs
+++ b/core/tests/behavior/copy.rs
@@ -54,6 +54,7 @@ pub async fn test_copy_file(op: Operator) -> Result<()> {
op.delete(&source_path).await.expect("delete must succeed");
op.delete(&target_path).await.expect("delete must succeed");
+
Ok(())
}
@@ -67,6 +68,7 @@ pub async fn test_copy_non_existing_source(op: Operator) -> Result<()> {
.await
.expect_err("copy must fail");
assert_eq!(err.kind(), ErrorKind::NotFound);
+
Ok(())
}
@@ -82,6 +84,9 @@ pub async fn test_copy_source_dir(op: Operator) -> Result<()> {
.await
.expect_err("copy must fail");
assert_eq!(err.kind(), ErrorKind::IsADirectory);
+
+ op.delete(&source_path).await.expect("delete must succeed");
+
Ok(())
}
@@ -104,6 +109,7 @@ pub async fn test_copy_target_dir(op: Operator) -> Result<()> {
op.delete(&source_path).await.expect("delete must succeed");
op.delete(&target_path).await.expect("delete must succeed");
+
Ok(())
}
@@ -121,30 +127,28 @@ pub async fn test_copy_self(op: Operator) -> Result<()> {
assert_eq!(err.kind(), ErrorKind::IsSameFile);
op.delete(&source_path).await.expect("delete must succeed");
+
Ok(())
}
/// Copy to a nested path, parent path should be created successfully.
pub async fn test_copy_nested(op: Operator) -> Result<()> {
- let source_path = uuid::Uuid::new_v4().to_string();
+ let dir = &format!("{}/", uuid::Uuid::new_v4());
+
+ let source_path = format!("{}{}/{}", dir, uuid::Uuid::new_v4(), uuid::Uuid::new_v4());
let (source_content, _) = gen_bytes();
op.write(&source_path, source_content.clone()).await?;
- let target_path = format!(
- "{}/{}/{}",
- uuid::Uuid::new_v4(),
- uuid::Uuid::new_v4(),
- uuid::Uuid::new_v4()
- );
+ let target_path = format!("{}{}/{}", dir, uuid::Uuid::new_v4(), uuid::Uuid::new_v4());
op.copy(&source_path, &target_path).await?;
let target_content = op.read(&target_path).await.expect("read must succeed");
assert_eq!(target_content, source_content);
- op.delete(&source_path).await.expect("delete must succeed");
- op.delete(&target_path).await.expect("delete must succeed");
+ op.remove_all(dir).await.expect("remove_all must succeed");
+
Ok(())
}
@@ -168,5 +172,6 @@ pub async fn test_copy_overwrite(op: Operator) -> Result<()> {
op.delete(&source_path).await.expect("delete must succeed");
op.delete(&target_path).await.expect("delete must succeed");
+
Ok(())
}
diff --git a/core/tests/behavior/list.rs b/core/tests/behavior/list.rs
index eed9021f5..bfbb84103 100644
--- a/core/tests/behavior/list.rs
+++ b/core/tests/behavior/list.rs
@@ -61,7 +61,6 @@ pub async fn test_check(op: Operator) -> Result<()> {
pub async fn test_list_dir(op: Operator) -> Result<()> {
let parent = uuid::Uuid::new_v4().to_string();
let path = format!("{parent}/{}", uuid::Uuid::new_v4());
- debug!("Generate a random file: {}", &path);
let (content, size) = gen_bytes();
op.write(&path, content).await.expect("write must succeed");
@@ -80,7 +79,8 @@ pub async fn test_list_dir(op: Operator) -> Result<()> {
}
assert!(found, "file should be found in list");
- op.delete(&path).await.expect("delete must succeed");
+ op.remove_all(&format!("{parent}/")).await?;
+
Ok(())
}
@@ -117,6 +117,7 @@ pub async fn test_list_rich_dir(op: Operator) -> Result<()> {
assert_eq!(actual, expected);
op.remove_all("test_list_rich_dir/").await?;
+
Ok(())
}
@@ -136,6 +137,7 @@ pub async fn test_list_empty_dir(op: Operator) -> Result<()> {
assert_eq!(objects.len(), 0, "dir should only return empty");
op.delete(&dir).await.expect("delete must succeed");
+
Ok(())
}
@@ -151,6 +153,7 @@ pub async fn test_list_non_exist_dir(op: Operator) -> Result<()> {
debug!("got objects: {:?}", objects);
assert_eq!(objects.len(), 0, "dir should only return empty");
+
Ok(())
}
@@ -174,6 +177,7 @@ pub async fn test_list_sub_dir(op: Operator) -> Result<()> {
assert!(found, "dir should be found in list");
op.delete(&path).await.expect("delete must succeed");
+
Ok(())
}
@@ -225,9 +229,8 @@ pub async fn test_list_nested_dir(op: Operator) -> Result<()> {
.await?;
assert_eq!(meta.mode(), EntryMode::DIR);
- op.delete(&file_path).await.expect("delete must succeed");
- op.delete(&dir_path).await.expect("delete must succeed");
- op.delete(&dir).await.expect("delete must succeed");
+ op.remove_all(&dir).await.expect("delete must succeed");
+
Ok(())
}
@@ -294,6 +297,7 @@ pub async fn test_scan_root(op: Operator) -> Result<()> {
assert!(!actual.contains("/"), "empty root should return itself");
assert!(!actual.contains(""), "empty root should return empty");
+
Ok(())
}
@@ -330,6 +334,9 @@ pub async fn test_scan(op: Operator) -> Result<()> {
assert!(actual.contains("x/y"));
assert!(actual.contains("x/x/y"));
assert!(actual.contains("x/x/x/y"));
+
+ op.remove_all(&format!("{parent}/")).await?;
+
Ok(())
}
@@ -348,7 +355,7 @@ pub async fn test_remove_all(op: Operator) -> Result<()> {
}
}
- op.remove_all(&format!("{parent}/x/")).await?;
+ op.remove_all(&format!("{parent}/")).await?;
for path in expected.iter() {
if path.ends_with('/') {
@@ -359,5 +366,6 @@ pub async fn test_remove_all(op: Operator) -> Result<()> {
"{parent}/{path} should be removed"
)
}
+
Ok(())
}
diff --git a/core/tests/behavior/presign.rs b/core/tests/behavior/presign.rs
index 8e2b2d2f2..29c19f52c 100644
--- a/core/tests/behavior/presign.rs
+++ b/core/tests/behavior/presign.rs
@@ -41,7 +41,6 @@ pub fn behavior_presign_tests(op: &Operator) -> Vec<Trial> {
/// Presign write should succeed.
pub async fn test_presign_write(op: Operator) -> Result<()> {
let path = uuid::Uuid::new_v4().to_string();
- debug!("Generate a random file: {}", &path);
let (content, size) = gen_bytes();
let signed_req = op.presign_write(&path, Duration::from_secs(3600)).await?;
@@ -68,12 +67,12 @@ pub async fn test_presign_write(op: Operator) -> Result<()> {
assert_eq!(meta.content_length(), size as u64);
op.delete(&path).await.expect("delete must succeed");
+
Ok(())
}
pub async fn test_presign_stat(op: Operator) -> Result<()> {
let path = uuid::Uuid::new_v4().to_string();
- debug!("Generate a random file: {}", &path);
let (content, size) = gen_bytes();
op.write(&path, content.clone())
.await
@@ -97,13 +96,13 @@ pub async fn test_presign_stat(op: Operator) -> Result<()> {
assert_eq!(content_length, size as u64);
op.delete(&path).await.expect("delete must succeed");
+
Ok(())
}
// Presign read should read content successfully.
pub async fn test_presign_read(op: Operator) -> Result<()> {
let path = uuid::Uuid::new_v4().to_string();
- debug!("Generate a random file: {}", &path);
let (content, size) = gen_bytes();
op.write(&path, content.clone())
@@ -133,5 +132,6 @@ pub async fn test_presign_read(op: Operator) -> Result<()> {
);
op.delete(&path).await.expect("delete must succeed");
+
Ok(())
}
diff --git a/core/tests/behavior/rename.rs b/core/tests/behavior/rename.rs
index d6c64a805..0bade3b57 100644
--- a/core/tests/behavior/rename.rs
+++ b/core/tests/behavior/rename.rs
@@ -57,6 +57,7 @@ pub async fn test_rename_file(op: Operator) -> Result<()> {
op.delete(&source_path).await.expect("delete must succeed");
op.delete(&target_path).await.expect("delete must succeed");
+
Ok(())
}
@@ -70,6 +71,7 @@ pub async fn test_rename_non_existing_source(op: Operator) -> Result<()> {
.await
.expect_err("rename must fail");
assert_eq!(err.kind(), ErrorKind::NotFound);
+
Ok(())
}
@@ -85,6 +87,9 @@ pub async fn test_rename_source_dir(op: Operator) -> Result<()> {
.await
.expect_err("rename must fail");
assert_eq!(err.kind(), ErrorKind::IsADirectory);
+
+ op.delete(&source_path).await.expect("delete must succeed");
+
Ok(())
}
@@ -107,6 +112,7 @@ pub async fn test_rename_target_dir(op: Operator) -> Result<()> {
op.delete(&source_path).await.expect("delete must succeed");
op.delete(&target_path).await.expect("delete must succeed");
+
Ok(())
}
@@ -124,33 +130,31 @@ pub async fn test_rename_self(op: Operator) -> Result<()> {
assert_eq!(err.kind(), ErrorKind::IsSameFile);
op.delete(&source_path).await.expect("delete must succeed");
+
Ok(())
}
/// Rename to a nested path, parent path should be created successfully.
pub async fn test_rename_nested(op: Operator) -> Result<()> {
- let source_path = uuid::Uuid::new_v4().to_string();
+ let dir = &format!("{}/", uuid::Uuid::new_v4());
+
+ let source_path = &format!("{}{}/{}", dir, uuid::Uuid::new_v4(), uuid::Uuid::new_v4());
let (source_content, _) = gen_bytes();
- op.write(&source_path, source_content.clone()).await?;
+ op.write(source_path, source_content.clone()).await?;
- let target_path = format!(
- "{}/{}/{}",
- uuid::Uuid::new_v4(),
- uuid::Uuid::new_v4(),
- uuid::Uuid::new_v4()
- );
+ let target_path = format!("{}/{}/{}", dir, uuid::Uuid::new_v4(), uuid::Uuid::new_v4());
- op.rename(&source_path, &target_path).await?;
+ op.rename(source_path, &target_path).await?;
- let err = op.stat(&source_path).await.expect_err("stat must fail");
+ let err = op.stat(source_path).await.expect_err("stat must fail");
assert_eq!(err.kind(), ErrorKind::NotFound);
let target_content = op.read(&target_path).await.expect("read must succeed");
assert_eq!(target_content, source_content);
- op.delete(&source_path).await.expect("delete must succeed");
- op.delete(&target_path).await.expect("delete must succeed");
+ op.remove_all(dir).await.expect("remove_all must succeed");
+
Ok(())
}
@@ -177,5 +181,6 @@ pub async fn test_rename_overwrite(op: Operator) -> Result<()> {
op.delete(&source_path).await.expect("delete must succeed");
op.delete(&target_path).await.expect("delete must succeed");
+
Ok(())
}
diff --git a/core/tests/behavior/write.rs b/core/tests/behavior/write.rs
index f147d5883..54c85f049 100644
--- a/core/tests/behavior/write.rs
+++ b/core/tests/behavior/write.rs
@@ -26,7 +26,7 @@ use futures::AsyncReadExt;
use futures::AsyncSeekExt;
use futures::StreamExt;
use http::StatusCode;
-use log::debug;
+
use log::warn;
use reqwest::Url;
use sha2::Digest;
@@ -100,6 +100,7 @@ pub async fn test_create_dir(op: Operator) -> Result<()> {
assert_eq!(meta.mode(), EntryMode::DIR);
op.delete(&path).await.expect("delete must succeed");
+
Ok(())
}
@@ -115,6 +116,7 @@ pub async fn test_create_dir_existing(op: Operator) -> Result<()> {
assert_eq!(meta.mode(), EntryMode::DIR);
op.delete(&path).await.expect("delete must succeed");
+
Ok(())
}
@@ -129,6 +131,7 @@ pub async fn test_write_only(op: Operator) -> Result<()> {
assert_eq!(meta.content_length(), size as u64);
op.delete(&path).await.expect("delete must succeed");
+
Ok(())
}
@@ -141,13 +144,15 @@ pub async fn test_write_with_dir_path(op: Operator) -> Result<()> {
assert!(result.is_err());
assert_eq!(result.unwrap_err().kind(), ErrorKind::IsADirectory);
+ op.delete(&path).await.expect("delete must succeed");
+
Ok(())
}
/// Write a single file with special chars should succeed.
pub async fn test_write_with_special_chars(op: Operator) -> Result<()> {
// Ignore test for supabase until https://github.com/apache/incubator-opendal/issues/2194 addressed.
- if op.info().scheme() == opendal::Scheme::Supabase {
+ if op.info().scheme() == Scheme::Supabase {
warn!("ignore test for supabase until https://github.com/apache/incubator-opendal/issues/2194 is resolved");
return Ok(());
}
@@ -161,6 +166,7 @@ pub async fn test_write_with_special_chars(op: Operator) -> Result<()> {
assert_eq!(meta.content_length(), size as u64);
op.delete(&path).await.expect("delete must succeed");
+
Ok(())
}
@@ -256,6 +262,7 @@ pub async fn test_stat_file(op: Operator) -> Result<()> {
assert_eq!(meta.content_length(), size as u64);
op.delete(&path).await.expect("delete must succeed");
+
Ok(())
}
@@ -269,6 +276,7 @@ pub async fn test_stat_dir(op: Operator) -> Result<()> {
assert_eq!(meta.mode(), EntryMode::DIR);
op.delete(&path).await.expect("delete must succeed");
+
Ok(())
}
@@ -290,13 +298,13 @@ pub async fn test_stat_with_special_chars(op: Operator) -> Result<()> {
assert_eq!(meta.content_length(), size as u64);
op.delete(&path).await.expect("delete must succeed");
+
Ok(())
}
/// Stat not cleaned path should also succeed.
pub async fn test_stat_not_cleaned_path(op: Operator) -> Result<()> {
let path = uuid::Uuid::new_v4().to_string();
- debug!("Generate a random file: {}", &path);
let (content, size) = gen_bytes();
op.write(&path, content).await.expect("write must succeed");
@@ -306,6 +314,7 @@ pub async fn test_stat_not_cleaned_path(op: Operator) -> Result<()> {
assert_eq!(meta.content_length(), size as u64);
op.delete(&path).await.expect("delete must succeed");
+
Ok(())
}
@@ -327,7 +336,6 @@ pub async fn test_stat_with_if_match(op: Operator) -> Result<()> {
}
let path = uuid::Uuid::new_v4().to_string();
- debug!("Generate a random file: {}", &path);
let (content, size) = gen_bytes();
op.write(&path, content.clone())
@@ -349,6 +357,7 @@ pub async fn test_stat_with_if_match(op: Operator) -> Result<()> {
assert!(result.is_ok());
op.delete(&path).await.expect("delete must succeed");
+
Ok(())
}
@@ -359,7 +368,6 @@ pub async fn test_stat_with_if_none_match(op: Operator) -> Result<()> {
}
let path = uuid::Uuid::new_v4().to_string();
- debug!("Generate a random file: {}", &path);
let (content, size) = gen_bytes();
op.write(&path, content.clone())
@@ -385,6 +393,7 @@ pub async fn test_stat_with_if_none_match(op: Operator) -> Result<()> {
assert_eq!(res.content_length(), meta.content_length());
op.delete(&path).await.expect("delete must succeed");
+
Ok(())
}
@@ -402,7 +411,6 @@ pub async fn test_stat_root(op: Operator) -> Result<()> {
/// Read full content should match.
pub async fn test_read_full(op: Operator) -> Result<()> {
let path = uuid::Uuid::new_v4().to_string();
- debug!("Generate a random file: {}", &path);
let (content, size) = gen_bytes();
op.write(&path, content.clone())
@@ -418,6 +426,7 @@ pub async fn test_read_full(op: Operator) -> Result<()> {
);
op.delete(&path).await.expect("delete must succeed");
+
Ok(())
}
@@ -428,7 +437,6 @@ pub async fn test_read_range(op: Operator) -> Result<()> {
}
let path = uuid::Uuid::new_v4().to_string();
- debug!("Generate a random file: {}", &path);
let (content, size) = gen_bytes();
let (offset, length) = gen_offset_length(size);
@@ -448,6 +456,7 @@ pub async fn test_read_range(op: Operator) -> Result<()> {
);
op.delete(&path).await.expect("delete must succeed");
+
Ok(())
}
@@ -458,7 +467,6 @@ pub async fn test_read_large_range(op: Operator) -> Result<()> {
}
let path = uuid::Uuid::new_v4().to_string();
- debug!("Generate a random file: {}", &path);
let (content, size) = gen_bytes();
let (offset, _) = gen_offset_length(size);
@@ -479,6 +487,7 @@ pub async fn test_read_large_range(op: Operator) -> Result<()> {
);
op.delete(&path).await.expect("delete must succeed");
+
Ok(())
}
@@ -489,7 +498,6 @@ pub async fn test_reader_range(op: Operator) -> Result<()> {
}
let path = uuid::Uuid::new_v4().to_string();
- debug!("Generate a random file: {}", &path);
let (content, size) = gen_bytes();
let (offset, length) = gen_offset_length(size);
@@ -512,6 +520,7 @@ pub async fn test_reader_range(op: Operator) -> Result<()> {
);
op.delete(&path).await.expect("delete must succeed");
+
Ok(())
}
@@ -522,7 +531,6 @@ pub async fn test_reader_from(op: Operator) -> Result<()> {
}
let path = uuid::Uuid::new_v4().to_string();
- debug!("Generate a random file: {}", &path);
let (content, size) = gen_bytes();
let (offset, _) = gen_offset_length(size);
@@ -543,6 +551,7 @@ pub async fn test_reader_from(op: Operator) -> Result<()> {
);
op.delete(&path).await.expect("delete must succeed");
+
Ok(())
}
@@ -553,7 +562,6 @@ pub async fn test_reader_tail(op: Operator) -> Result<()> {
}
let path = uuid::Uuid::new_v4().to_string();
- debug!("Generate a random file: {}", &path);
let (content, size) = gen_bytes();
let (_, length) = gen_offset_length(size);
@@ -582,6 +590,7 @@ pub async fn test_reader_tail(op: Operator) -> Result<()> {
);
op.delete(&path).await.expect("delete must succeed");
+
Ok(())
}
@@ -603,7 +612,6 @@ pub async fn test_read_with_if_match(op: Operator) -> Result<()> {
}
let path = uuid::Uuid::new_v4().to_string();
- debug!("Generate a random file: {}", &path);
let (content, _) = gen_bytes();
op.write(&path, content.clone())
@@ -624,6 +632,7 @@ pub async fn test_read_with_if_match(op: Operator) -> Result<()> {
assert_eq!(bs, content);
op.delete(&path).await.expect("delete must succeed");
+
Ok(())
}
@@ -634,7 +643,6 @@ pub async fn test_read_with_if_none_match(op: Operator) -> Result<()> {
}
let path = uuid::Uuid::new_v4().to_string();
- debug!("Generate a random file: {}", &path);
let (content, _) = gen_bytes();
op.write(&path, content.clone())
@@ -658,6 +666,7 @@ pub async fn test_read_with_if_none_match(op: Operator) -> Result<()> {
assert_eq!(bs, content);
op.delete(&path).await.expect("delete must succeed");
+
Ok(())
}
@@ -667,7 +676,6 @@ pub async fn test_fuzz_range_reader(op: Operator) -> Result<()> {
}
let path = uuid::Uuid::new_v4().to_string();
- debug!("Generate a random file: {}", &path);
let (content, _) = gen_bytes();
op.write(&path, content.clone())
@@ -699,6 +707,7 @@ pub async fn test_fuzz_range_reader(op: Operator) -> Result<()> {
}
op.delete(&path).await.expect("delete must succeed");
+
Ok(())
}
@@ -708,7 +717,6 @@ pub async fn test_fuzz_offset_reader(op: Operator) -> Result<()> {
}
let path = uuid::Uuid::new_v4().to_string();
- debug!("Generate a random file: {}", &path);
let (content, _) = gen_bytes();
op.write(&path, content.clone())
@@ -740,6 +748,7 @@ pub async fn test_fuzz_offset_reader(op: Operator) -> Result<()> {
}
op.delete(&path).await.expect("delete must succeed");
+
Ok(())
}
@@ -749,7 +758,6 @@ pub async fn test_fuzz_part_reader(op: Operator) -> Result<()> {
}
let path = uuid::Uuid::new_v4().to_string();
- debug!("Generate a random file: {}", &path);
let (content, size) = gen_bytes();
let (offset, length) = gen_offset_length(size);
@@ -783,6 +791,7 @@ pub async fn test_fuzz_part_reader(op: Operator) -> Result<()> {
}
op.delete(&path).await.expect("delete must succeed");
+
Ok(())
}
@@ -797,6 +806,7 @@ pub async fn test_read_with_dir_path(op: Operator) -> Result<()> {
assert_eq!(result.unwrap_err().kind(), ErrorKind::IsADirectory);
op.delete(&path).await.expect("delete must succeed");
+
Ok(())
}
@@ -809,7 +819,6 @@ pub async fn test_read_with_special_chars(op: Operator) -> Result<()> {
}
let path = format!("{} !@#$%^&()_+-=;',.txt", uuid::Uuid::new_v4());
- debug!("Generate a random file: {}", &path);
let (content, size) = gen_bytes();
op.write(&path, content.clone())
@@ -825,6 +834,7 @@ pub async fn test_read_with_special_chars(op: Operator) -> Result<()> {
);
op.delete(&path).await.expect("delete must succeed");
+
Ok(())
}
@@ -870,6 +880,7 @@ pub async fn test_read_with_override_cache_control(op: Operator) -> Result<()> {
);
op.delete(&path).await.expect("delete must succeed");
+
Ok(())
}
@@ -926,7 +937,7 @@ pub async fn test_read_with_override_content_disposition(op: Operator) -> Result
Ok(())
}
-/// Delete existing file should succeed.
+/// Abort writer should not write actual file.
pub async fn test_writer_abort(op: Operator) -> Result<()> {
let path = uuid::Uuid::new_v4().to_string();
let (content, _) = gen_bytes();
@@ -989,7 +1000,6 @@ pub async fn test_delete_with_special_chars(op: Operator) -> Result<()> {
}
let path = format!("{} !@#$%^&()_+-=;',.txt", uuid::Uuid::new_v4());
- debug!("Generate a random file: {}", &path);
let (content, _) = gen_bytes();
op.write(&path, content).await.expect("write must succeed");
@@ -1050,6 +1060,8 @@ pub async fn test_delete_stream(op: Operator) -> Result<()> {
)
}
+ op.delete(&format!("{dir}/")).await?;
+
Ok(())
}
@@ -1089,6 +1101,7 @@ pub async fn test_writer_write(op: Operator) -> Result<()> {
);
op.delete(&path).await.expect("delete must succeed");
+
Ok(())
}
@@ -1129,6 +1142,7 @@ pub async fn test_writer_sink(op: Operator) -> Result<()> {
);
op.delete(&path).await.expect("delete must succeed");
+
Ok(())
}
@@ -1169,6 +1183,7 @@ pub async fn test_writer_copy(op: Operator) -> Result<()> {
);
op.delete(&path).await.expect("delete must succeed");
+
Ok(())
}
@@ -1204,6 +1219,7 @@ pub async fn test_writer_futures_copy(op: Operator) -> Result<()> {
);
op.delete(&path).await.expect("delete must succeed");
+
Ok(())
}
@@ -1231,5 +1247,6 @@ pub async fn test_fuzz_unsized_writer(op: Operator) -> Result<()> {
fuzzer.check(&content);
op.delete(&path).await.expect("delete must succeed");
+
Ok(())
}