aboutsummaryrefslogtreecommitdiff
path: root/src/remote
diff options
context:
space:
mode:
authorRuben Beltran del Rio <git@r.bdr.sh>2025-01-09 18:23:20 +0100
committerRuben Beltran del Rio <git@r.bdr.sh>2025-01-09 18:23:20 +0100
commit67a5f942d573b94ce9b20d19088be075ad433d78 (patch)
treef15613c0ccaa1d48b5091c375980991f1891cdeb /src/remote
parent98d323f5e86df5eab2218ae879da68ae3cb5230a (diff)
Cleanup test directories
Diffstat (limited to 'src/remote')
-rw-r--r--src/remote/git.rs6
-rw-r--r--src/remote/mod.rs42
2 files changed, 47 insertions, 1 deletions
diff --git a/src/remote/git.rs b/src/remote/git.rs
index c260df8..f74af42 100644
--- a/src/remote/git.rs
+++ b/src/remote/git.rs
@@ -175,6 +175,7 @@ mod tests {
"file2.txt",
"I also exist now, btw",
);
+ cleanup_test_dir(&test_dir);
}
#[test]
@@ -200,6 +201,7 @@ mod tests {
assert_file_in_repo_with_contents(&remote_dir_as_string, "file1.txt", "I exist");
assert_file_does_not_exist(&remote_dir_as_string, "boo.txt");
+ cleanup_test_dir(&test_dir);
}
#[test]
@@ -214,6 +216,7 @@ mod tests {
let result = git.sync_up(&invalid_remote, &local_dir);
assert!(result.is_err());
+ cleanup_test_dir(&test_dir);
}
#[test]
@@ -247,6 +250,7 @@ mod tests {
.expect("Could not sync down from remote");
assert_file_contents(&local_dir.join("file1.txt"), "I exist, but remotely");
assert_file_contents(&local_dir.join("file2.txt"), "I also exist, but remotely");
+ cleanup_test_dir(&test_dir);
}
#[test]
@@ -270,6 +274,7 @@ mod tests {
.expect("Could not sync down from remote");
assert_file_contents(&local_dir.join("file1.txt"), "I exist, but remotely");
assert!(!&local_dir.join("nooo.txt").exists());
+ cleanup_test_dir(&test_dir);
}
#[test]
@@ -284,5 +289,6 @@ mod tests {
let result = git.sync_down(&invalid_remote, &local_dir);
assert!(result.is_err());
+ cleanup_test_dir(&test_dir);
}
}
diff --git a/src/remote/mod.rs b/src/remote/mod.rs
index 6561936..c8561ff 100644
--- a/src/remote/mod.rs
+++ b/src/remote/mod.rs
@@ -12,7 +12,7 @@ pub trait Remote {
fn sync_down(&self, remote: &str, directory: &Path) -> Result<()>;
}
-pub fn add(config_directory: &Path, remote_config: &Path, remote: &String) -> Result<()> {
+pub fn add(config_directory: &Path, remote_config: &Path, remote: &str) -> Result<()> {
create_dir_all(config_directory)?;
write(remote_config, remote)?;
Ok(())
@@ -67,3 +67,43 @@ fn read_remote(file_path: &Path) -> Option<String> {
file.read_to_string(&mut contents).ok()?;
Some(contents)
}
+
+#[cfg(test)]
+mod tests {
+ use std::fs::create_dir_all;
+ use std::path::Path;
+ use std::process::{Command, Stdio};
+
+ use super::*;
+ use crate::remote::Remote;
+
+ use test_utilities::*;
+
+ #[test]
+ fn test_adds_a_remote() {
+ let test_dir = setup_test_dir();
+ let config_dir = test_dir.join("config");
+ let remote_config = config_dir.join("remoteconfig");
+
+ assert!(!&config_dir.exists());
+ add(&config_dir, &remote_config, "whaaat").expect("Could not add a remote");
+ assert!(&config_dir.exists());
+ assert_file_contents(&remote_config, "whaaat");
+
+ cleanup_test_dir(&test_dir);
+ }
+
+ #[test]
+ fn test_removes_a_remote() {
+ let test_dir = setup_test_dir();
+ let remote_config = test_dir.join("remoteconfig");
+
+ create_test_file(&remote_config, "remote control");
+
+ assert_file_contents(&remote_config, "remote control");
+ remove(&remote_config).expect("Could not remove a remote");
+ assert!(!&remote_config.exists());
+
+ cleanup_test_dir(&test_dir);
+ }
+}