Skip to content

Commit

Permalink
refactor: Re-organize the layout of tests (#3904)
Browse files Browse the repository at this point in the history
* Refactor tests

Signed-off-by: Xuanwo <[email protected]>

* refactor: Re-organize the layout of tests

Signed-off-by: Xuanwo <[email protected]>

---------

Signed-off-by: Xuanwo <[email protected]>
  • Loading branch information
Xuanwo committed Jan 3, 2024
1 parent 7f30232 commit 62e79ca
Show file tree
Hide file tree
Showing 25 changed files with 2,614 additions and 3,586 deletions.
223 changes: 0 additions & 223 deletions core/tests/behavior/append.rs

This file was deleted.

28 changes: 13 additions & 15 deletions core/tests/behavior/copy.rs → core/tests/behavior/async_copy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,22 @@ use sha2::Sha256;

use crate::*;

pub fn behavior_copy_tests(op: &Operator) -> Vec<Trial> {
pub fn tests(op: &Operator, tests: &mut Vec<Trial>) {
let cap = op.info().full_capability();

if !(cap.read && cap.write && cap.copy) {
return vec![];
if cap.read && cap.write && cap.copy {
tests.extend(async_trials!(
op,
test_copy_file_with_ascii_name,
test_copy_file_with_non_ascii_name,
test_copy_non_existing_source,
test_copy_source_dir,
test_copy_target_dir,
test_copy_self,
test_copy_nested,
test_copy_overwrite
))
}

async_trials!(
op,
test_copy_file_with_ascii_name,
test_copy_file_with_non_ascii_name,
test_copy_non_existing_source,
test_copy_source_dir,
test_copy_target_dir,
test_copy_self,
test_copy_nested,
test_copy_overwrite
)
}

/// Copy a file with ascii name and test contents.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,40 +15,39 @@
// specific language governing permissions and limitations
// under the License.

use std::collections::HashMap;

use anyhow::Result;
use futures::TryStreamExt;

use crate::*;

pub fn behavior_list_only_tests(op: &Operator) -> Vec<Trial> {
pub fn tests(op: &Operator, tests: &mut Vec<Trial>) {
let cap = op.info().full_capability();

if !cap.list || cap.write {
return vec![];
if cap.create_dir && cap.stat {
tests.extend(async_trials!(op, test_create_dir, test_create_dir_existing))
}
}

/// Create dir with dir path should succeed.
pub async fn test_create_dir(op: Operator) -> Result<()> {
let path = TEST_FIXTURE.new_dir_path();

async_trials!(op, test_list_only)
op.create_dir(&path).await?;

let meta = op.stat(&path).await?;
assert_eq!(meta.mode(), EntryMode::DIR);
Ok(())
}

/// Stat normal file and dir should return metadata
pub async fn test_list_only(op: Operator) -> Result<()> {
let mut entries = HashMap::new();
/// Create dir on existing dir should succeed.
pub async fn test_create_dir_existing(op: Operator) -> Result<()> {
let path = TEST_FIXTURE.new_dir_path();

let mut ds = op.lister("/").await?;
while let Some(de) = ds.try_next().await? {
entries.insert(de.path().to_string(), op.stat(de.path()).await?.mode());
}
op.create_dir(&path).await?;

assert_eq!(entries["normal_file.txt"], EntryMode::FILE);
assert_eq!(
entries["special_file !@#$%^&()_+-=;',.txt"],
EntryMode::FILE
);
op.create_dir(&path).await?;

assert_eq!(entries["normal_dir/"], EntryMode::DIR);
assert_eq!(entries["special_dir !@#$%^&()_+-=;',/"], EntryMode::DIR);
let meta = op.stat(&path).await?;
assert_eq!(meta.mode(), EntryMode::DIR);

Ok(())
}
Loading

0 comments on commit 62e79ca

Please sign in to comment.