aboutsummaryrefslogtreecommitdiff
path: root/src/remote/mod.rs
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/mod.rs
parent98d323f5e86df5eab2218ae879da68ae3cb5230a (diff)
Cleanup test directories
Diffstat (limited to 'src/remote/mod.rs')
-rw-r--r--src/remote/mod.rs42
1 files changed, 41 insertions, 1 deletions
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);
+ }
+}