Adds helper function. Wrap(http.HandlerFund) gin.HandlerFun

This commit is contained in:
Manu Mtz-Almeida
2015-05-19 22:18:58 +02:00
parent f2ab821223
commit 4f855faef2
2 changed files with 24 additions and 0 deletions
+17
View File
@@ -5,6 +5,8 @@
package gin
import (
"fmt"
"net/http"
"testing"
"github.com/stretchr/testify/assert"
@@ -14,6 +16,21 @@ func init() {
SetMode(TestMode)
}
func TestWrap(t *testing.T) {
router := New()
router.GET("/path", Wrap(func(w http.ResponseWriter, req *http.Request) {
assert.Equal(t, req.Method, "GET")
assert.Equal(t, req.URL.Path, "/path")
w.WriteHeader(400)
fmt.Fprint(w, "hola!")
}))
w := performRequest(router, "GET", "/path")
assert.Equal(t, w.Code, 400)
assert.Equal(t, w.Body.String(), "hola!")
}
func TestLastChar(t *testing.T) {
assert.Equal(t, lastChar("hola"), uint8('a'))
assert.Equal(t, lastChar("adios"), uint8('s'))