mirror of
https://github.com/caddyserver/caddy.git
synced 2024-11-29 12:16:16 +08:00
Added a test on markdown for the default template
This commit is contained in:
parent
6451e10d3e
commit
2df30d186e
15
middleware/markdown/log/test.md
Normal file
15
middleware/markdown/log/test.md
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
---
|
||||||
|
title: Markdown test
|
||||||
|
variables:
|
||||||
|
sitename: A Caddy website
|
||||||
|
---
|
||||||
|
|
||||||
|
## Welcome on the blog
|
||||||
|
|
||||||
|
Body
|
||||||
|
|
||||||
|
``` go
|
||||||
|
func getTrue() bool {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
```
|
|
@ -3,6 +3,7 @@ package markdown
|
||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/russross/blackfriday"
|
"github.com/russross/blackfriday"
|
||||||
|
@ -18,11 +19,19 @@ func TestMarkdown(t *testing.T) {
|
||||||
Config{
|
Config{
|
||||||
Renderer: blackfriday.HtmlRenderer(0, "", ""),
|
Renderer: blackfriday.HtmlRenderer(0, "", ""),
|
||||||
PathScope: "/blog",
|
PathScope: "/blog",
|
||||||
Extensions: []string{"md"},
|
Extensions: []string{".md"},
|
||||||
Styles: []string{},
|
Styles: []string{},
|
||||||
Scripts: []string{},
|
Scripts: []string{},
|
||||||
Templates: templates,
|
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"},
|
IndexFiles: []string{"index.html"},
|
||||||
}
|
}
|
||||||
|
@ -62,7 +71,50 @@ func getTrue() bool {
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
`
|
`
|
||||||
|
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 = `<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>Markdown test</title>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<link rel="stylesheet" href="/resources/css/log.css">
|
||||||
|
<link rel="stylesheet" href="/resources/css/default.css">
|
||||||
|
|
||||||
|
<script src="/resources/js/log.js"></script>
|
||||||
|
<script src="/resources/js/default.js"></script>
|
||||||
|
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h2>Welcome on the blog</h2>
|
||||||
|
|
||||||
|
<p>Body</p>
|
||||||
|
|
||||||
|
<p><code>go
|
||||||
|
func getTrue() bool {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
</code></p>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>`
|
||||||
|
|
||||||
|
replacer := strings.NewReplacer("\r", "", "\n", "")
|
||||||
|
respBody = replacer.Replace(respBody)
|
||||||
|
expectedBody = replacer.Replace(expectedBody)
|
||||||
if respBody != expectedBody {
|
if respBody != expectedBody {
|
||||||
t.Fatalf("Expected body: %v got: %v", expectedBody, respBody)
|
t.Fatalf("Expected body: %v got: %v", expectedBody, respBody)
|
||||||
}
|
}
|
||||||
|
|
|
@ -191,7 +191,7 @@ const (
|
||||||
{{js}}
|
{{js}}
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
{{.markdown}}
|
{{.Markdown}}
|
||||||
</body>
|
</body>
|
||||||
</html>`
|
</html>`
|
||||||
cssTemplate = `<link rel="stylesheet" href="{{url}}">`
|
cssTemplate = `<link rel="stylesheet" href="{{url}}">`
|
||||||
|
|
Loading…
Reference in New Issue
Block a user