Skip to content

Commit

Permalink
Add load html file and func map.
Browse files Browse the repository at this point in the history
Signed-off-by: Bo-Yi Wu <[email protected]>
  • Loading branch information
appleboy committed Jul 2, 2017
1 parent a40699e commit f11fb03
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions gin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,18 @@ func setupHTMLFiles(t *testing.T) func() {
go func() {
router := New()
router.Delims("{[{", "}]}")
router.LoadHTMLFiles("./fixtures/basic/hello.tmpl")
router.SetFuncMap(template.FuncMap{
"formatAsDate": formatAsDate,
})
router.LoadHTMLFiles("./fixtures/basic/hello.tmpl", "./fixtures/basic/raw.tmpl")
router.GET("/test", func(c *Context) {
c.HTML(http.StatusOK, "hello.tmpl", map[string]string{"name": "world"})
})
router.GET("/raw", func(c *Context) {
c.HTML(http.StatusOK, "raw.tmpl", map[string]interface{}{
"now": time.Date(2017, 07, 01, 0, 0, 0, 0, time.UTC),
})
})
router.Run(":8888")
}()
t.Log("waiting 1 second for server startup")
Expand Down Expand Up @@ -74,7 +82,7 @@ func TestLoadHTMLGlob(t *testing.T) {
td()
}

func TestLoadHTMLFromFuncMap(t *testing.T) {
func TestLoadHTMLGlobFromFuncMap(t *testing.T) {
time.Now()
td := setupHTMLGlob(t)
res, err := http.Get("http://127.0.0.1:8888/raw")
Expand Down Expand Up @@ -129,6 +137,20 @@ func TestLoadHTMLFiles(t *testing.T) {
td()
}

func TestLoadHTMLFilesFuncMap(t *testing.T) {
time.Now()
td := setupHTMLFiles(t)
res, err := http.Get("http://127.0.0.1:8888/raw")
if err != nil {
fmt.Println(err)
}

resp, _ := ioutil.ReadAll(res.Body)
assert.Equal(t, "Date: 2017/07/01\n", string(resp[:]))

td()
}

func TestLoadHTMLReleaseMode(t *testing.T) {

}
Expand Down

0 comments on commit f11fb03

Please sign in to comment.