aboutsummaryrefslogtreecommitdiff
path: root/src/remote/mod.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/remote/mod.rs')
-rw-r--r--src/remote/mod.rs109
1 files changed, 109 insertions, 0 deletions
diff --git a/src/remote/mod.rs b/src/remote/mod.rs
index 1a2421d..74f4c48 100644
--- a/src/remote/mod.rs
+++ b/src/remote/mod.rs
@@ -71,6 +71,8 @@ fn read_remote(file_path: &Path) -> Option<String> {
#[cfg(test)]
mod tests {
use std::fs::create_dir_all;
+ use std::io::Write;
+ use std::path::PathBuf;
use super::*;
@@ -134,6 +136,51 @@ mod tests {
}
#[test]
+ fn test_syncs_remote_up_even_if_directory_does_not_exist() {
+ let test_dir = setup_test_dir();
+ let local_dir = test_dir.join("modlocal");
+ let remote_dir = test_dir.join("modremote");
+ create_dir_all(&remote_dir).expect("Could not create remote test directory");
+
+ create_remote(&remote_dir);
+
+ let remote_dir_as_string = remote_dir.display().to_string();
+ create_test_file(&test_dir.join("remoteconfig"), &remote_dir_as_string);
+
+ sync_up(&local_dir, &test_dir.join("remoteconfig")).expect("Could not sync up to remote");
+ assert!(local_dir.exists());
+ cleanup_test_dir(&test_dir);
+ }
+
+ #[test]
+ fn test_sync_up_down_fails_if_local_not_creatable() {
+ let test_dir = setup_test_dir();
+ let local_dir = &PathBuf::from("/lasjkdlaksjdklasjdlaks/asldkj/asjdlaksdj");
+ let remote_dir = test_dir.join("modremote");
+ create_dir_all(&remote_dir).expect("Could not create remote test directory");
+
+ create_remote(&remote_dir);
+
+ let remote_dir_as_string = remote_dir.display().to_string();
+ create_test_file(&test_dir.join("remoteconfig"), &remote_dir_as_string);
+
+ let result = sync_up(&local_dir, &test_dir.join("remoteconfig"));
+ assert!(result.is_err());
+ cleanup_test_dir(&test_dir);
+ }
+
+ #[test]
+ fn test_sync_up_fails_on_invalid_strategies() {
+ let test_dir = setup_test_dir();
+ let local_dir = test_dir.join("modlocal");
+ create_test_file(&test_dir.join("remoteconfig"), "AAAAAH");
+
+ let result = sync_up(&local_dir, &test_dir.join("remoteconfig"));
+ assert!(result.is_err());
+ cleanup_test_dir(&test_dir);
+ }
+
+ #[test]
fn test_syncs_remote_down() {
let test_dir = setup_test_dir();
let local_dir = test_dir.join("modownlocal");
@@ -166,4 +213,66 @@ mod tests {
assert_file_contents(&local_dir.join("file2.txt"), "I also exist, but remotely");
cleanup_test_dir(&test_dir);
}
+
+ #[test]
+ fn test_syncs_remote_down_even_if_directory_does_not_exist() {
+ let test_dir = setup_test_dir();
+ let local_dir = test_dir.join("modlocal");
+ let remote_dir = test_dir.join("modremote");
+ create_dir_all(&remote_dir).expect("Could not create remote test directory");
+
+ create_remote(&remote_dir);
+
+ let remote_dir_as_string = remote_dir.display().to_string();
+ create_test_file(&test_dir.join("remoteconfig"), &remote_dir_as_string);
+
+ commit_file_to_remote(&remote_dir_as_string, "onions", "Make me cry");
+
+ sync_down(&local_dir, &test_dir.join("remoteconfig")).expect("Could not sync up to remote");
+ assert_file_contents(&local_dir.join("onions"), "Make me cry");
+ cleanup_test_dir(&test_dir);
+ }
+
+ #[test]
+ fn test_sync_down_fails_if_local_not_creatable() {
+ let test_dir = setup_test_dir();
+ let local_dir = &PathBuf::from("/lasjkdlaksjdklasjdlaks/asldkj/asjdlaksdj");
+ let remote_dir = test_dir.join("modremote");
+ create_dir_all(&remote_dir).expect("Could not create remote test directory");
+
+ create_remote(&remote_dir);
+
+ let remote_dir_as_string = remote_dir.display().to_string();
+ create_test_file(&test_dir.join("remoteconfig"), &remote_dir_as_string);
+
+ let result = sync_down(&local_dir, &test_dir.join("remoteconfig"));
+ assert!(result.is_err());
+ cleanup_test_dir(&test_dir);
+ }
+
+ #[test]
+ fn test_sync_down_fails_on_invalid_strategies() {
+ let test_dir = setup_test_dir();
+ let local_dir = test_dir.join("modlocal");
+ create_test_file(&test_dir.join("remoteconfig"), "AAAAAH");
+
+ let result = sync_down(&local_dir, &test_dir.join("remoteconfig"));
+ assert!(result.is_err());
+ cleanup_test_dir(&test_dir);
+ }
+
+ #[test]
+ fn test_it_should_fail_if_remote_is_invalid() {
+ let test_dir = setup_test_dir();
+ let bad_file_path = &test_dir.join("BADFILE OH NO");
+ let invalid_bytes = vec![0xFF, 0xFF];
+
+ let mut bad_file = File::create(&bad_file_path).expect("Could not create bad file.");
+ bad_file
+ .write_all(&invalid_bytes)
+ .expect("Could not write bad bytes to bad file.");
+
+ assert_eq!(read_remote(&bad_file_path), None);
+ cleanup_test_dir(&test_dir);
+ }
}