X-Git-Url: https://git.r.bdr.sh/rbdr/page/blobdiff_plain/1c5797fadeea6be505c01f13508203ba234cbdfa..ad021007efdaced54b6351b4220d77fa8188309e:/src/file_handler/mod.rs diff --git a/src/file_handler/mod.rs b/src/file_handler/mod.rs index 8ba50d4..cefe6a2 100644 --- a/src/file_handler/mod.rs +++ b/src/file_handler/mod.rs @@ -94,10 +94,13 @@ pub struct File { #[cfg(test)] mod tests { - use super::*; use std::path::PathBuf; - fn create_test_file(path: &str, file_type: FileType) -> File { + use super::*; + + use test_utilities::*; + + fn create_test_internal_file(path: &str, file_type: FileType) -> File { File { path: PathBuf::from(path), file_type, @@ -128,17 +131,21 @@ mod tests { #[test] fn test_identify_unknown_file() { let handler = FileHandler::default(); - let path = PathBuf::from("tests/fixtures"); + let path = PathBuf::from("tests"); assert!(matches!(handler.identify(&path), FileType::Unknown)); } #[test] fn test_get_layout_success() { + let test_dir = setup_test_dir(); + let layout_path = test_dir.join("_layout.html"); + create_test_file(&layout_path, ""); + let mut handler = FileHandler::default(); let files = vec![ - create_test_file("test.gmi", FileType::Gemini), - create_test_file("tests/fixtures/_layout.html", FileType::Layout), - create_test_file("regular.html", FileType::File), + create_test_internal_file("test.gmi", FileType::Gemini), + create_test_internal_file(&layout_path.to_str().expect("Could not encode layout"), FileType::Layout), + create_test_internal_file("regular.html", FileType::File), ]; assert!(handler.get_layout_or_panic(&files).is_ok()); @@ -148,8 +155,8 @@ mod tests { fn test_get_layout_failure() { let mut handler = FileHandler::default(); let files = vec![ - create_test_file("test.gmi", FileType::Gemini), - create_test_file("regular.html", FileType::File), + create_test_internal_file("test.gmi", FileType::Gemini), + create_test_internal_file("regular.html", FileType::File), ]; assert!(handler.get_layout_or_panic(&files).is_err()); @@ -213,7 +220,7 @@ mod tests { let mut handler = FileHandler::default(); handler.layout = Some("test layout".to_string()); - let file = create_test_file("tests/fixtures/test1.gmi", FileType::Gemini); + let file = create_test_internal_file("tests/fixtures/test1.gmi", FileType::Gemini); // Should not panic with valid layout handler.handle( @@ -228,7 +235,7 @@ mod tests { #[should_panic(expected = "Layout should be initialized before handling files")] fn test_handle_without_layout() { let handler = FileHandler::default(); - let file = create_test_file("test.gmi", FileType::Gemini); + let file = create_test_internal_file("test.gmi", FileType::Gemini); handler.handle( &PathBuf::from("source"), @@ -240,12 +247,16 @@ mod tests { #[test] fn test_slice_handling() { + let test_dir = setup_test_dir(); + let layout_path = test_dir.join("_layout.html"); + create_test_file(&layout_path, ""); + let mut handler = FileHandler::default(); let files = vec![ - create_test_file("tests/fixtures/test1.gmi", FileType::Gemini), - create_test_file("tests/fixtures/_layout.html", FileType::Layout), - create_test_file("tests/fixtures/test2.gmi", FileType::Gemini), - create_test_file("tests/fixtures/test3.gmi", FileType::Gemini), + create_test_internal_file("tests/fixtures/test1.gmi", FileType::Gemini), + create_test_internal_file(&layout_path.to_str().expect("Could not encode layout"), FileType::Layout), + create_test_internal_file("tests/fixtures/test2.gmi", FileType::Gemini), + create_test_internal_file("tests/fixtures/test3.gmi", FileType::Gemini), ]; let _ = handler.get_layout_or_panic(&files[1..]);