Skip to content

Commit

Permalink
Add a test for remove_all_files()
Browse files Browse the repository at this point in the history
  • Loading branch information
ghkdxofla committed Oct 15, 2023
1 parent 8b4d036 commit fb20fd2
Showing 1 changed file with 24 additions and 1 deletion.
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

0 comments on commit fb20fd2

Please sign in to comment.