From bc2feece4b29836e6d91fe7533aaf7deef3d2b5b Mon Sep 17 00:00:00 2001 From: Maxime Date: Thu, 23 Jul 2015 09:35:46 +0200 Subject: [PATCH] Moved test files to testdata folder. Changed the tests accordingly. --- middleware/browse/browse_test.go | 4 ++-- middleware/browse/{ => testdata}/header.html | 0 middleware/browse/{ => testdata}/photos.tpl | 0 middleware/browse/{ => testdata}/photos/test.html | 0 middleware/browse/{ => testdata}/photos/test2.html | 0 middleware/markdown/markdown.go | 2 ++ middleware/markdown/markdown_test.go | 11 ++++++++--- middleware/markdown/process.go | 2 ++ middleware/markdown/{ => testdata}/blog/test.md | 0 middleware/markdown/{ => testdata}/header.html | 0 middleware/markdown/{ => testdata}/log/test.md | 0 middleware/markdown/{ => testdata}/markdown_tpl.html | 0 middleware/templates/templates_test.go | 8 ++++---- middleware/templates/{ => testdata}/header.html | 0 .../templates/{ => testdata}/images/header.html | 0 middleware/templates/{ => testdata}/images/img.htm | 0 middleware/templates/{ => testdata}/photos/test.html | 0 middleware/templates/{ => testdata}/root.html | 0 18 files changed, 18 insertions(+), 9 deletions(-) rename middleware/browse/{ => testdata}/header.html (100%) rename middleware/browse/{ => testdata}/photos.tpl (100%) rename middleware/browse/{ => testdata}/photos/test.html (100%) rename middleware/browse/{ => testdata}/photos/test2.html (100%) rename middleware/markdown/{ => testdata}/blog/test.md (100%) rename middleware/markdown/{ => testdata}/header.html (100%) rename middleware/markdown/{ => testdata}/log/test.md (100%) rename middleware/markdown/{ => testdata}/markdown_tpl.html (100%) rename middleware/templates/{ => testdata}/header.html (100%) rename middleware/templates/{ => testdata}/images/header.html (100%) rename middleware/templates/{ => testdata}/images/img.htm (100%) rename middleware/templates/{ => testdata}/photos/test.html (100%) rename middleware/templates/{ => testdata}/root.html (100%) diff --git a/middleware/browse/browse_test.go b/middleware/browse/browse_test.go index 4c5183b6..b0ff28db 100644 --- a/middleware/browse/browse_test.go +++ b/middleware/browse/browse_test.go @@ -101,7 +101,7 @@ func TestSort(t *testing.T) { } func TestBrowseTemplate(t *testing.T) { - tmpl, err := template.ParseFiles("photos.tpl") + tmpl, err := template.ParseFiles("testdata/photos.tpl") if err != nil { t.Fatalf("An error occured while parsing the template: %v", err) } @@ -111,7 +111,7 @@ func TestBrowseTemplate(t *testing.T) { t.Fatalf("Next shouldn't be called") return 0, nil }), - Root: ".", + Root: "./testdata", Configs: []Config{ Config{ PathScope: "/photos", diff --git a/middleware/browse/header.html b/middleware/browse/testdata/header.html similarity index 100% rename from middleware/browse/header.html rename to middleware/browse/testdata/header.html diff --git a/middleware/browse/photos.tpl b/middleware/browse/testdata/photos.tpl similarity index 100% rename from middleware/browse/photos.tpl rename to middleware/browse/testdata/photos.tpl diff --git a/middleware/browse/photos/test.html b/middleware/browse/testdata/photos/test.html similarity index 100% rename from middleware/browse/photos/test.html rename to middleware/browse/testdata/photos/test.html diff --git a/middleware/browse/photos/test2.html b/middleware/browse/testdata/photos/test2.html similarity index 100% rename from middleware/browse/photos/test2.html rename to middleware/browse/testdata/photos/test2.html diff --git a/middleware/markdown/markdown.go b/middleware/markdown/markdown.go index 71b18906..8aeb1f73 100644 --- a/middleware/markdown/markdown.go +++ b/middleware/markdown/markdown.go @@ -3,6 +3,7 @@ package markdown import ( + "fmt" "io/ioutil" "net/http" "os" @@ -125,6 +126,7 @@ func (md Markdown) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, error URL: r.URL, } html, err := md.Process(m, fpath, body, ctx) + fmt.Printf("%v", html) if err != nil { return http.StatusInternalServerError, err } diff --git a/middleware/markdown/markdown_test.go b/middleware/markdown/markdown_test.go index 2e3ac85e..e01d88e8 100644 --- a/middleware/markdown/markdown_test.go +++ b/middleware/markdown/markdown_test.go @@ -6,15 +6,16 @@ import ( "strings" "testing" + "github.com/mholt/caddy/middleware" "github.com/russross/blackfriday" ) func TestMarkdown(t *testing.T) { templates := make(map[string]string) - templates[DefaultTemplate] = "markdown_tpl.html" + templates[DefaultTemplate] = "testdata/markdown_tpl.html" md := Markdown{ - Root: "/blog", - FileSys: http.Dir("."), + Root: "./testdata", + FileSys: http.Dir("./testdata"), Configs: []Config{ Config{ Renderer: blackfriday.HtmlRenderer(0, "", ""), @@ -34,6 +35,10 @@ func TestMarkdown(t *testing.T) { }, }, IndexFiles: []string{"index.html"}, + Next: middleware.HandlerFunc(func(w http.ResponseWriter, r *http.Request) (int, error) { + t.Fatalf("Next shouldn't be called") + return 0, nil + }), } req, err := http.NewRequest("GET", "/blog/test.md", nil) diff --git a/middleware/markdown/process.go b/middleware/markdown/process.go index 02905b5f..1761ffc8 100644 --- a/middleware/markdown/process.go +++ b/middleware/markdown/process.go @@ -2,6 +2,7 @@ package markdown import ( "bytes" + "fmt" "io/ioutil" "log" "os" @@ -106,6 +107,7 @@ func (md Markdown) processTemplate(c Config, requestPath string, tmpl []byte, me // nothing fatal, only log the error. // TODO: Report this non-fatal error, but don't log it here log.Println(err) + fmt.Printf("Error: %v", err) } return b.Bytes(), nil diff --git a/middleware/markdown/blog/test.md b/middleware/markdown/testdata/blog/test.md similarity index 100% rename from middleware/markdown/blog/test.md rename to middleware/markdown/testdata/blog/test.md diff --git a/middleware/markdown/header.html b/middleware/markdown/testdata/header.html similarity index 100% rename from middleware/markdown/header.html rename to middleware/markdown/testdata/header.html diff --git a/middleware/markdown/log/test.md b/middleware/markdown/testdata/log/test.md similarity index 100% rename from middleware/markdown/log/test.md rename to middleware/markdown/testdata/log/test.md diff --git a/middleware/markdown/markdown_tpl.html b/middleware/markdown/testdata/markdown_tpl.html similarity index 100% rename from middleware/markdown/markdown_tpl.html rename to middleware/markdown/testdata/markdown_tpl.html diff --git a/middleware/templates/templates_test.go b/middleware/templates/templates_test.go index a519de99..5c283390 100644 --- a/middleware/templates/templates_test.go +++ b/middleware/templates/templates_test.go @@ -25,8 +25,8 @@ func Test(t *testing.T) { Path: "/images", }, }, - Root: ".", - FileSys: http.Dir("."), + Root: "./testdata", + FileSys: http.Dir("./testdata"), } tmplroot := Templates{ @@ -40,8 +40,8 @@ func Test(t *testing.T) { Path: "/", }, }, - Root: ".", - FileSys: http.Dir("."), + Root: "./testdata", + FileSys: http.Dir("./testdata"), } /* diff --git a/middleware/templates/header.html b/middleware/templates/testdata/header.html similarity index 100% rename from middleware/templates/header.html rename to middleware/templates/testdata/header.html diff --git a/middleware/templates/images/header.html b/middleware/templates/testdata/images/header.html similarity index 100% rename from middleware/templates/images/header.html rename to middleware/templates/testdata/images/header.html diff --git a/middleware/templates/images/img.htm b/middleware/templates/testdata/images/img.htm similarity index 100% rename from middleware/templates/images/img.htm rename to middleware/templates/testdata/images/img.htm diff --git a/middleware/templates/photos/test.html b/middleware/templates/testdata/photos/test.html similarity index 100% rename from middleware/templates/photos/test.html rename to middleware/templates/testdata/photos/test.html diff --git a/middleware/templates/root.html b/middleware/templates/testdata/root.html similarity index 100% rename from middleware/templates/root.html rename to middleware/templates/testdata/root.html