}
Ok(())
}
+
+#[cfg(test)]
+mod tests {
+ use std::collections::HashMap;
+ use std::fs::create_dir_all;
+
+ use super::*;
+ use crate::template::Value;
+
+ use test_utilities::*;
+
+ #[test]
+ fn test_renders_the_context_into_the_template() {
+ let test_dir = setup_test_dir();
+ let template_dir = test_dir.join("template");
+ let output_dir = test_dir.join("output");
+ create_dir_all(&output_dir).expect("Could not create output test directory");
+ create_dir_all(&template_dir).expect("Could not create template test directory");
+
+ create_test_file(&template_dir.join("index.gmi"), "Simple {{= test }}");
+
+ let context: Context =
+ HashMap::from([("test".to_string(), Value::String("things".to_string()))]);
+
+ archive(&test_dir, &template_dir, &output_dir, &context).expect("Archive failed");
+
+ assert_file_contents(&output_dir.join("index.gmi"), "Simple things");
+ }
+
+ #[test]
+ fn test_fails_if_template_is_malformed() {
+ let test_dir = setup_test_dir();
+ let template_dir = test_dir.join("template");
+ let output_dir = test_dir.join("output");
+ create_dir_all(&output_dir).expect("Could not create output test directory");
+ create_dir_all(&template_dir).expect("Could not create template test directory");
+
+ create_test_file(&template_dir.join("index.gmi"), "Simple {{ test }}");
+
+ let context: Context =
+ HashMap::from([("test".to_string(), Value::String("things".to_string()))]);
+
+ let result = archive(&test_dir, &template_dir, &output_dir, &context);
+
+ assert!(result.is_err());
+ }
+
+ #[test]
+ fn test_fails_if_output_folder_is_not_writable() {
+ let test_dir = setup_test_dir();
+ let template_dir = test_dir.join("template");
+ let output_dir = test_dir.join("/unwritable/folder/please");
+ create_dir_all(&template_dir).expect("Could not create template test directory");
+
+ create_test_file(&template_dir.join("index.gmi"), "Simple {{= test }}");
+
+ let context: Context =
+ HashMap::from([("test".to_string(), Value::String("things".to_string()))]);
+
+ let result = archive(&test_dir, &template_dir, &output_dir, &context);
+
+ assert!(result.is_err());
+ }
+}
}
Ok(())
}
+
+#[cfg(test)]
+mod tests {
+ use std::collections::HashMap;
+ use std::fs::create_dir_all;
+
+ use super::*;
+ use crate::template::Value;
+
+ use test_utilities::*;
+
+ #[test]
+ fn test_renders_the_context_into_the_template() {
+ let test_dir = setup_test_dir();
+ let template_dir = test_dir.join("template");
+ let output_dir = test_dir.join("output");
+ create_dir_all(&output_dir).expect("Could not create output test directory");
+ create_dir_all(&template_dir).expect("Could not create template test directory");
+
+ create_test_file(&template_dir.join("index.gph"), "Simple {{= test }}");
+
+ let context: Context =
+ HashMap::from([("test".to_string(), Value::String("things".to_string()))]);
+
+ archive(&test_dir, &template_dir, &output_dir, &context).expect("Archive failed");
+
+ assert_file_contents(&output_dir.join("index.gph"), "Simple things");
+ }
+
+ #[test]
+ fn test_fails_if_template_is_malformed() {
+ let test_dir = setup_test_dir();
+ let template_dir = test_dir.join("template");
+ let output_dir = test_dir.join("output");
+ create_dir_all(&output_dir).expect("Could not create output test directory");
+ create_dir_all(&template_dir).expect("Could not create template test directory");
+
+ create_test_file(&template_dir.join("index.gph"), "Simple {{ test }}");
+
+ let context: Context =
+ HashMap::from([("test".to_string(), Value::String("things".to_string()))]);
+
+ let result = archive(&test_dir, &template_dir, &output_dir, &context);
+
+ assert!(result.is_err());
+ }
+
+ #[test]
+ fn test_fails_if_output_folder_is_not_writable() {
+ let test_dir = setup_test_dir();
+ let template_dir = test_dir.join("template");
+ let output_dir = test_dir.join("/gopherunwritable/folder/please");
+ create_dir_all(&template_dir).expect("Could not create template test directory");
+
+ create_test_file(&template_dir.join("index.gph"), "Simple {{= test }}");
+
+ let context: Context =
+ HashMap::from([("test".to_string(), Value::String("things".to_string()))]);
+
+ let result = archive(&test_dir, &template_dir, &output_dir, &context);
+
+ assert!(result.is_err());
+ }
+}
}
Ok(())
}
+
+#[cfg(test)]
+mod tests {
+ use std::collections::HashMap;
+ use std::fs::create_dir_all;
+
+ use super::*;
+ use crate::template::Value;
+
+ use test_utilities::*;
+
+ #[test]
+ fn test_copies_files() {
+ let test_dir = setup_test_dir();
+ let archive_dir = test_dir.join("archive");
+ let output_dir = test_dir.join("output");
+ create_dir_all(&archive_dir).expect("Could not create archive test directory");
+ create_dir_all(&output_dir).expect("Could not create output test directory");
+
+ create_test_file(&archive_dir.join("🤠"), "beep boop boop beep");
+
+ let context: Context = HashMap::new();
+
+ archive(&archive_dir, &test_dir, &output_dir, &context).expect("Archive failed");
+
+ assert_file_contents(&output_dir.join("🤠"), "beep boop boop beep");
+ }
+
+ #[test]
+ fn test_ignores_if_no_archive() {
+ let test_dir = setup_test_dir();
+ let archive_dir = test_dir.join("archive");
+ let output_dir = test_dir.join("output");
+
+ let context: Context = HashMap::new();
+
+ archive(&archive_dir, &test_dir, &output_dir, &context).expect("Archive failed");
+ }
+}