Skip to content

Commit

Permalink
add testing and fix path.
Browse files Browse the repository at this point in the history
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
  • Loading branch information
appleboy committed Dec 20, 2016
1 parent 0216d6b commit 2e1a143
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
1 change: 1 addition & 0 deletions multitemplate.go
Expand Up @@ -2,6 +2,7 @@ package multitemplate

import (
"html/template"
"path/filepath"

"github.com/gin-gonic/gin/render"
)
Expand Down
38 changes: 38 additions & 0 deletions multitemplate_test.go
@@ -0,0 +1,38 @@
package multitemplate

import (
"net/http"
"net/http/httptest"
"testing"

"github.com/stretchr/testify/assert"
"gopkg.in/gin-gonic/gin.v1"
)

func performRequest(r http.Handler, method, path string) *httptest.ResponseRecorder {
req, _ := http.NewRequest(method, path, nil)
w := httptest.NewRecorder()
r.ServeHTTP(w, req)
return w
}

func createMyRender() Render {
r := New()
r.AddFromFiles("index", "tests/base.html", "tests/base.html")

return r
}

func TestAddFromFiles(t *testing.T) {
router := gin.New()
router.HTMLRender = createMyRender()
router.GET("/", func(c *gin.Context) {
c.HTML(200, "index", gin.H{
"title": "Test Multiple Template",
})
})

w := performRequest(router, "GET", "/")
assert.Equal(t, 200, w.Code)
assert.Equal(t, "<p>Test Multiple Template</p>\n", w.Body.String())
}
1 change: 1 addition & 0 deletions tests/base.html
@@ -0,0 +1 @@
<p>{{ .title }}</p>

0 comments on commit 2e1a143

Please sign in to comment.