mirror of https://github.com/gofiber/fiber.git
fix unhandled errors in app_test.go (#2071)
* fix unhandled errors
* fix unhandled error in cache package test
* omit variable type
* omit variable type
* rename variable because collide with the imported package name
* handle file error on closing
* fix unhandled in common_linux.go
* fix unhandled errors in helpers_test.go
* fix unhandled errors in listen_test.go
* remove unused parameter in emptyHandler method
* refactor path.go
* unhandled error in hooks test
* fix unhandled errors in app_test.go
* fix unhandled errors in ctx_test.go
* ✨ fix unhandled errors in helpers_test.go
* revert app_test.go
pull/2075/head
parent
87faeda5c1
commit
c8b1879b11
|
@ -1378,7 +1378,8 @@ func Test_App_New_Test_Parallel(t *testing.T) {
|
|||
t.Run("Test_App_New_Test_Parallel_2", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
app := New(Config{Immutable: true})
|
||||
app.Test(httptest.NewRequest("GET", "/", nil))
|
||||
_, err := app.Test(httptest.NewRequest("GET", "/", nil))
|
||||
utils.AssertEqual(t, nil, err)
|
||||
})
|
||||
}
|
||||
|
||||
|
|
27
ctx_test.go
27
ctx_test.go
|
@ -755,35 +755,42 @@ func Test_Ctx_Format(t *testing.T) {
|
|||
c := app.AcquireCtx(&fasthttp.RequestCtx{})
|
||||
defer app.ReleaseCtx(c)
|
||||
c.Request().Header.Set(HeaderAccept, MIMETextPlain)
|
||||
c.Format([]byte("Hello, World!"))
|
||||
err := c.Format([]byte("Hello, World!"))
|
||||
utils.AssertEqual(t, nil, err)
|
||||
utils.AssertEqual(t, "Hello, World!", string(c.Response().Body()))
|
||||
|
||||
c.Request().Header.Set(HeaderAccept, MIMETextHTML)
|
||||
c.Format("Hello, World!")
|
||||
err = c.Format("Hello, World!")
|
||||
utils.AssertEqual(t, nil, err)
|
||||
utils.AssertEqual(t, "<p>Hello, World!</p>", string(c.Response().Body()))
|
||||
|
||||
c.Request().Header.Set(HeaderAccept, MIMEApplicationJSON)
|
||||
c.Format("Hello, World!")
|
||||
err = c.Format("Hello, World!")
|
||||
utils.AssertEqual(t, nil, err)
|
||||
utils.AssertEqual(t, `"Hello, World!"`, string(c.Response().Body()))
|
||||
|
||||
c.Request().Header.Set(HeaderAccept, MIMETextPlain)
|
||||
c.Format(complex(1, 1))
|
||||
err = c.Format(complex(1, 1))
|
||||
utils.AssertEqual(t, nil, err)
|
||||
utils.AssertEqual(t, "(1+1i)", string(c.Response().Body()))
|
||||
|
||||
c.Request().Header.Set(HeaderAccept, MIMEApplicationXML)
|
||||
c.Format("Hello, World!")
|
||||
err = c.Format("Hello, World!")
|
||||
utils.AssertEqual(t, nil, err)
|
||||
utils.AssertEqual(t, `<string>Hello, World!</string>`, string(c.Response().Body()))
|
||||
|
||||
err := c.Format(complex(1, 1))
|
||||
err = c.Format(complex(1, 1))
|
||||
utils.AssertEqual(t, true, err != nil)
|
||||
|
||||
c.Request().Header.Set(HeaderAccept, MIMETextPlain)
|
||||
c.Format(Map{})
|
||||
err = c.Format(Map{})
|
||||
utils.AssertEqual(t, nil, err)
|
||||
utils.AssertEqual(t, "map[]", string(c.Response().Body()))
|
||||
|
||||
type broken string
|
||||
c.Request().Header.Set(HeaderAccept, "broken/accept")
|
||||
c.Format(broken("Hello, World!"))
|
||||
err = c.Format(broken("Hello, World!"))
|
||||
utils.AssertEqual(t, nil, err)
|
||||
utils.AssertEqual(t, `Hello, World!`, string(c.Response().Body()))
|
||||
}
|
||||
|
||||
|
@ -3137,8 +3144,8 @@ func Test_Ctx_Get_Location_From_Route_name(t *testing.T) {
|
|||
utils.AssertEqual(t, nil, err)
|
||||
utils.AssertEqual(t, "/user/fiber", location)
|
||||
})
|
||||
|
||||
t.Run("case sensitive",func(t *testing.T) {
|
||||
|
||||
t.Run("case sensitive", func(t *testing.T) {
|
||||
app := New(Config{CaseSensitive: true})
|
||||
c := app.AcquireCtx(&fasthttp.RequestCtx{})
|
||||
defer app.ReleaseCtx(c)
|
||||
|
|
|
@ -84,7 +84,8 @@ func Test_Utils_ETag_Weak(t *testing.T) {
|
|||
t.Run("Match Weak ETag", func(t *testing.T) {
|
||||
c := app.AcquireCtx(&fasthttp.RequestCtx{})
|
||||
defer app.ReleaseCtx(c)
|
||||
c.SendString("Hello, World!")
|
||||
err := c.SendString("Hello, World!")
|
||||
utils.AssertEqual(t, nil, err)
|
||||
c.Request().Header.Set(HeaderIfNoneMatch, `W/"13-1831710635"`)
|
||||
setETag(c, true)
|
||||
utils.AssertEqual(t, 304, c.Response().StatusCode())
|
||||
|
@ -95,7 +96,8 @@ func Test_Utils_ETag_Weak(t *testing.T) {
|
|||
t.Run("Not Match Weak ETag", func(t *testing.T) {
|
||||
c := app.AcquireCtx(&fasthttp.RequestCtx{})
|
||||
defer app.ReleaseCtx(c)
|
||||
c.SendString("Hello, World!")
|
||||
err := c.SendString("Hello, World!")
|
||||
utils.AssertEqual(t, nil, err)
|
||||
c.Request().Header.Set(HeaderIfNoneMatch, `W/"13-1831710635xx"`)
|
||||
setETag(c, true)
|
||||
utils.AssertEqual(t, `W/"13-1831710635"`, string(c.Response().Header.Peek(HeaderETag)))
|
||||
|
@ -135,7 +137,8 @@ func Benchmark_Utils_ETag_Weak(b *testing.B) {
|
|||
app := New()
|
||||
c := app.AcquireCtx(&fasthttp.RequestCtx{})
|
||||
defer app.ReleaseCtx(c)
|
||||
c.SendString("Hello, World!")
|
||||
err := c.SendString("Hello, World!")
|
||||
utils.AssertEqual(b, nil, err)
|
||||
for n := 0; n < b.N; n++ {
|
||||
setETag(c, true)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue