aboutsummaryrefslogtreecommitdiff
path: root/src/command/add.rs
diff options
context:
space:
mode:
authorRuben Beltran del Rio <git@r.bdr.sh>2025-01-18 13:27:03 +0100
committerRuben Beltran del Rio <git@r.bdr.sh>2025-01-18 13:27:03 +0100
commit64296ca9c83011e3de4d9f1be02335d8eb1bfe95 (patch)
tree21d13b4689a2f52fc9d0b9077151cab0159d3cc6 /src/command/add.rs
parent760b30e71e565d4db2a3d8f25af0d05fa174e871 (diff)
Add tests for
Diffstat (limited to 'src/command/add.rs')
-rw-r--r--src/command/add.rs95
1 files changed, 95 insertions, 0 deletions
diff --git a/src/command/add.rs b/src/command/add.rs
index d38d077..9622f81 100644
--- a/src/command/add.rs
+++ b/src/command/add.rs
@@ -48,3 +48,98 @@ impl super::Command for Add {
"<path_to_post>\t\t\tCreates new blog post"
}
}
+
+#[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_add_command() {
+ let add = Add::new();
+
+ // Create all directories
+ let test_dir = setup_test_dir();
+
+ let posts_dir = test_dir.join("posts");
+ create_dir_all(&posts_dir).expect("Could not create posts test directory");
+ create_dir_all(&posts_dir.join("0")).expect("Could not create post 0 test directory");
+
+ // Create Test Files
+
+ // Create configuration
+ let mut configuration = Configuration::new();
+ configuration.posts_directory = posts_dir.clone();
+
+ // Let's ensure the initial state is OK
+ assert!(&posts_dir.join("0").exists());
+ assert!(!&posts_dir.join("1").exists());
+ assert!(!&posts_dir.join("2").exists());
+ assert!(!&posts_dir.join("3").exists());
+
+ // Add 1 of 3
+ add.execute(None, &configuration, "add")
+ .expect("Could not add a.gmi");
+ assert!(!&posts_dir.join("0").exists());
+ assert!(&posts_dir.join("1").exists());
+ assert!(!&posts_dir.join("2").exists());
+ assert!(!&posts_dir.join("3").exists());
+
+ // Add 2 of 3
+ add.execute(None, &configuration, "add")
+ .expect("Could not add a.gmi");
+ assert!(!&posts_dir.join("0").exists());
+ assert!(!&posts_dir.join("1").exists());
+ assert!(&posts_dir.join("2").exists());
+ assert!(!&posts_dir.join("3").exists());
+
+ // Add 3 of 3
+ add.execute(None, &configuration, "add")
+ .expect("Could not add a.gmi");
+ assert!(!&posts_dir.join("0").exists());
+ assert!(!&posts_dir.join("1").exists());
+ assert!(!&posts_dir.join("2").exists());
+ assert!(!&posts_dir.join("3").exists());
+
+ cleanup_test_dir(&test_dir);
+ }
+
+ #[test]
+ fn add_before_dependencies() {
+ let add = Add::new();
+ let dependencies = add.before_dependencies();
+
+ assert_eq!(dependencies.len(), 1);
+ assert_eq!(dependencies[0].command(), "sync-down");
+ }
+
+ #[test]
+ fn add_after_dependencies() {
+ let add = Add::new();
+ let dependencies = add.after_dependencies();
+
+ assert_eq!(dependencies.len(), 3);
+ assert_eq!(dependencies[0].command(), "update");
+ assert_eq!(dependencies[1].command(), "generate");
+ assert_eq!(dependencies[2].command(), "sync-up");
+ }
+
+ // These two tests feel pointless but I'm doing it for the coverage :p
+
+ #[test]
+ fn add_command_output() {
+ let add = Add::new();
+ add.command();
+ }
+
+ #[test]
+ fn add_help_output() {
+ let add = Add::new();
+ add.help();
+ }
+}