cli: Add assertions around creating an initial site.
This commit is contained in:
parent
d0ad8362c0
commit
d7288bef4e
|
@ -124,7 +124,6 @@ fn main() {
|
||||||
type Result = std::result::Result<(), RookeriesError>;
|
type Result = std::result::Result<(), RookeriesError>;
|
||||||
|
|
||||||
fn serve_site(args: &Args) -> Result {
|
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?
|
// TODO: Create a file watcher to check for changes to the source files?
|
||||||
header_message("Preparing to serve site...");
|
header_message("Preparing to serve site...");
|
||||||
|
|
||||||
|
|
|
@ -29,7 +29,6 @@ fn extract_and_install_archive(
|
||||||
) -> Result<(), RookeriesError> {
|
) -> Result<(), RookeriesError> {
|
||||||
let rookeries_home_cache = get_rookeries_home_cache_dir()?;
|
let rookeries_home_cache = get_rookeries_home_cache_dir()?;
|
||||||
let reader = std::io::Cursor::new(installer_archive);
|
let reader = std::io::Cursor::new(installer_archive);
|
||||||
// TODO: Add some file type for the error.
|
|
||||||
let mut zip = zip::ZipArchive::new(reader)
|
let mut zip = zip::ZipArchive::new(reader)
|
||||||
.map_err(|err| RookeriesError::ExtractArchiveError(err, file_type))?;
|
.map_err(|err| RookeriesError::ExtractArchiveError(err, file_type))?;
|
||||||
for i in 0..zip.len() {
|
for i in 0..zip.len() {
|
||||||
|
|
|
@ -2,8 +2,12 @@ extern crate rookeries;
|
||||||
|
|
||||||
use rand::{thread_rng, Rng};
|
use rand::{thread_rng, Rng};
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
use std::path::Path;
|
use rookeries::Site;
|
||||||
use std::process::{Command, Output};
|
use std::{
|
||||||
|
fs::read_to_string,
|
||||||
|
path::Path,
|
||||||
|
process::{Command, Output},
|
||||||
|
};
|
||||||
|
|
||||||
fn run_rookeries_command(command: &str) -> Output {
|
fn run_rookeries_command(command: &str) -> Output {
|
||||||
let mut test_command = vec!["run", "--"];
|
let mut test_command = vec!["run", "--"];
|
||||||
|
@ -89,7 +93,28 @@ fn test_init_creates_site() {
|
||||||
|
|
||||||
let project_root_dir = Path::new(&test_directory);
|
let project_root_dir = Path::new(&test_directory);
|
||||||
assert_valid_file_types_in_path(&project_root_dir, vec!["md", "toml"], false);
|
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");
|
let templates_dir = project_root_dir.join("template");
|
||||||
assert_valid_file_types_in_path(&templates_dir, vec!["html"], true);
|
assert_valid_file_types_in_path(&templates_dir, vec!["html"], true);
|
||||||
|
|
Loading…
Reference in New Issue