summaryrefslogtreecommitdiff
path: root/server/common/src/tests.rs
diff options
context:
space:
mode:
Diffstat (limited to 'server/common/src/tests.rs')
-rw-r--r--server/common/src/tests.rs45
1 files changed, 45 insertions, 0 deletions
diff --git a/server/common/src/tests.rs b/server/common/src/tests.rs
new file mode 100644
index 0000000..540ee2d
--- /dev/null
+++ b/server/common/src/tests.rs
@@ -0,0 +1,45 @@
+use tokio::fs;
+use testdir::testdir;
+
+use crate::fs_utils;
+
+#[tokio::test]
+async fn test_fs_utils_create_dir_allow_existing() {
+ let dir = testdir!();
+ let foo = dir.join("foo");
+ assert!(fs_utils::create_dir_allow_existing(&foo).await.is_ok());
+ assert!(fs::try_exists(&foo).await.unwrap());
+ assert!(fs_utils::create_dir_allow_existing(&foo).await.is_ok());
+}
+
+#[tokio::test]
+async fn test_fs_utils_create_dir_allow_existing_file() {
+ let dir = testdir!();
+ let foo = dir.join("foo");
+ assert!(fs::write(&foo, "hello").await.is_ok());
+ assert!(fs_utils::create_dir_allow_existing(&foo).await.is_err());
+}
+
+#[tokio::test]
+async fn test_fs_utils_remove_file_allow_not_found() {
+ let dir = testdir!();
+ let foo = dir.join("foo");
+ assert!(fs_utils::remove_file_allow_not_found(&foo).await.is_ok());
+ assert!(fs::write(&foo, "hello").await.is_ok());
+ assert!(fs_utils::remove_file_allow_not_found(&foo).await.is_ok());
+ assert!(!fs::try_exists(&foo).await.unwrap());
+}
+
+#[tokio::test]
+async fn test_fs_utils_symlink_update_existing() {
+ let dir = testdir!();
+ let foo = dir.join("foo");
+ let bar = dir.join("bar");
+ let fum = dir.join("fum");
+ assert!(fs::write(&foo, "hello").await.is_ok());
+ assert!(fs_utils::symlink_update_existing(&foo, &bar).await.is_ok());
+ assert!(fs_utils::symlink_update_existing(&foo, &bar).await.is_ok());
+ assert_eq!(fs::read_link(&bar).await.unwrap(), foo);
+ assert!(fs_utils::symlink_update_existing(&fum, &bar).await.is_ok());
+ assert_eq!(fs::read_link(&bar).await.unwrap(), fum);
+}