diff --git a/caddyhttp/markdown/markdown.go b/caddyhttp/markdown/markdown.go
index 27e60b03..12c2ec61 100644
--- a/caddyhttp/markdown/markdown.go
+++ b/caddyhttp/markdown/markdown.go
@@ -53,6 +53,9 @@ type Config struct {
// Template(s) to render with
Template *template.Template
+
+ // a pair of template's name and its underlying file path
+ TemplateFiles map[string]string
}
// ServeHTTP implements the http.Handler interface.
diff --git a/caddyhttp/markdown/markdown_test.go b/caddyhttp/markdown/markdown_test.go
index 4da39a7f..e8279da9 100644
--- a/caddyhttp/markdown/markdown_test.go
+++ b/caddyhttp/markdown/markdown_test.go
@@ -1,17 +1,15 @@
package markdown
import (
- "bufio"
"io/ioutil"
"net/http"
"net/http/httptest"
"os"
"path/filepath"
- "strings"
"testing"
"text/template"
- "time"
+ "github.com/mholt/caddy"
"github.com/mholt/caddy/caddyhttp/httpserver"
"github.com/russross/blackfriday"
)
@@ -79,19 +77,26 @@ func TestMarkdown(t *testing.T) {
}),
}
- req, err := http.NewRequest("GET", "/blog/test.md", nil)
- if err != nil {
- t.Fatalf("Could not create HTTP request: %v", err)
+ get := func(url string) string {
+ req, err := http.NewRequest("GET", url, nil)
+ if err != nil {
+ t.Fatalf("Could not create HTTP request: %v", err)
+ return ""
+ }
+ rec := httptest.NewRecorder()
+ code, err := md.ServeHTTP(rec, req)
+ if err != nil {
+ t.Fatal(err)
+ return ""
+ }
+ if code != http.StatusOK {
+ t.Fatalf("Wrong status, expected: %d and got %d", http.StatusOK, code)
+ return ""
+ }
+ return rec.Body.String()
}
- 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()
+ respBody := get("/blog/test.md")
expectedBody := `
@@ -99,7 +104,6 @@ func TestMarkdown(t *testing.T) {
Header for: Markdown test 1
-
Welcome to A Caddy website!
Welcome on the blog
@@ -113,46 +117,22 @@ Welcome to A Caddy website!
`
- if !equalStrings(respBody, expectedBody) {
- t.Fatalf("Expected body: %v got: %v", expectedBody, respBody)
- }
-
- req, err = http.NewRequest("GET", "/docflags/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()
+ respBody = get("/docflags/test.md")
expectedBody = `Doc.var_string hello
-Doc.var_bool
-DocFlags.var_string
-DocFlags.var_bool true`
+Doc.var_bool true
+`
- if !equalStrings(respBody, expectedBody) {
- t.Fatalf("Expected body: %v got: %v", expectedBody, respBody)
+ if respBody != expectedBody {
+ t.Fatalf("Expected body:\n%q\ngot:\n%q", 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()
+ respBody = get("/log/test.md")
expectedBody = `
Markdown test 2
+
@@ -171,26 +151,11 @@ DocFlags.var_bool true`
`
- if !equalStrings(respBody, expectedBody) {
- t.Fatalf("Expected body: %v got: %v", expectedBody, respBody)
+ if respBody != expectedBody {
+ t.Fatalf("Expected body:\n%q\ngot:\n%q", expectedBody, respBody)
}
- req, err = http.NewRequest("GET", "/og/first.md", nil)
- if err != nil {
- t.Fatalf("Could not create HTTP request: %v", err)
- }
- rec = httptest.NewRecorder()
- currenttime := time.Now().Local().Add(-time.Second)
- _ = os.Chtimes("testdata/og/first.md", currenttime, currenttime)
- currenttime = time.Now().Local()
- _ = os.Chtimes("testdata/og_static/og/first.md/index.html", currenttime, currenttime)
- time.Sleep(time.Millisecond * 200)
-
- 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()
+ respBody = get("/og/first.md")
expectedBody = `
@@ -198,32 +163,18 @@ DocFlags.var_bool true`
Header for: first_post
-
Welcome to title!
Test h1
-`
+