diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/archiver/gemini.rs | 3 | ||||
| -rw-r--r-- | src/archiver/gopher.rs | 3 | ||||
| -rw-r--r-- | src/archiver/mod.rs | 1 | ||||
| -rw-r--r-- | src/archiver/raw.rs | 2 | ||||
| -rw-r--r-- | src/generator/html.rs | 4 | ||||
| -rw-r--r-- | src/generator/mod.rs | 3 | ||||
| -rw-r--r-- | src/generator/rss.rs | 4 | ||||
| -rw-r--r-- | src/generator/static_files.rs | 3 | ||||
| -rw-r--r-- | src/generator/txt.rs | 4 | ||||
| -rw-r--r-- | src/metadata.rs | 3 | ||||
| -rw-r--r-- | src/remote/git.rs | 6 | ||||
| -rw-r--r-- | src/remote/mod.rs | 42 | ||||
| -rw-r--r-- | src/utils.rs | 2 |
13 files changed, 79 insertions, 1 deletions
diff --git a/src/archiver/gemini.rs b/src/archiver/gemini.rs index 7839ff2..0cde0b1 100644 --- a/src/archiver/gemini.rs +++ b/src/archiver/gemini.rs @@ -47,6 +47,7 @@ mod tests { archive(&test_dir, &template_dir, &output_dir, &context).expect("Archive failed"); assert_file_contents(&output_dir.join("index.gmi"), "Simple things"); + cleanup_test_dir(&test_dir); } #[test] @@ -65,6 +66,7 @@ mod tests { let result = archive(&test_dir, &template_dir, &output_dir, &context); assert!(result.is_err()); + cleanup_test_dir(&test_dir); } #[test] @@ -82,5 +84,6 @@ mod tests { let result = archive(&test_dir, &template_dir, &output_dir, &context); assert!(result.is_err()); + cleanup_test_dir(&test_dir); } } diff --git a/src/archiver/gopher.rs b/src/archiver/gopher.rs index aa584ab..77f23b9 100644 --- a/src/archiver/gopher.rs +++ b/src/archiver/gopher.rs @@ -47,6 +47,7 @@ mod tests { archive(&test_dir, &template_dir, &output_dir, &context).expect("Archive failed"); assert_file_contents(&output_dir.join("index.gph"), "Simple things"); + cleanup_test_dir(&test_dir); } #[test] @@ -65,6 +66,7 @@ mod tests { let result = archive(&test_dir, &template_dir, &output_dir, &context); assert!(result.is_err()); + cleanup_test_dir(&test_dir); } #[test] @@ -82,5 +84,6 @@ mod tests { let result = archive(&test_dir, &template_dir, &output_dir, &context); assert!(result.is_err()); + cleanup_test_dir(&test_dir); } } diff --git a/src/archiver/mod.rs b/src/archiver/mod.rs index f809b8c..ddca473 100644 --- a/src/archiver/mod.rs +++ b/src/archiver/mod.rs @@ -265,5 +265,6 @@ mod tests { &output_dir.join("index.gmi"), "1736121600001/my-very-bad-file", ); + cleanup_test_dir(&test_dir); } } diff --git a/src/archiver/raw.rs b/src/archiver/raw.rs index 5cac709..d0f40d7 100644 --- a/src/archiver/raw.rs +++ b/src/archiver/raw.rs @@ -34,6 +34,7 @@ mod tests { archive(&archive_dir, &test_dir, &output_dir, &context).expect("Archive failed"); assert_file_contents(&output_dir.join("🤠"), "beep boop boop beep"); + cleanup_test_dir(&test_dir); } #[test] @@ -45,5 +46,6 @@ mod tests { let context: Context = HashMap::new(); archive(&archive_dir, &test_dir, &output_dir, &context).expect("Archive failed"); + cleanup_test_dir(&test_dir); } } diff --git a/src/generator/html.rs b/src/generator/html.rs index 7895a83..7af4c73 100644 --- a/src/generator/html.rs +++ b/src/generator/html.rs @@ -70,6 +70,7 @@ mod tests { assert_file_contains(&output_dir.join("index.html"), "<p>Contextualization</p>"); assert_file_contains(&output_dir.join("index.html"), "<p>Contexternalization</p>"); + cleanup_test_dir(&test_dir); } #[test] @@ -114,6 +115,7 @@ mod tests { <p>Recontexternalization</p> ", ); + cleanup_test_dir(&test_dir); } #[test] @@ -139,6 +141,7 @@ mod tests { let result = generate(&static_dir, &template_dir, &output_dir, &context); assert!(result.is_err()); + cleanup_test_dir(&test_dir); } #[test] @@ -174,5 +177,6 @@ mod tests { let result = generate(&static_dir, &template_dir, &output_dir, &context); assert!(result.is_err()); + cleanup_test_dir(&test_dir); } } diff --git a/src/generator/mod.rs b/src/generator/mod.rs index 55946af..1ba4036 100644 --- a/src/generator/mod.rs +++ b/src/generator/mod.rs @@ -125,6 +125,7 @@ mod tests { 1736045200000 ", ); + cleanup_test_dir(&test_dir); } #[test] @@ -138,6 +139,7 @@ mod tests { let result = generate(&static_dir, &template_dir, &output_dir, &posts); assert!(result.is_err()); + cleanup_test_dir(&test_dir); } #[test] @@ -183,5 +185,6 @@ mod tests { let result = generate(&static_dir, &template_dir, &output_dir, &posts); assert!(result.is_err()); + cleanup_test_dir(&test_dir); } } diff --git a/src/generator/rss.rs b/src/generator/rss.rs index c4b8bdb..0e28777 100644 --- a/src/generator/rss.rs +++ b/src/generator/rss.rs @@ -86,6 +86,7 @@ mod tests { assert_file_contains(&output_dir.join("feed.xml"), "<p>Contextualization</p>"); assert_file_contains(&output_dir.join("feed.xml"), "<p>Contexternalization</p>"); + cleanup_test_dir(&test_dir); } #[test] @@ -130,6 +131,7 @@ mod tests { <p>Recontexternalization</p> ", ); + cleanup_test_dir(&test_dir); } #[test] @@ -155,6 +157,7 @@ mod tests { let result = generate(&static_dir, &template_dir, &output_dir, &context); assert!(result.is_err()); + cleanup_test_dir(&test_dir); } #[test] @@ -190,5 +193,6 @@ mod tests { let result = generate(&static_dir, &template_dir, &output_dir, &context); assert!(result.is_err()); + cleanup_test_dir(&test_dir); } } diff --git a/src/generator/static_files.rs b/src/generator/static_files.rs index ae676a1..9d7ec80 100644 --- a/src/generator/static_files.rs +++ b/src/generator/static_files.rs @@ -35,6 +35,7 @@ mod tests { generate(&static_dir, &template_dir, &output_dir, &context).expect("Generate failed"); assert_file_contents(&output_dir.join("test.jpg"), "Cool hat"); + cleanup_test_dir(&test_dir); } #[test] @@ -53,6 +54,7 @@ mod tests { generate(&static_dir, &template_dir, &output_dir, &context).expect("Generate failed"); assert_file_contents(&output_dir.join("nested/test.mov"), "Cool hats, multiple."); + cleanup_test_dir(&test_dir); } #[test] @@ -67,5 +69,6 @@ mod tests { let result = generate(&static_dir, &template_dir, &output_dir, &context); assert!(result.is_ok()); + cleanup_test_dir(&test_dir); } } diff --git a/src/generator/txt.rs b/src/generator/txt.rs index ef48c03..d35720d 100644 --- a/src/generator/txt.rs +++ b/src/generator/txt.rs @@ -64,6 +64,7 @@ mod tests { assert_file_contains(&output_dir.join("index.txt"), "Contextualization"); assert_file_contains(&output_dir.join("index.txt"), "Contexternalization"); + cleanup_test_dir(&test_dir); } #[test] @@ -108,6 +109,7 @@ Recontextualization Recontexternalization ", ); + cleanup_test_dir(&test_dir); } #[test] @@ -133,6 +135,7 @@ Recontextualization let result = generate(&static_dir, &template_dir, &output_dir, &context); assert!(result.is_err()); + cleanup_test_dir(&test_dir); } #[test] @@ -168,5 +171,6 @@ Recontextualization let result = generate(&static_dir, &template_dir, &output_dir, &context); assert!(result.is_err()); + cleanup_test_dir(&test_dir); } } diff --git a/src/metadata.rs b/src/metadata.rs index f2890a4..140d1f4 100644 --- a/src/metadata.rs +++ b/src/metadata.rs @@ -72,6 +72,7 @@ mod tests { assert_eq!(metadata.id, "cool"); assert_eq!(metadata.created_on, 1_736_105_008_957); + cleanup_test_dir(&test_dir); } #[test] @@ -81,6 +82,7 @@ mod tests { assert!(!test_dir.join("metadata.json").exists()); let metadata = Metadata::read_or_create(&test_dir.join("metadata.json")); assert_eq!(metadata.created_on.to_string(), metadata.id); + cleanup_test_dir(&test_dir); } #[test] @@ -90,6 +92,7 @@ mod tests { let metadata = Metadata::read_or_create(&test_dir.join("metadata.json")); assert_eq!(metadata.created_on.to_string(), metadata.id); + cleanup_test_dir(&test_dir); } #[test] 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); + } +} diff --git a/src/utils.rs b/src/utils.rs index 01b6cdf..2e49a93 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -54,6 +54,7 @@ mod tests { assert_file_contents(&target_dir.join("nested/.hidden"), "I am not here?"); assert_file_contents(&target_dir.join(".hidden/in_plain_sight.mkv"), "Almost"); assert_file_contents(&target_dir.join(".hidden/.hidden"), "I'm double hidden"); + cleanup_test_dir(&test_dir); } #[test] @@ -67,5 +68,6 @@ mod tests { recursively_copy(&source_dir, &target_dir).expect("Copy failed on empty test directory"); assert_eq!(target_dir.read_dir().unwrap().count(), 0); + cleanup_test_dir(&test_dir); } } |