add custom Delims support (#860)

* Revert "Merge pull request #753 from gin-gonic/bug"

This reverts commit 556287ff08, reversing
changes made to 32cab500ec.

* Revert "Merge pull request #744 from aviddiviner/logger-fix"

This reverts commit c3bfd69303, reversing
changes made to 9177f01c28.

* add custom Delims support

* add some test for Delims

* remove the empty line for import native package

* remove unuseful comments
This commit is contained in:
sope
2017-05-29 16:03:49 +08:00
committed by Bo-Yi Wu
parent 8295db44ed
commit 35f5df63e6
4 changed files with 84 additions and 10 deletions
+59 -1
View File
@@ -5,14 +5,60 @@
package gin
import (
"fmt"
"io/ioutil"
"net/http"
"reflect"
"testing"
"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 +88,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) {
}