From 2df30d186ebf1151be1f9e0abe4344f850371027 Mon Sep 17 00:00:00 2001 From: Maxime Date: Tue, 21 Jul 2015 17:45:32 +0200 Subject: [PATCH] Added a test on markdown for the default template --- middleware/markdown/log/test.md | 15 ++++++++ middleware/markdown/markdown_test.go | 54 +++++++++++++++++++++++++++- middleware/markdown/process.go | 2 +- 3 files changed, 69 insertions(+), 2 deletions(-) create mode 100644 middleware/markdown/log/test.md diff --git a/middleware/markdown/log/test.md b/middleware/markdown/log/test.md new file mode 100644 index 000000000..7ec766160 --- /dev/null +++ b/middleware/markdown/log/test.md @@ -0,0 +1,15 @@ +--- +title: Markdown test +variables: + sitename: A Caddy website +--- + +## Welcome on the blog + +Body + +``` go +func getTrue() bool { + return true +} +``` diff --git a/middleware/markdown/markdown_test.go b/middleware/markdown/markdown_test.go index 3f8b50ec6..2e3ac85e6 100644 --- a/middleware/markdown/markdown_test.go +++ b/middleware/markdown/markdown_test.go @@ -3,6 +3,7 @@ package markdown import ( "net/http" "net/http/httptest" + "strings" "testing" "github.com/russross/blackfriday" @@ -18,11 +19,19 @@ func TestMarkdown(t *testing.T) { Config{ Renderer: blackfriday.HtmlRenderer(0, "", ""), PathScope: "/blog", - Extensions: []string{"md"}, + Extensions: []string{".md"}, Styles: []string{}, Scripts: []string{}, Templates: templates, }, + Config{ + Renderer: blackfriday.HtmlRenderer(0, "", ""), + PathScope: "/log", + Extensions: []string{".md"}, + Styles: []string{"/resources/css/log.css", "/resources/css/default.css"}, + Scripts: []string{"/resources/js/log.js", "/resources/js/default.js"}, + Templates: make(map[string]string), + }, }, IndexFiles: []string{"index.html"}, } @@ -62,7 +71,50 @@ func getTrue() bool { ` + if respBody != expectedBody { + t.Fatalf("Expected body: %v got: %v", expectedBody, respBody) + } + req, err = http.NewRequest("GET", "/log/test.md", nil) + if err != nil { + t.Fatalf("Could not create HTTP request: %v", err) + } + rec = httptest.NewRecorder() + + md.ServeHTTP(rec, req) + if rec.Code != http.StatusOK { + t.Fatalf("Wrong status, expected: %d and got %d", http.StatusOK, rec.Code) + } + respBody = rec.Body.String() + expectedBody = ` + + + Markdown test + + + + + + + + + +

Welcome on the blog

+ +

Body

+ +

go +func getTrue() bool { + return true +} +

+ + +` + + replacer := strings.NewReplacer("\r", "", "\n", "") + respBody = replacer.Replace(respBody) + expectedBody = replacer.Replace(expectedBody) if respBody != expectedBody { t.Fatalf("Expected body: %v got: %v", expectedBody, respBody) } diff --git a/middleware/markdown/process.go b/middleware/markdown/process.go index ce9b5a7ca..02905b5f7 100644 --- a/middleware/markdown/process.go +++ b/middleware/markdown/process.go @@ -191,7 +191,7 @@ const ( {{js}} - {{.markdown}} + {{.Markdown}} ` cssTemplate = ``