mirror of
https://github.com/caddyserver/caddy.git
synced 2025-01-07 11:28:48 +03:00
Moved test files to testdata folder.
Changed the tests accordingly.
This commit is contained in:
parent
2df30d186e
commit
bc2feece4b
18 changed files with 18 additions and 9 deletions
|
@ -101,7 +101,7 @@ func TestSort(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestBrowseTemplate(t *testing.T) {
|
func TestBrowseTemplate(t *testing.T) {
|
||||||
tmpl, err := template.ParseFiles("photos.tpl")
|
tmpl, err := template.ParseFiles("testdata/photos.tpl")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("An error occured while parsing the template: %v", err)
|
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")
|
t.Fatalf("Next shouldn't be called")
|
||||||
return 0, nil
|
return 0, nil
|
||||||
}),
|
}),
|
||||||
Root: ".",
|
Root: "./testdata",
|
||||||
Configs: []Config{
|
Configs: []Config{
|
||||||
Config{
|
Config{
|
||||||
PathScope: "/photos",
|
PathScope: "/photos",
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
package markdown
|
package markdown
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
|
@ -125,6 +126,7 @@ func (md Markdown) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, error
|
||||||
URL: r.URL,
|
URL: r.URL,
|
||||||
}
|
}
|
||||||
html, err := md.Process(m, fpath, body, ctx)
|
html, err := md.Process(m, fpath, body, ctx)
|
||||||
|
fmt.Printf("%v", html)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return http.StatusInternalServerError, err
|
return http.StatusInternalServerError, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,15 +6,16 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/mholt/caddy/middleware"
|
||||||
"github.com/russross/blackfriday"
|
"github.com/russross/blackfriday"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestMarkdown(t *testing.T) {
|
func TestMarkdown(t *testing.T) {
|
||||||
templates := make(map[string]string)
|
templates := make(map[string]string)
|
||||||
templates[DefaultTemplate] = "markdown_tpl.html"
|
templates[DefaultTemplate] = "testdata/markdown_tpl.html"
|
||||||
md := Markdown{
|
md := Markdown{
|
||||||
Root: "/blog",
|
Root: "./testdata",
|
||||||
FileSys: http.Dir("."),
|
FileSys: http.Dir("./testdata"),
|
||||||
Configs: []Config{
|
Configs: []Config{
|
||||||
Config{
|
Config{
|
||||||
Renderer: blackfriday.HtmlRenderer(0, "", ""),
|
Renderer: blackfriday.HtmlRenderer(0, "", ""),
|
||||||
|
@ -34,6 +35,10 @@ func TestMarkdown(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
IndexFiles: []string{"index.html"},
|
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)
|
req, err := http.NewRequest("GET", "/blog/test.md", nil)
|
||||||
|
|
|
@ -2,6 +2,7 @@ package markdown
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
|
@ -106,6 +107,7 @@ func (md Markdown) processTemplate(c Config, requestPath string, tmpl []byte, me
|
||||||
// nothing fatal, only log the error.
|
// nothing fatal, only log the error.
|
||||||
// TODO: Report this non-fatal error, but don't log it here
|
// TODO: Report this non-fatal error, but don't log it here
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
|
fmt.Printf("Error: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return b.Bytes(), nil
|
return b.Bytes(), nil
|
||||||
|
|
|
@ -25,8 +25,8 @@ func Test(t *testing.T) {
|
||||||
Path: "/images",
|
Path: "/images",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Root: ".",
|
Root: "./testdata",
|
||||||
FileSys: http.Dir("."),
|
FileSys: http.Dir("./testdata"),
|
||||||
}
|
}
|
||||||
|
|
||||||
tmplroot := Templates{
|
tmplroot := Templates{
|
||||||
|
@ -40,8 +40,8 @@ func Test(t *testing.T) {
|
||||||
Path: "/",
|
Path: "/",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Root: ".",
|
Root: "./testdata",
|
||||||
FileSys: http.Dir("."),
|
FileSys: http.Dir("./testdata"),
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
Loading…
Reference in a new issue