From e964ec8f74b644d66ca166a7524adcc3a82709c9 Mon Sep 17 00:00:00 2001 From: "Gabriel A. Giovanini" Date: Sat, 14 May 2022 19:56:06 +0200 Subject: feat: Move code to blog - Move most logic of the blog to blog.rs, making it easier to test. - Now the file contains the creation date of the blog post to be parsed. - Add chrono to parse datetime, so later we can order by date. - Refactor gitlab pipeline, move `before_script` to a proper place. --- tests/test_blog.rs | 36 ++++++++++++++++++++++++++++++++++++ tests/test_router.rs | 2 +- 2 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 tests/test_blog.rs (limited to 'tests') diff --git a/tests/test_blog.rs b/tests/test_blog.rs new file mode 100644 index 0000000..31d5725 --- /dev/null +++ b/tests/test_blog.rs @@ -0,0 +1,36 @@ +use macroblog::blog::*; + +use chrono::NaiveDate; + + +#[test] +fn test_create_blog_entry() { + let asset_filename = String::from("2021-12-03Enable_NFS_on_K3S.html"); + let post_date = NaiveDate::from_ymd(2021, 12, 03); + + let blog_entry = BlogEntry::new(&asset_filename); + + assert_eq!(blog_entry.title, "Enable NFS on K3S"); + assert_eq!(blog_entry.datetime, post_date); +} + +#[test] +fn test_read_assets() { + // This test meant to test if all files are parsed correctly + let assets = BlogEntry::read_assets(); + assert!(assets.iter().count() > 1) +} + +#[test] +fn test_render_post_page() { + let path = &String::from("2020-07-14Friz_box_turned_off_DHCP.html"); + let page = render_post_page(path); + assert!(!page.is_empty()); +} + + +#[test] +fn test_render_index_page() { + let page = render_index_page(); + assert!(!page.is_empty()); +} diff --git a/tests/test_router.rs b/tests/test_router.rs index 0158d78..7ebe019 100644 --- a/tests/test_router.rs +++ b/tests/test_router.rs @@ -1,4 +1,4 @@ -use router::{Router}; +use macroblog::router::{Router}; #[test] fn test_router_new_posts() { -- cgit v1.2.3