summaryrefslogtreecommitdiffstats
path: root/tokio/tests/fs_dir.rs
diff options
context:
space:
mode:
authorDmitri Shkurski <45545354+shkurski@users.noreply.github.com>2020-05-21 13:49:36 +0300
committerGitHub <noreply@github.com>2020-05-21 12:49:36 +0200
commit8fda5f1984e5c56548ea5bb0cf7d0f5c57c3a190 (patch)
tree334caa3afa736147218a55216c609b9305cf4adf /tokio/tests/fs_dir.rs
parent7cb5e3460c67bdfbe29fb6abf02e2d3cfc13625e (diff)
fs: add DirBuilder (#2524)
The initial idea was to implement a thin wrapper around an internally held `std::fs::DirBuilder` instance. This, however, didn't work due to `std::fs::DirBuilder` not having a Copy/Clone traits implemented, which are necessary for constructing an instance to move-capture it into a closure. Instead, we mirror `std::fs::DirBuilder` configuration by storing the `recursive` and (unix-only) `mode` parameters locally, which are then used to construct an `std::fs::DirBuilder` instance on-the-fly. This commit also mirrors the (unix-only) DirBuilderExt trait from std. Fixes: #2369
Diffstat (limited to 'tokio/tests/fs_dir.rs')
-rw-r--r--tokio/tests/fs_dir.rs19
1 files changed, 18 insertions, 1 deletions
diff --git a/tokio/tests/fs_dir.rs b/tokio/tests/fs_dir.rs
index eaff59da..6355ef05 100644
--- a/tokio/tests/fs_dir.rs
+++ b/tokio/tests/fs_dir.rs
@@ -2,7 +2,7 @@
#![cfg(feature = "full")]
use tokio::fs;
-use tokio_test::assert_ok;
+use tokio_test::{assert_err, assert_ok};
use std::sync::{Arc, Mutex};
use tempfile::tempdir;
@@ -29,6 +29,23 @@ async fn create_all() {
}
#[tokio::test]
+async fn build_dir() {
+ let base_dir = tempdir().unwrap();
+ let new_dir = base_dir.path().join("foo").join("bar");
+ let new_dir_2 = new_dir.clone();
+
+ assert_ok!(fs::DirBuilder::new().recursive(true).create(new_dir).await);
+
+ assert!(new_dir_2.is_dir());
+ assert_err!(
+ fs::DirBuilder::new()
+ .recursive(false)
+ .create(new_dir_2)
+ .await
+ );
+}
+
+#[tokio::test]
async fn remove() {
let base_dir = tempdir().unwrap();
let new_dir = base_dir.path().join("foo");