summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorTom Barrett <spalf0@gmail.com>2019-08-15 10:19:59 -0500
committerTom Barrett <spalf0@gmail.com>2019-08-15 10:19:59 -0500
commit46b6a160c71473177bcd607103fae35e3468d463 (patch)
tree3f991595182c21db14fc36cd3e7891672c9fd83d /tests
parent81bbfcb77ef9fe029897878ebd733017066c80e1 (diff)
wrote basic test, now passing io errors via ?
Diffstat (limited to 'tests')
-rw-r--r--tests/tests.rs49
1 files changed, 49 insertions, 0 deletions
diff --git a/tests/tests.rs b/tests/tests.rs
new file mode 100644
index 0000000..efdb909
--- /dev/null
+++ b/tests/tests.rs
@@ -0,0 +1,49 @@
+extern crate rsycle;
+
+#[cfg(test)]
+mod tests {
+ use rsycle::main::{build_path, empty, list, restore, rsycle};
+ use std::fs;
+ use std::path::{Component, PathBuf};
+
+ fn get_rsyclebin() -> PathBuf {
+ let mut rsyclebin = dirs::home_dir().unwrap();
+ rsyclebin.push(".test_rsyclebin");
+ if !rsyclebin.exists() {
+ fs::create_dir(&rsyclebin).unwrap();
+ }
+ rsyclebin
+ }
+
+ #[test]
+ fn test_rsycle() {
+ let rsyclebin = get_rsyclebin();
+
+ let filename = "test_file".as_ref();
+
+ let mut test_path: PathBuf = [Component::CurDir, Component::Normal(filename)]
+ .iter()
+ .collect();
+
+ assert!(!test_path.exists());
+
+ fs::File::create(test_path.clone()).unwrap();
+
+ test_path = build_path(filename.to_str().unwrap()).unwrap();
+
+ assert!(rsycle(rsyclebin.clone(), test_path.clone()).is_ok());
+
+ assert!(!test_path.exists());
+
+ assert!(list(rsyclebin.clone()).is_ok());
+
+ assert!(restore(rsyclebin.clone(), test_path.clone()).is_ok());
+
+ assert!(test_path.exists());
+
+ assert!(empty(rsyclebin.clone()).is_ok());
+
+ fs::remove_file(test_path).unwrap();
+ fs::remove_dir_all(rsyclebin).unwrap();
+ }
+}