aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Cargo.lock4
-rw-r--r--Cargo.toml4
-rw-r--r--src/command/generate.rs3
-rw-r--r--src/command/sync_down.rs118
-rw-r--r--src/configuration.rs18
-rw-r--r--test_utilities/Cargo.toml4
6 files changed, 139 insertions, 12 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 56a10d0..279df6f 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -4,7 +4,7 @@ version = 4
[[package]]
name = "blog"
-version = "7.1.0"
+version = "7.1.1"
dependencies = [
"gema_texto",
"serde",
@@ -121,7 +121,7 @@ dependencies = [
[[package]]
name = "test_utilities"
-version = "7.1.0"
+version = "7.1.1"
[[package]]
name = "time"
diff --git a/Cargo.toml b/Cargo.toml
index cfea8d4..68f1eaa 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,7 +1,7 @@
[package]
name = "blog"
-version = "7.1.0"
-edition = "2021"
+version = "7.1.1"
+edition = "2024"
license = "AGPL-3.0-or-later"
description = "Command line tool to author and manage a semi-ephemeralâ„¢ blog with a gemini archive."
homepage = "https://r.bdr.sh/blog.html"
diff --git a/src/command/generate.rs b/src/command/generate.rs
index b74b33b..e96ff33 100644
--- a/src/command/generate.rs
+++ b/src/command/generate.rs
@@ -31,15 +31,18 @@ impl Generate {
}
fn find_blog_content(post_path: &Path) -> Option<String> {
+ println!("{}", post_path.display());
let entries = read_dir(post_path).ok()?;
for entry in entries.filter_map(Result::ok) {
let entry_path = entry.path();
+ println!("{}", entry_path.display());
match entry_path.extension() {
Some(extension) => {
if extension == "gmi" {
let mut file = File::open(entry_path).ok()?;
let mut contents = String::new();
file.read_to_string(&mut contents).ok()?;
+ println!("{contents}");
return Some(contents);
}
}
diff --git a/src/command/sync_down.rs b/src/command/sync_down.rs
index f9122d4..bc9d983 100644
--- a/src/command/sync_down.rs
+++ b/src/command/sync_down.rs
@@ -44,3 +44,121 @@ impl super::Command for SyncDown {
"\t\t\t\tPulls from the git remote if configured"
}
}
+
+#[cfg(test)]
+mod tests {
+ use std::fs::create_dir_all;
+
+ use super::*;
+ use crate::command::Command;
+ use crate::configuration::Configuration;
+
+ use test_utilities::*;
+
+ #[test]
+ fn test_sync_down_command() {
+ let sync_down = SyncDown::new();
+
+ let test_dir = setup_test_dir();
+ let local_dir = test_dir.join("commandlocalup");
+ let remote_dir = test_dir.join("commandremoteup");
+ 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, "file1.txt", "I exist, but remotely");
+ assert!(!&local_dir.join("file1.txt").exists());
+ assert!(!&local_dir.join("file2.txt").exists());
+
+ let mut configuration = Configuration::new();
+ configuration.data_directory = local_dir.clone();
+ configuration.remote_config = test_dir.join("remoteconfig");
+
+ create_test_file(&local_dir.join("file1.txt"), "I exist");
+ sync_down
+ .execute(None, &configuration, "sync-down")
+ .expect("Could not sync down from remote");
+ assert_file_contents(&local_dir.join("file1.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
+ .execute(None, &configuration, "sync-down")
+ .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]
+ fn test_sync_down_fails_with_incorrect_remote() {
+ let sync_down = SyncDown::new();
+
+ let test_dir = setup_test_dir();
+ create_test_file(&test_dir.join("remoteconfigdown"), "DO NOT WAAANT");
+
+ let mut configuration = Configuration::new();
+ configuration.data_directory = test_dir.clone();
+ configuration.remote_config = test_dir.join("remoteconfig");
+
+ let result = sync_down.execute(None, &configuration, "sync-down");
+ assert!(result.is_err());
+ cleanup_test_dir(&test_dir);
+ }
+
+ #[test]
+ fn test_sync_down_does_not_fail_if_running_as_dependency() {
+ let sync_down = SyncDown::new();
+
+ let test_dir = setup_test_dir();
+ create_test_file(&test_dir.join("remoteconfigdown"), "DO NOT WAAANT");
+
+ let mut configuration = Configuration::new();
+ configuration.data_directory = test_dir.clone();
+ configuration.remote_config = test_dir.join("remoteconfig");
+
+ let result = sync_down.execute(None, &configuration, "NOPE");
+ assert!(result.is_ok());
+ cleanup_test_dir(&test_dir);
+ }
+
+ #[test]
+ fn sync_down_before_dependencies() {
+ let sync_down = SyncDown::new();
+ let dependencies = sync_down.before_dependencies();
+
+ assert_eq!(dependencies.len(), 0);
+ }
+
+ #[test]
+ fn sync_down_after_dependencies() {
+ let sync_down = SyncDown::new();
+ let dependencies = sync_down.after_dependencies();
+
+ assert_eq!(dependencies.len(), 0);
+ }
+
+ // These two tests feel pointless but I'm doing it for the coverage :p
+
+ #[test]
+ fn sync_down_command_output() {
+ let sync_down = SyncDown::new();
+ sync_down.command();
+ }
+
+ #[test]
+ fn sync_down_help_output() {
+ let sync_down = SyncDown::new();
+ sync_down.help();
+ }
+}
diff --git a/src/configuration.rs b/src/configuration.rs
index 1d7ce6a..afee277 100644
--- a/src/configuration.rs
+++ b/src/configuration.rs
@@ -102,7 +102,9 @@ mod tests {
#[test]
fn test_reads_configuration_from_configuration_variable_if_set() {
let test_dir = setup_test_dir();
- env::set_var("TEST_BLOG_CONFIG_DIRECTORY", &test_dir);
+ unsafe {
+ env::set_var("TEST_BLOG_CONFIG_DIRECTORY", &test_dir);
+ }
let config_directory = Configuration::directory(
"TEST_BLOG_CONFIG_DIRECTORY",
@@ -118,7 +120,9 @@ mod tests {
#[test]
fn test_reads_configuration_from_default_location_if_configuration_variable_not_set() {
let test_dir = setup_test_dir();
- env::set_var("TEST_XDG_CONFIG_HOME", &test_dir);
+ unsafe {
+ env::set_var("TEST_XDG_CONFIG_HOME", &test_dir);
+ }
let config_directory = Configuration::directory(
"UNDEFINED_BLOG_CONFIG_DIRECTORY",
@@ -150,10 +154,12 @@ mod tests {
let default_configuration = Configuration::new();
let test_dir = setup_test_dir();
- env::set_var("BLOG_CONFIG_DIRECTORY", test_dir.join("config"));
- env::set_var("BLOG_DATA_DIRECTORY", test_dir.join("data"));
- env::set_var("BLOG_OUTPUT_DIRECTORY", test_dir.join("output"));
- env::set_var("BLOG_MAX_POSTS", "99");
+ unsafe {
+ env::set_var("BLOG_CONFIG_DIRECTORY", test_dir.join("config"));
+ env::set_var("BLOG_DATA_DIRECTORY", test_dir.join("data"));
+ env::set_var("BLOG_OUTPUT_DIRECTORY", test_dir.join("output"));
+ env::set_var("BLOG_MAX_POSTS", "99");
+ }
let override_configuration = Configuration::new();
// Ensure our overrides were applied
diff --git a/test_utilities/Cargo.toml b/test_utilities/Cargo.toml
index 57ed81a..056e976 100644
--- a/test_utilities/Cargo.toml
+++ b/test_utilities/Cargo.toml
@@ -1,7 +1,7 @@
[package]
name = "test_utilities"
-version = "7.1.0"
-edition = "2021"
+version = "7.1.1"
+edition = "2024"
license = "AGPL-3.0-or-later"
description = "Shared test utilities for blog"
homepage = "https://r.bdr.sh/page.html"