From df98735f6653e281802ef7ca5f23c10db0881c99 Mon Sep 17 00:00:00 2001 From: ghkdxofla Date: Sun, 15 Oct 2023 15:52:17 +0900 Subject: [PATCH] Add a test for `remove_all_files()` --- network/src/storage.rs | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/network/src/storage.rs b/network/src/storage.rs index 52a5328c..67539042 100644 --- a/network/src/storage.rs +++ b/network/src/storage.rs @@ -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::>(); + + 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]