diff --git a/fiberzerolog/config.go b/fiberzerolog/config.go index 9fa1c199..443c97c2 100644 --- a/fiberzerolog/config.go +++ b/fiberzerolog/config.go @@ -4,8 +4,9 @@ import ( "os" "time" - "github.com/gofiber/fiber/v2" "github.com/rs/zerolog" + + "github.com/gofiber/fiber/v3" ) const ( @@ -38,23 +39,23 @@ type Config struct { // Next defines a function to skip this middleware when returned true. // // Optional. Default: nil - Next func(c *fiber.Ctx) bool + Next func(c fiber.Ctx) bool // SkipBody defines a function to skip log "body" field when returned true. // // Optional. Default: nil - SkipBody func(c *fiber.Ctx) bool + SkipBody func(c fiber.Ctx) bool // SkipResBody defines a function to skip log "resBody" field when returned true. // // Optional. Default: nil - SkipResBody func(c *fiber.Ctx) bool + SkipResBody func(c fiber.Ctx) bool // GetResBody defines a function to get ResBody. // eg: when use compress middleware, resBody is unreadable. you can set GetResBody func to get readable resBody. // // Optional. Default: nil - GetResBody func(c *fiber.Ctx) []byte + GetResBody func(c fiber.Ctx) []byte // Skip logging for these uri // @@ -72,7 +73,7 @@ type Config struct { // GetLogger will override Logger. // // Optional. Default: nil - GetLogger func(c *fiber.Ctx) zerolog.Logger + GetLogger func(c fiber.Ctx) zerolog.Logger // Add fields what you want see. // @@ -100,7 +101,7 @@ type Config struct { Levels []zerolog.Level } -func (c *Config) loggerCtx(fc *fiber.Ctx) zerolog.Context { +func (c *Config) loggerCtx(fc fiber.Ctx) zerolog.Context { if c.GetLogger != nil { return c.GetLogger(fc).With() } @@ -108,7 +109,7 @@ func (c *Config) loggerCtx(fc *fiber.Ctx) zerolog.Context { return c.Logger.With() } -func (c *Config) logger(fc *fiber.Ctx, latency time.Duration, err error) zerolog.Logger { +func (c *Config) logger(fc fiber.Ctx, latency time.Duration, err error) zerolog.Logger { zc := c.loggerCtx(fc) for _, field := range c.Fields { diff --git a/fiberzerolog/go.mod b/fiberzerolog/go.mod index 6f4039a5..8321597f 100644 --- a/fiberzerolog/go.mod +++ b/fiberzerolog/go.mod @@ -1,22 +1,25 @@ module github.com/gofiber/contrib/fiberzerolog -go 1.18 +go 1.21 require ( - github.com/gofiber/fiber/v2 v2.51.0 - github.com/rs/zerolog v1.31.0 + github.com/gofiber/fiber/v3 v3.0.0-beta.2 + github.com/rs/zerolog v1.33.0 + github.com/stretchr/testify v1.9.0 ) require ( - github.com/andybalholm/brotli v1.0.5 // indirect - github.com/google/uuid v1.4.0 // indirect - github.com/klauspost/compress v1.16.7 // indirect + github.com/andybalholm/brotli v1.1.0 // indirect + github.com/davecgh/go-spew v1.1.1 // indirect + github.com/gofiber/utils/v2 v2.0.0-beta.4 // indirect + github.com/google/uuid v1.6.0 // indirect + github.com/klauspost/compress v1.17.8 // indirect github.com/mattn/go-colorable v0.1.13 // indirect github.com/mattn/go-isatty v0.0.20 // indirect - github.com/mattn/go-runewidth v0.0.15 // indirect - github.com/rivo/uniseg v0.2.0 // indirect + github.com/pmezard/go-difflib v1.0.0 // indirect github.com/valyala/bytebufferpool v1.0.0 // indirect - github.com/valyala/fasthttp v1.50.0 // indirect + github.com/valyala/fasthttp v1.54.0 // indirect github.com/valyala/tcplisten v1.0.0 // indirect - golang.org/x/sys v0.14.0 // indirect + golang.org/x/sys v0.20.0 // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/fiberzerolog/go.sum b/fiberzerolog/go.sum index 6a7c93e5..5e6783df 100644 --- a/fiberzerolog/go.sum +++ b/fiberzerolog/go.sum @@ -1,35 +1,43 @@ -github.com/andybalholm/brotli v1.0.5 h1:8uQZIdzKmjc/iuPu7O2ioW48L81FgatrcpfFmiq/cCs= -github.com/andybalholm/brotli v1.0.5/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig= +github.com/andybalholm/brotli v1.1.0 h1:eLKJA0d02Lf0mVpIDgYnqXcUn0GqVmEFny3VuID1U3M= +github.com/andybalholm/brotli v1.1.0/go.mod h1:sms7XGricyQI9K10gOSf56VKKWS4oLer58Q+mhRPtnY= github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= -github.com/gofiber/fiber/v2 v2.51.0 h1:JNACcZy5e2tGApWB2QrRpenTWn0fq0hkFm6k0C86gKQ= -github.com/gofiber/fiber/v2 v2.51.0/go.mod h1:xaQRZQJGqnKOQnbQw+ltvku3/h8QxvNi8o6JiJ7Ll0U= -github.com/google/uuid v1.4.0 h1:MtMxsa51/r9yyhkyLsVeVt0B+BGQZzpQiTQ4eHZ8bc4= -github.com/google/uuid v1.4.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/klauspost/compress v1.16.7 h1:2mk3MPGNzKyxErAw8YaohYh69+pa4sIQSC0fPGCFR9I= -github.com/klauspost/compress v1.16.7/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE= +github.com/gofiber/fiber/v3 v3.0.0-beta.2 h1:mVVgt8PTaHGup3NGl/+7U7nEoZaXJ5OComV4E+HpAao= +github.com/gofiber/fiber/v3 v3.0.0-beta.2/go.mod h1:w7sdfTY0okjZ1oVH6rSOGvuACUIt0By1iK0HKUb3uqM= +github.com/gofiber/utils/v2 v2.0.0-beta.4 h1:1gjbVFFwVwUb9arPcqiB6iEjHBwo7cHsyS41NeIW3co= +github.com/gofiber/utils/v2 v2.0.0-beta.4/go.mod h1:sdRsPU1FXX6YiDGGxd+q2aPJRMzpsxdzCXo9dz+xtOY= +github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= +github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/klauspost/compress v1.17.8 h1:YcnTYrq7MikUT7k0Yb5eceMmALQPYBW/Xltxn0NAMnU= +github.com/klauspost/compress v1.17.8/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw= github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg= github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= -github.com/mattn/go-runewidth v0.0.15 h1:UNAjwbU9l54TA3KzvqLGxwWjHmMgBUVhBiTjelZgg3U= -github.com/mattn/go-runewidth v0.0.15/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= -github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY= -github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg= -github.com/rs/zerolog v1.31.0 h1:FcTR3NnLWW+NnTwwhFWiJSZr4ECLpqCm6QsEnyvbV4A= -github.com/rs/zerolog v1.31.0/go.mod h1:/7mN4D5sKwJLZQ2b/znpjC3/GQWY/xaDXUM0kKWRHss= +github.com/rs/zerolog v1.33.0 h1:1cU2KZkvPxNyfgEmhHAz/1A9Bz+llsdYzklWFzgp0r8= +github.com/rs/zerolog v1.33.0/go.mod h1:/7mN4D5sKwJLZQ2b/znpjC3/GQWY/xaDXUM0kKWRHss= +github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= +github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw= github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc= -github.com/valyala/fasthttp v1.50.0 h1:H7fweIlBm0rXLs2q0XbalvJ6r0CUPFWK3/bB4N13e9M= -github.com/valyala/fasthttp v1.50.0/go.mod h1:k2zXd82h/7UZc3VOdJ2WaUqt1uZ/XpXAfE9i+HBC3lA= +github.com/valyala/fasthttp v1.54.0 h1:cCL+ZZR3z3HPLMVfEYVUMtJqVaui0+gu7Lx63unHwS0= +github.com/valyala/fasthttp v1.54.0/go.mod h1:6dt4/8olwq9QARP/TDuPmWyWcl4byhpvTJ4AAtcz+QM= github.com/valyala/tcplisten v1.0.0 h1:rBHj/Xf+E1tRGZyWIWwJDiRY0zc1Js+CV5DqwacVSA8= github.com/valyala/tcplisten v1.0.0/go.mod h1:T0xQ8SeCZGxckz9qRXTfG43PvQ/mcWh7FwZEA7Ioqkc= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.14.0 h1:Vz7Qs629MkJkGyHxUlRHizWJRG2j8fbQKjELVSNhy7Q= -golang.org/x/sys v0.14.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y= +golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/fiberzerolog/zerolog.go b/fiberzerolog/zerolog.go index 6a328375..db43d397 100644 --- a/fiberzerolog/zerolog.go +++ b/fiberzerolog/zerolog.go @@ -3,8 +3,9 @@ package fiberzerolog import ( "time" - "github.com/gofiber/fiber/v2" "github.com/rs/zerolog" + + "github.com/gofiber/fiber/v3" ) // New creates a new middleware handler @@ -19,7 +20,7 @@ func New(config ...Config) fiber.Handler { } // Return new handler - return func(c *fiber.Ctx) error { + return func(c fiber.Ctx) error { // Don't execute middleware if Next returns true if cfg.Next != nil && cfg.Next(c) { return c.Next() diff --git a/fiberzerolog/zerolog_test.go b/fiberzerolog/zerolog_test.go index 64348dc9..0b1eb318 100644 --- a/fiberzerolog/zerolog_test.go +++ b/fiberzerolog/zerolog_test.go @@ -12,9 +12,10 @@ import ( "testing" "time" - "github.com/gofiber/fiber/v2" - "github.com/gofiber/fiber/v2/utils" "github.com/rs/zerolog" + "github.com/stretchr/testify/assert" + + "github.com/gofiber/fiber/v3" ) func Test_GetResBody(t *testing.T) { @@ -28,23 +29,23 @@ func Test_GetResBody(t *testing.T) { app := fiber.New() app.Use(New(Config{ Logger: &logger, - GetResBody: func(c *fiber.Ctx) []byte { + GetResBody: func(c fiber.Ctx) []byte { return []byte(readableResBody) }, Fields: []string{FieldResBody}, })) - app.Get("/", func(c *fiber.Ctx) error { + app.Get("/", func(c fiber.Ctx) error { return c.SendString("------this is unreadable resp------") }) _, err := app.Test(httptest.NewRequest("GET", "/", nil)) - utils.AssertEqual(t, nil, err) + assert.Equal(t, nil, err) var logs map[string]any _ = json.Unmarshal(buf.Bytes(), &logs) - utils.AssertEqual(t, readableResBody, logs[FieldResBody]) + assert.Equal(t, readableResBody, logs[FieldResBody]) } func Test_SkipBody(t *testing.T) { @@ -55,7 +56,7 @@ func Test_SkipBody(t *testing.T) { app := fiber.New() app.Use(New(Config{ - SkipBody: func(_ *fiber.Ctx) bool { + SkipBody: func(_ fiber.Ctx) bool { return true }, Logger: &logger, @@ -64,14 +65,14 @@ func Test_SkipBody(t *testing.T) { body := bytes.NewReader([]byte("this is test")) resp, err := app.Test(httptest.NewRequest("GET", "/", body)) - utils.AssertEqual(t, nil, err) - utils.AssertEqual(t, fiber.StatusNotFound, resp.StatusCode) + assert.Equal(t, nil, err) + assert.Equal(t, fiber.StatusNotFound, resp.StatusCode) var logs map[string]any _ = json.Unmarshal(buf.Bytes(), &logs) _, ok := logs[FieldBody] - utils.AssertEqual(t, false, ok) + assert.Equal(t, false, ok) } func Test_SkipResBody(t *testing.T) { @@ -82,7 +83,7 @@ func Test_SkipResBody(t *testing.T) { app := fiber.New() app.Use(New(Config{ - SkipResBody: func(_ *fiber.Ctx) bool { + SkipResBody: func(_ fiber.Ctx) bool { return true }, Logger: &logger, @@ -91,14 +92,14 @@ func Test_SkipResBody(t *testing.T) { body := bytes.NewReader([]byte("this is test")) resp, err := app.Test(httptest.NewRequest("GET", "/", body)) - utils.AssertEqual(t, nil, err) - utils.AssertEqual(t, fiber.StatusNotFound, resp.StatusCode) + assert.Equal(t, nil, err) + assert.Equal(t, fiber.StatusNotFound, resp.StatusCode) var logs map[string]any _ = json.Unmarshal(buf.Bytes(), &logs) _, ok := logs[FieldResBody] - utils.AssertEqual(t, false, ok) + assert.Equal(t, false, ok) } func Test_Logger(t *testing.T) { @@ -112,19 +113,19 @@ func Test_Logger(t *testing.T) { Logger: &logger, })) - app.Get("/", func(c *fiber.Ctx) error { + app.Get("/", func(c fiber.Ctx) error { return errors.New("some random error") }) resp, err := app.Test(httptest.NewRequest("GET", "/", nil)) - utils.AssertEqual(t, nil, err) - utils.AssertEqual(t, fiber.StatusInternalServerError, resp.StatusCode) + assert.Equal(t, nil, err) + assert.Equal(t, fiber.StatusInternalServerError, resp.StatusCode) var logs map[string]any _ = json.Unmarshal(buf.Bytes(), &logs) - utils.AssertEqual(t, "some random error", logs[FieldError]) - utils.AssertEqual(t, float64(500), logs[FieldStatus]) + assert.Equal(t, "some random error", logs[FieldError]) + assert.Equal(t, float64(500), logs[FieldStatus]) } func Test_Latency(t *testing.T) { @@ -138,22 +139,22 @@ func Test_Latency(t *testing.T) { Logger: &logger, })) - app.Get("/", func(c *fiber.Ctx) error { + app.Get("/", func(c fiber.Ctx) error { time.Sleep(100 * time.Millisecond) return c.SendStatus(fiber.StatusOK) }) resp, err := app.Test(httptest.NewRequest("GET", "/", nil)) - utils.AssertEqual(t, nil, err) - utils.AssertEqual(t, fiber.StatusOK, resp.StatusCode) + assert.Equal(t, nil, err) + assert.Equal(t, fiber.StatusOK, resp.StatusCode) var logs map[string]any _ = json.Unmarshal(buf.Bytes(), &logs) latencyStr, ok := logs[FieldLatency].(string) - utils.AssertEqual(t, true, ok) - utils.AssertEqual(t, true, strings.Contains(latencyStr, "ms")) - utils.AssertEqual(t, float64(200), logs[FieldStatus]) + assert.Equal(t, true, ok) + assert.Equal(t, true, strings.Contains(latencyStr, "ms")) + assert.Equal(t, float64(200), logs[FieldStatus]) } func Test_Logger_Next(t *testing.T) { @@ -161,14 +162,14 @@ func Test_Logger_Next(t *testing.T) { app := fiber.New() app.Use(New(Config{ - Next: func(_ *fiber.Ctx) bool { + Next: func(_ fiber.Ctx) bool { return true }, })) resp, err := app.Test(httptest.NewRequest("GET", "/", nil)) - utils.AssertEqual(t, nil, err) - utils.AssertEqual(t, fiber.StatusNotFound, resp.StatusCode) + assert.Equal(t, nil, err) + assert.Equal(t, fiber.StatusNotFound, resp.StatusCode) } func Test_Logger_All(t *testing.T) { @@ -197,14 +198,14 @@ func Test_Logger_All(t *testing.T) { }, })) - app.Get("/", func(c *fiber.Ctx) error { + app.Get("/", func(c fiber.Ctx) error { time.Sleep(100 * time.Millisecond) return c.SendStatus(fiber.StatusNotFound) }) resp, err := app.Test(httptest.NewRequest("GET", "/?foo=bar", nil)) - utils.AssertEqual(t, nil, err) - utils.AssertEqual(t, fiber.StatusNotFound, resp.StatusCode) + assert.Equal(t, nil, err) + assert.Equal(t, fiber.StatusNotFound, resp.StatusCode) expected := map[string]interface{}{ "body": "", @@ -215,7 +216,7 @@ func Test_Logger_All(t *testing.T) { "message": "Client error", "method": "GET", "route": "/", - "protocol": "http", + "protocol": "HTTP/1.1", "pid": float64(os.Getpid()), "queryParams": "foo=bar", "resBody": "Not Found", @@ -227,12 +228,12 @@ func Test_Logger_All(t *testing.T) { _ = json.Unmarshal(buf.Bytes(), &logs) for key, value := range expected { - utils.AssertEqual(t, value, logs[key]) + assert.Equal(t, value, logs[key]) } latencyStr, ok := logs[FieldLatency].(string) - utils.AssertEqual(t, true, ok) - utils.AssertEqual(t, true, strings.Contains(latencyStr, "ms")) + assert.Equal(t, true, ok) + assert.Equal(t, true, strings.Contains(latencyStr, "ms")) } func Test_Response_Body(t *testing.T) { @@ -249,17 +250,17 @@ func Test_Response_Body(t *testing.T) { expectedGetResponse := "Sample response body" - app.Get("/", func(c *fiber.Ctx) error { + app.Get("/", func(c fiber.Ctx) error { return c.SendString(expectedGetResponse) }) _, err := app.Test(httptest.NewRequest("GET", "/", nil)) - utils.AssertEqual(t, nil, err) + assert.Equal(t, nil, err) var logs map[string]any _ = json.Unmarshal(buf.Bytes(), &logs) - utils.AssertEqual(t, expectedGetResponse, logs[FieldResBody]) + assert.Equal(t, expectedGetResponse, logs[FieldResBody]) } func Test_Request_Id(t *testing.T) { @@ -276,19 +277,19 @@ func Test_Request_Id(t *testing.T) { requestID := "bf985e8e-6a32-42ec-8e50-05a21db8f0e4" - app.Get("/", func(c *fiber.Ctx) error { + app.Get("/", func(c fiber.Ctx) error { c.Response().Header.Set(fiber.HeaderXRequestID, requestID) return c.SendString("hello") }) resp, err := app.Test(httptest.NewRequest("GET", "/", nil)) - utils.AssertEqual(t, nil, err) - utils.AssertEqual(t, fiber.StatusOK, resp.StatusCode) + assert.Equal(t, nil, err) + assert.Equal(t, fiber.StatusOK, resp.StatusCode) var logs map[string]any _ = json.Unmarshal(buf.Bytes(), &logs) - utils.AssertEqual(t, requestID, logs[FieldRequestID]) + assert.Equal(t, requestID, logs[FieldRequestID]) } func Test_Skip_URIs(t *testing.T) { @@ -303,14 +304,14 @@ func Test_Skip_URIs(t *testing.T) { SkipURIs: []string{"/ignore_logging"}, })) - app.Get("/ignore_logging", func(c *fiber.Ctx) error { + app.Get("/ignore_logging", func(c fiber.Ctx) error { return errors.New("no log") }) resp, err := app.Test(httptest.NewRequest("GET", "/ignore_logging", nil)) - utils.AssertEqual(t, nil, err) - utils.AssertEqual(t, fiber.StatusInternalServerError, resp.StatusCode) - utils.AssertEqual(t, 0, buf.Len()) + assert.Equal(t, nil, err) + assert.Equal(t, fiber.StatusInternalServerError, resp.StatusCode) + assert.Equal(t, 0, buf.Len()) } func Test_Req_Headers(t *testing.T) { @@ -325,7 +326,7 @@ func Test_Req_Headers(t *testing.T) { Fields: []string{FieldReqHeaders}, })) - app.Get("/", func(c *fiber.Ctx) error { + app.Get("/", func(c fiber.Ctx) error { return c.SendString("hello") }) @@ -334,8 +335,8 @@ func Test_Req_Headers(t *testing.T) { req.Header.Add("baz", "foo") resp, err := app.Test(req) - utils.AssertEqual(t, nil, err) - utils.AssertEqual(t, fiber.StatusOK, resp.StatusCode) + assert.Equal(t, nil, err) + assert.Equal(t, fiber.StatusOK, resp.StatusCode) expected := map[string]interface{}{ "Host": "example.com", @@ -348,7 +349,7 @@ func Test_Req_Headers(t *testing.T) { var logs map[string]any _ = json.Unmarshal(buf.Bytes(), &logs) - utils.AssertEqual(t, expected, logs) + assert.Equal(t, expected, logs) } func Test_LoggerLevelsAndMessages(t *testing.T) { @@ -367,15 +368,15 @@ func Test_LoggerLevelsAndMessages(t *testing.T) { Levels: levels, })) - app.Get("/200", func(c *fiber.Ctx) error { + app.Get("/200", func(c fiber.Ctx) error { c.Status(fiber.StatusOK) return nil }) - app.Get("/400", func(c *fiber.Ctx) error { + app.Get("/400", func(c fiber.Ctx) error { c.Status(fiber.StatusBadRequest) return nil }) - app.Get("/500", func(c *fiber.Ctx) error { + app.Get("/500", func(c fiber.Ctx) error { c.Status(fiber.StatusInternalServerError) return nil }) @@ -413,14 +414,14 @@ func Test_LoggerLevelsAndMessages(t *testing.T) { buf.Reset() resp, err := app.Test(test.Req) - utils.AssertEqual(t, nil, err) - utils.AssertEqual(t, test.Status, resp.StatusCode) + assert.Equal(t, nil, err) + assert.Equal(t, test.Status, resp.StatusCode) var logs map[string]any _ = json.Unmarshal(buf.Bytes(), &logs) - utils.AssertEqual(t, test.Level, logs["level"]) - utils.AssertEqual(t, test.Message, logs["message"]) + assert.Equal(t, test.Level, logs["level"]) + assert.Equal(t, test.Message, logs["message"]) }) } } @@ -432,7 +433,7 @@ func Test_Logger_FromContext(t *testing.T) { app := fiber.New() app.Use(New(Config{ - GetLogger: func(c *fiber.Ctx) zerolog.Logger { + GetLogger: func(c fiber.Ctx) zerolog.Logger { return zerolog.New(&buf). With(). Str("foo", "bar"). @@ -441,10 +442,10 @@ func Test_Logger_FromContext(t *testing.T) { })) _, err := app.Test(httptest.NewRequest("GET", "/", nil)) - utils.AssertEqual(t, nil, err) + assert.Equal(t, nil, err) var logs map[string]any _ = json.Unmarshal(buf.Bytes(), &logs) - utils.AssertEqual(t, "bar", logs["foo"]) + assert.Equal(t, "bar", logs["foo"]) }