mirror of https://github.com/gofiber/fiber.git
v3: fix tests
parent
9428befb9c
commit
543e8bb7ea
|
@ -1552,7 +1552,7 @@ func Test_Bind_RepeatParserWithSameStruct(t *testing.T) {
|
|||
|
||||
type Request struct {
|
||||
QueryParam string `query:"query_param"`
|
||||
HeaderParam string `reqHeader:"header_param"`
|
||||
HeaderParam string `header:"header_param"`
|
||||
BodyParam string `json:"body_param" xml:"body_param" form:"body_param"`
|
||||
}
|
||||
|
||||
|
|
32
ctx_test.go
32
ctx_test.go
|
@ -1596,27 +1596,8 @@ func Test_Ctx_Protocol(t *testing.T) {
|
|||
|
||||
require.Equal(t, "HTTP/1.1", c.Protocol())
|
||||
|
||||
c.Request().Header.Set(HeaderXForwardedProtocol, "https")
|
||||
require.Equal(t, "https", c.Protocol())
|
||||
c.Request().Header.Reset()
|
||||
|
||||
c.Request().Header.Set(HeaderXForwardedProto, "https, http")
|
||||
require.Equal(t, "https", c.Protocol())
|
||||
c.Request().Header.Reset()
|
||||
|
||||
c.Request().Header.Set(HeaderXForwardedProtocol, "https, http")
|
||||
require.Equal(t, "https", c.Protocol())
|
||||
c.Request().Header.Reset()
|
||||
|
||||
c.Request().Header.Set(HeaderXForwardedSsl, "on")
|
||||
require.Equal(t, "https", c.Protocol())
|
||||
c.Request().Header.Reset()
|
||||
|
||||
c.Request().Header.Set(HeaderXUrlScheme, "https")
|
||||
require.Equal(t, "https", c.Protocol())
|
||||
c.Request().Header.Reset()
|
||||
|
||||
require.Equal(t, "http", c.Protocol())
|
||||
c.Request().Header.SetProtocol("HTTP/2")
|
||||
require.Equal(t, "HTTP/2", c.Protocol())
|
||||
}
|
||||
|
||||
// go test -v -run=^$ -bench=Benchmark_Ctx_Protocol -benchmem -count=4
|
||||
|
@ -2218,7 +2199,7 @@ func Test_Ctx_JSONP(t *testing.T) {
|
|||
})
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, `callback({"Age":20,"Name":"Grame"});`, string(c.Response().Body()))
|
||||
require.Equal(t, "application/javascript; charset=utf-8", string(c.Response().Header.Peek("content-type")))
|
||||
require.Equal(t, "text/javascript; charset=utf-8", string(c.Response().Header.Peek("content-type")))
|
||||
|
||||
err = c.JSONP(Map{
|
||||
"Name": "Grame",
|
||||
|
@ -2226,7 +2207,7 @@ func Test_Ctx_JSONP(t *testing.T) {
|
|||
}, "john")
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, `john({"Age":20,"Name":"Grame"});`, string(c.Response().Body()))
|
||||
require.Equal(t, "application/javascript; charset=utf-8", string(c.Response().Header.Peek("content-type")))
|
||||
require.Equal(t, "text/javascript; charset=utf-8", string(c.Response().Header.Peek("content-type")))
|
||||
}
|
||||
|
||||
// go test -v -run=^$ -bench=Benchmark_Ctx_JSONP -benchmem -count=4
|
||||
|
@ -2914,11 +2895,6 @@ func Test_Ctx_SendStream(t *testing.T) {
|
|||
|
||||
c.SendStream(bufio.NewReader(bytes.NewReader([]byte("Hello bufio"))))
|
||||
require.Equal(t, "Hello bufio", string(c.Response().Body()))
|
||||
|
||||
file, err := os.Open("./.github/index.html")
|
||||
require.NoError(t, err)
|
||||
c.SendStream(bufio.NewReader(file))
|
||||
require.True(t, c.Response().Header.ContentLength() > 200)
|
||||
}
|
||||
|
||||
// go test -run Test_Ctx_Set
|
||||
|
|
|
@ -46,7 +46,7 @@ func Test_Utils_UniqueRouteStack(t *testing.T) {
|
|||
func Test_Utils_getGroupPath(t *testing.T) {
|
||||
t.Parallel()
|
||||
res := getGroupPath("/v1", "/")
|
||||
require.Equal(t, "/v1", res)
|
||||
require.Equal(t, "/v1/", res)
|
||||
|
||||
res = getGroupPath("/v1/", "/")
|
||||
require.Equal(t, "/v1/", res)
|
||||
|
|
|
@ -618,10 +618,11 @@ func Test_Cache_WithHead(t *testing.T) {
|
|||
app := fiber.New()
|
||||
app.Use(New())
|
||||
|
||||
app.Get("/", func(c fiber.Ctx) error {
|
||||
handler := func(c fiber.Ctx) error {
|
||||
now := fmt.Sprintf("%d", time.Now().UnixNano())
|
||||
return c.SendString(now)
|
||||
})
|
||||
}
|
||||
app.Route("/").Get(handler).Head(handler)
|
||||
|
||||
req := httptest.NewRequest("HEAD", "/", nil)
|
||||
resp, err := app.Test(req)
|
||||
|
@ -646,9 +647,11 @@ func Test_Cache_WithHeadThenGet(t *testing.T) {
|
|||
|
||||
app := fiber.New()
|
||||
app.Use(New())
|
||||
app.Get("/", func(c fiber.Ctx) error {
|
||||
|
||||
handler := func(c fiber.Ctx) error {
|
||||
return c.SendString(c.Query("cache"))
|
||||
})
|
||||
}
|
||||
app.Route("/").Get(handler).Head(handler)
|
||||
|
||||
headResp, err := app.Test(httptest.NewRequest("HEAD", "/?cache=123", nil))
|
||||
require.NoError(t, err)
|
||||
|
|
Loading…
Reference in New Issue