mirror of
https://github.com/gin-gonic/gin.git
synced 2025-10-16 21:32:11 +08:00
add some test for Delims
This commit is contained in:
parent
edd55b55ce
commit
e8ce83e9f2
1
fixtures/basic/hello.tmpl
Normal file
1
fixtures/basic/hello.tmpl
Normal file
@ -0,0 +1 @@
|
||||
<h1>Hello {[{.name}]}</h1>
|
3
gin.go
3
gin.go
@ -152,7 +152,8 @@ func (engine *Engine) SetHTMLTemplate(templ *template.Template) {
|
||||
if len(engine.trees) > 0 {
|
||||
debugPrintWARNINGSetHTMLTemplate()
|
||||
}
|
||||
engine.HTMLRender = render.HTMLProduction{Template: templ, Delims: engine.delims}
|
||||
|
||||
engine.HTMLRender = render.HTMLProduction{Template: templ}
|
||||
}
|
||||
|
||||
// NoRoute adds handlers for NoRoute. It return a 404 code by default.
|
||||
|
63
gin_test.go
63
gin_test.go
@ -8,11 +8,60 @@ import (
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"net/http"
|
||||
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func setupHTMLFiles(t *testing.T) func() {
|
||||
go func() {
|
||||
router := New()
|
||||
router.Delims("{[{", "}]}")
|
||||
router.LoadHTMLFiles("./fixtures/basic/hello.tmpl")
|
||||
router.GET("/test", func(c *Context) {
|
||||
c.HTML(http.StatusOK, "hello.tmpl", map[string]string{"name": "world"})
|
||||
})
|
||||
router.Run(":8888")
|
||||
}()
|
||||
t.Log("waiting 1 second for server startup")
|
||||
time.Sleep(1 * time.Second)
|
||||
return func() {}
|
||||
}
|
||||
|
||||
func setupHTMLGlob(t *testing.T) func() {
|
||||
go func() {
|
||||
router := New()
|
||||
router.Delims("{[{", "}]}")
|
||||
router.LoadHTMLGlob("./fixtures/basic/*")
|
||||
router.GET("/test", func(c *Context) {
|
||||
c.HTML(http.StatusOK, "hello.tmpl", map[string]string{"name": "world"})
|
||||
})
|
||||
router.Run(":8888")
|
||||
}()
|
||||
t.Log("waiting 1 second for server startup")
|
||||
time.Sleep(1 * time.Second)
|
||||
return func() {}
|
||||
}
|
||||
|
||||
//TODO
|
||||
// func (engine *Engine) LoadHTMLGlob(pattern string) {
|
||||
func TestLoadHTMLGlob(t *testing.T) {
|
||||
td := setupHTMLGlob(t)
|
||||
res, err := http.Get("http://127.0.0.1:8888/test")
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
|
||||
resp, _ := ioutil.ReadAll(res.Body)
|
||||
assert.Equal(t, "<h1>Hello world</h1>", string(resp[:]))
|
||||
|
||||
td()
|
||||
}
|
||||
|
||||
// func (engine *Engine) LoadHTMLFiles(files ...string) {
|
||||
// func (engine *Engine) RunTLS(addr string, cert string, key string) error {
|
||||
|
||||
@ -42,6 +91,18 @@ func TestCreateEngine(t *testing.T) {
|
||||
// SetMode(TestMode)
|
||||
// }
|
||||
|
||||
func TestLoadHTMLFiles(t *testing.T) {
|
||||
td := setupHTMLFiles(t)
|
||||
res, err := http.Get("http://127.0.0.1:8888/test")
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
|
||||
resp, _ := ioutil.ReadAll(res.Body)
|
||||
assert.Equal(t, "<h1>Hello world</h1>", string(resp[:]))
|
||||
td()
|
||||
}
|
||||
|
||||
func TestLoadHTMLReleaseMode(t *testing.T) {
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user