func main() { log.Trace("Starting") flag.Parse() if *blog_dir == "" { log.Error("Must specify a directory where blogs are stored") time.Sleep(1000) os.Exit(1) } blogs := blog.New() blogReader := reader.New(blogs, *blog_dir, log) v := view.New(blogs, log) router := router.New(v, log) err := blogReader.ReadBlogs() if err != nil { log.Error("Error creating blog reader: %s", err) time.Sleep(1000) os.Exit(1) } http.Handle("/", router) http.Handle("/public/", http.StripPrefix("/public/", http.FileServer(http.Dir("./public")))) err = http.ListenAndServe(":"+*protocol, nil) if err != nil { log.Error("Problem with http server: %s", err) time.Sleep(1000) os.Exit(1) } log.Trace("Stopping") }
func Test_CanReadAndGetBlogs(t *testing.T) { blogs := blog.New() reader := reader.New(blogs, "../blogs", log) reader.ReadBlogs() blog1 := blogs.Get("example_1") blog2 := blogs.Get("example_2") blog3 := blogs.Get("example_3") blog4 := blogs.Get("example_4") if blog1 == nil || blog2 == nil || blog3 == nil || blog4 == nil { t.Error("Did not properly read blogs") return } if blog1.Title != "Example 1" { t.Error("Did not receive expected blog") return } if blog2.Title != "Example 2" { t.Error("Did not receive expected blog") return } if blog3.Title != "Example 3" { t.Error("Did not receive expected blog") return } if blog4.Title != "Example 4" { t.Error("Did not receive expected blog") return } }
func Test_MakeBlogWithFile(t *testing.T) { b := blog.New() r := reader.New(b, "dir", log) err := r.NewBlogFromFile("example.txt") if err != nil { t.Error("Unexpected error parsing the blog file:", err.Error()) return } if !(b.Blogs()[0].Title == "The Title") { t.Error("Did not set the proper title") return } if !(b.Blogs()[0].Intro == "The Intro") { t.Error("Did not set the proper intro") return } if !(b.Blogs()[0].Subsections[0].Header == "Sub Title 1") { t.Error("Did not set the proper subtitle", b.Blogs()[0].Subsections[0].Header) return } if !(b.Blogs()[0].Subsections[0].Text == "Sub Text 1") { t.Error("Did not set the proper sub text") return } if !(b.Blogs()[0].Subsections[1].Header == "Sub Title 2") { t.Error("Did not set the proper subtitle") return } if !(b.Blogs()[0].Subsections[1].Text == "Sub Text 2") { t.Error("Did not set the proper sub text") return } if !(b.Blogs()[0].Outro == "The Outro") { t.Error("Did not set the proper outro") return } if !(b.Blogs()[0].Tags[0].Name == "Tag 1") { t.Error("Did not set the proper tag") return } if !(b.Blogs()[0].Tags[1].Name == "Tag 2") { t.Error("Did not set the proper tag") return } }
func Test_BlogRequiresIntro(t *testing.T) { r := reader.New(blog.New(), "dir", log) err := r.NewBlogFromFile("missing_intro.txt") if err == nil { t.Error("Expected error") return } if !(err.Error() == "Missing Section: Intro") { t.Error("Did not get the correct error") return } }
func Test_CanHaveMiltiLines(t *testing.T) { b := blog.New() r := reader.New(b, "dir", log) err := r.NewBlogFromFile("multiline_body.txt") if err != nil { t.Error("Unexpected error") return } if !(b.Blogs()[0].Intro == "The Intro, line 1\nThe Intro, line 2\nThe Intro, line 3") { t.Error("Unexpected Intro:", b.Blogs()[0].Intro) return } }