From d7288bef4e120b7e7e7458224e2a74f6b7c3e0d3 Mon Sep 17 00:00:00 2001 From: Dorian Pula Date: Wed, 4 Dec 2019 19:16:41 -0500 Subject: [PATCH] cli: Add assertions around creating an initial site. --- src/main.rs | 1 - src/template.rs | 1 - tests/test_cli_interaction.rs | 31 ++++++++++++++++++++++++++++--- 3 files changed, 28 insertions(+), 5 deletions(-) diff --git a/src/main.rs b/src/main.rs index 73235da..6f0a74d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -124,7 +124,6 @@ fn main() { type Result = std::result::Result<(), RookeriesError>; fn serve_site(args: &Args) -> Result { - // TODO: Add an option to open up a browser window using xdg-open. // TODO: Create a file watcher to check for changes to the source files? header_message("Preparing to serve site..."); diff --git a/src/template.rs b/src/template.rs index 1f6bacb..82fcc27 100644 --- a/src/template.rs +++ b/src/template.rs @@ -29,7 +29,6 @@ fn extract_and_install_archive( ) -> Result<(), RookeriesError> { let rookeries_home_cache = get_rookeries_home_cache_dir()?; let reader = std::io::Cursor::new(installer_archive); - // TODO: Add some file type for the error. let mut zip = zip::ZipArchive::new(reader) .map_err(|err| RookeriesError::ExtractArchiveError(err, file_type))?; for i in 0..zip.len() { diff --git a/tests/test_cli_interaction.rs b/tests/test_cli_interaction.rs index c31fac1..c43f821 100644 --- a/tests/test_cli_interaction.rs +++ b/tests/test_cli_interaction.rs @@ -2,8 +2,12 @@ extern crate rookeries; use rand::{thread_rng, Rng}; use regex::Regex; -use std::path::Path; -use std::process::{Command, Output}; +use rookeries::Site; +use std::{ + fs::read_to_string, + path::Path, + process::{Command, Output}, +}; fn run_rookeries_command(command: &str) -> Output { let mut test_command = vec!["run", "--"]; @@ -89,7 +93,28 @@ fn test_init_creates_site() { let project_root_dir = Path::new(&test_directory); assert_valid_file_types_in_path(&project_root_dir, vec!["md", "toml"], false); - // TODO: Add in assertions about pages created and the site.toml + + // Is the site.toml setup correctly? + let site_config_file = &project_root_dir.join("site.toml"); + assert!(site_config_file.exists()); + assert!(site_config_file.is_file()); + + let site_config_raw = read_to_string(site_config_file).unwrap(); + assert_ne!(site_config_raw, ""); + let site_config: Site = toml::from_str(&site_config_raw).unwrap(); + assert_eq!(site_config.name, "New Rookeries Site"); + + let sample_pages = site_config.pages.unwrap(); + assert_eq!(sample_pages.len(), 3); + + // Assert the pages are setup. + for page in sample_pages.keys() { + let sample_page_path = &project_root_dir.join(format!("{}.md", page)); + assert!(sample_page_path.exists()); + + let page_content = read_to_string(sample_page_path).unwrap(); + assert_ne!(page_content, ""); + } let templates_dir = project_root_dir.join("template"); assert_valid_file_types_in_path(&templates_dir, vec!["html"], true);