mirror of
				https://github.com/caddyserver/caddy.git
				synced 2025-11-03 19:17:29 -05: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 (
 | 
			
		||||
	"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 {
 | 
			
		||||
</body>
 | 
			
		||||
</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 {
 | 
			
		||||
		t.Fatalf("Expected body: %v got: %v", expectedBody, respBody)
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
@ -191,7 +191,7 @@ const (
 | 
			
		||||
		{{js}}
 | 
			
		||||
	</head>
 | 
			
		||||
	<body>
 | 
			
		||||
		{{.markdown}}
 | 
			
		||||
		{{.Markdown}}
 | 
			
		||||
	</body>
 | 
			
		||||
</html>`
 | 
			
		||||
	cssTemplate = `<link rel="stylesheet" href="{{url}}">`
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user