This is an automated email from the ASF dual-hosted git repository. xuanwo pushed a commit to branch add-list-with-metakey-test in repository https://gitbox.apache.org/repos/asf/incubator-opendal.git
commit 2afaae7f24ae7f0ac846064be35d8dee613ca226 Author: Xuanwo <[email protected]> AuthorDate: Mon Sep 18 19:21:10 2023 +0800 Add test Signed-off-by: Xuanwo <[email protected]> --- core/tests/behavior/blocking_list.rs | 91 ++++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) diff --git a/core/tests/behavior/blocking_list.rs b/core/tests/behavior/blocking_list.rs index dff03bc0b..c58e4feea 100644 --- a/core/tests/behavior/blocking_list.rs +++ b/core/tests/behavior/blocking_list.rs @@ -33,6 +33,8 @@ pub fn behavior_blocking_list_tests(op: &Operator) -> Vec<Trial> { blocking_trials!( op, test_blocking_list_dir, + test_blocking_list_dir_with_metakey, + test_blocking_list_dir_with_metakey_complete, test_blocking_list_non_exist_dir, test_blocking_scan, test_blocking_remove_all @@ -67,6 +69,95 @@ pub fn test_blocking_list_dir(op: BlockingOperator) -> Result<()> { Ok(()) } +/// List dir with metakey +pub fn test_blocking_list_dir_with_metakey(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"); + + let mut obs = op + .lister_with(&format!("{parent}/")) + .metakey( + Metakey::Mode + | Metakey::CacheControl + | Metakey::ContentDisposition + | Metakey::ContentLength + | Metakey::ContentMd5 + | Metakey::ContentRange + | Metakey::ContentType + | Metakey::Etag + | Metakey::LastModified + | Metakey::Version, + ) + .call()?; + let mut found = false; + while let Some(de) = obs.next().transpose()? { + let meta = de.metadata(); + if de.path() == path { + assert_eq!(meta.mode(), EntryMode::FILE); + assert_eq!(meta.content_length(), size as u64); + + // We don't care about the value, we just to check there is no panic. + let _ = meta.cache_control(); + let _ = meta.content_disposition(); + let _ = meta.content_md5(); + let _ = meta.content_range(); + let _ = meta.content_type(); + let _ = meta.etag(); + let _ = meta.last_modified(); + let _ = meta.version(); + + found = true + } + } + assert!(found, "file should be found in list"); + + op.delete(&path).expect("delete must succeed"); + Ok(()) +} + +/// List dir with metakey complete +pub fn test_blocking_list_dir_with_metakey_complete(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"); + + let mut obs = op + .lister_with(&format!("{parent}/")) + .metakey(Metakey::Complete) + .call()?; + let mut found = false; + while let Some(de) = obs.next().transpose()? { + let meta = de.metadata(); + if de.path() == path { + assert_eq!(meta.mode(), EntryMode::FILE); + assert_eq!(meta.content_length(), size as u64); + + // We don't care about the value, we just to check there is no panic. + let _ = meta.cache_control(); + let _ = meta.content_disposition(); + let _ = meta.content_md5(); + let _ = meta.content_range(); + let _ = meta.content_type(); + let _ = meta.etag(); + let _ = meta.last_modified(); + let _ = meta.version(); + + found = true + } + } + assert!(found, "file should be found in list"); + + op.delete(&path).expect("delete must succeed"); + Ok(()) +} + /// List non exist dir should return nothing. pub fn test_blocking_list_non_exist_dir(op: BlockingOperator) -> Result<()> { let dir = format!("{}/", uuid::Uuid::new_v4());
