Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a test for remove_all_files() #538

Merged
merged 1 commit into from
Oct 15, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion network/src/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,30 @@ mod tests {

#[tokio::test]
async fn remove_all_files() {
// TODO: test whether `remove_all_files()` actually removes all the file.
let dir = gerenate_random_storage_directory();
StorageImpl::create(&dir).await.unwrap();
let mut storage = StorageImpl::open(&dir).await.unwrap();

let names = (0..10)
.map(|_| generate_random_string())
.collect::<Vec<_>>();

for name in names.iter() {
let content = generate_random_string();
storage
.add_or_overwrite_file(name, content.clone())
.await
.unwrap();
assert_eq!(storage.read_file(name).await.unwrap(), content);
}

let _ = storage.remove_all_files().await;

for name in names.iter() {
let path = std::path::Path::new(&dir).join(name);
assert!(!path.exists());
assert!(storage.read_file(name).await.is_err());
}
}

#[tokio::test]
Expand Down
Loading