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.rs64
1 files changed, 64 insertions, 0 deletions
diff --git a/src/remote/mod.rs b/src/remote/mod.rs
index 9782b0d..1a2421d 100644
--- a/src/remote/mod.rs
+++ b/src/remote/mod.rs
@@ -70,6 +70,7 @@ fn read_remote(file_path: &Path) -> Option<String> {
#[cfg(test)]
mod tests {
+ use std::fs::create_dir_all;
use super::*;
@@ -102,4 +103,67 @@ mod tests {
cleanup_test_dir(&test_dir);
}
+
+ #[test]
+ fn test_syncs_remote_up() {
+ let test_dir = setup_test_dir();
+ let local_dir = test_dir.join("modlocal");
+ let remote_dir = test_dir.join("modremote");
+ create_dir_all(&local_dir).expect("Could not create local test directory");
+ 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);
+
+ create_test_file(&local_dir.join("file1.txt"), "I exist");
+ sync_up(&local_dir, &test_dir.join("remoteconfig")).expect("Could not sync up to remote");
+ assert_file_in_repo_with_contents(&remote_dir_as_string, "file1.txt", "I exist");
+ assert_file_in_repo_does_not_exist(&remote_dir_as_string, "file2.txt");
+
+ create_test_file(&local_dir.join("file2.txt"), "I also exist now, btw");
+ sync_up(&local_dir, &test_dir.join("remoteconfig")).expect("Could not sync up to remote");
+ assert_file_in_repo_with_contents(&remote_dir_as_string, "file1.txt", "I exist");
+ assert_file_in_repo_with_contents(
+ &remote_dir_as_string,
+ "file2.txt",
+ "I also exist now, btw",
+ );
+ cleanup_test_dir(&test_dir);
+ }
+
+ #[test]
+ fn test_syncs_remote_down() {
+ let test_dir = setup_test_dir();
+ let local_dir = test_dir.join("modownlocal");
+ let remote_dir = test_dir.join("modownremote");
+ create_dir_all(&local_dir).expect("Could not create local test directory");
+ 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, "file 1.txt", "I exist, but remotely");
+ assert!(!&local_dir.join("file 1.txt").exists());
+ assert!(!&local_dir.join("file2.txt").exists());
+ sync_down(&local_dir, &test_dir.join("remoteconfig"))
+ .expect("Could not sync down from remote");
+ assert_file_contents(&local_dir.join("file 1.txt"), "I exist, but remotely");
+ assert!(!&local_dir.join("file2.txt").exists());
+
+ commit_file_to_remote(
+ &remote_dir_as_string,
+ "file2.txt",
+ "I also exist, but remotely",
+ );
+ assert!(!&local_dir.join("file2.txt").exists());
+ sync_down(&local_dir, &test_dir.join("remoteconfig"))
+ .expect("Could not sync down from remote");
+ assert_file_contents(&local_dir.join("file 1.txt"), "I exist, but remotely");
+ assert_file_contents(&local_dir.join("file2.txt"), "I also exist, but remotely");
+ cleanup_test_dir(&test_dir);
+ }
}