This is an automated email from the ASF dual-hosted git repository.

xuanwo pushed a commit to branch list-prefix
in repository https://gitbox.apache.org/repos/asf/incubator-opendal.git

commit 21ded41fde672a36556f79033f0c883ac16354d7
Author: Xuanwo <[email protected]>
AuthorDate: Thu Dec 7 13:40:01 2023 +0800

    Cover more test
    
    Signed-off-by: Xuanwo <[email protected]>
---
 core/tests/behavior/list.rs | 31 ++++++++++++++++++++++++++++---
 1 file changed, 28 insertions(+), 3 deletions(-)

diff --git a/core/tests/behavior/list.rs b/core/tests/behavior/list.rs
index 5c8007d47..b3f8f5069 100644
--- a/core/tests/behavior/list.rs
+++ b/core/tests/behavior/list.rs
@@ -39,6 +39,7 @@ pub fn behavior_list_tests(op: &Operator) -> Vec<Trial> {
         test_list_dir,
         test_list_dir_with_metakey,
         test_list_dir_with_metakey_complete,
+        test_list_prefix,
         test_list_rich_dir,
         test_list_empty_dir,
         test_list_non_exist_dir,
@@ -175,6 +176,23 @@ pub async fn test_list_dir_with_metakey_complete(op: 
Operator) -> Result<()> {
     Ok(())
 }
 
+/// List prefix should return newly created file.
+pub async fn test_list_prefix(op: Operator) -> Result<()> {
+    let path = uuid::Uuid::new_v4().to_string();
+    debug!("Generate a random file: {}", &path);
+    let (content, _) = gen_bytes(op.info().full_capability());
+
+    op.write(&path, content).await.expect("write must succeed");
+
+    let obs = op.list(&path[..path.len() - 1]).await?;
+    assert_eq!(obs.len(), 1);
+    assert_eq!(obs[0].path(), path);
+    assert_eq!(obs[0].metadata().mode(), EntryMode::FILE);
+
+    op.delete(&path).await.expect("delete must succeed");
+    Ok(())
+}
+
 /// listing a directory, which contains more objects than a single page can 
take.
 pub async fn test_list_rich_dir(op: Operator) -> Result<()> {
     op.create_dir("test_list_rich_dir/").await?;
@@ -316,10 +334,17 @@ pub async fn test_list_nested_dir(op: Operator) -> 
Result<()> {
 /// List with path file should auto add / suffix.
 pub async fn test_list_dir_with_file_path(op: Operator) -> Result<()> {
     let parent = uuid::Uuid::new_v4().to_string();
+    let file = format!("{parent}/{}", uuid::Uuid::new_v4());
+
+    let (content, _) = gen_bytes(op.info().full_capability());
+    op.write(&file, content).await?;
+
+    let obs = op.list(&parent).await?;
+    assert_eq!(obs.len(), 1);
+    assert_eq!(obs[0].path(), format!("{parent}/"));
+    assert_eq!(obs[0].metadata().mode(), EntryMode::DIR);
 
-    let obs = op.lister(&parent).await.map(|_| ());
-    assert!(obs.is_err());
-    assert_eq!(obs.unwrap_err().kind(), ErrorKind::NotADirectory);
+    op.delete(&file).await?;
 
     Ok(())
 }

Reply via email to