|
@@ -5,6 +5,8 @@
|
|
|
package gin
|
|
package gin
|
|
|
|
|
|
|
|
import (
|
|
import (
|
|
|
|
|
+ "fmt"
|
|
|
|
|
+ "net/http"
|
|
|
"testing"
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/assert"
|
|
@@ -14,6 +16,21 @@ func init() {
|
|
|
SetMode(TestMode)
|
|
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) {
|
|
func TestLastChar(t *testing.T) {
|
|
|
assert.Equal(t, lastChar("hola"), uint8('a'))
|
|
assert.Equal(t, lastChar("hola"), uint8('a'))
|
|
|
assert.Equal(t, lastChar("adios"), uint8('s'))
|
|
assert.Equal(t, lastChar("adios"), uint8('s'))
|