Adds helper function. Wrap(http.HandlerFund) gin.HandlerFun
This commit is contained in:
@@ -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'))
|
||||
|
||||
Reference in New Issue
Block a user