mirror of
https://github.com/gofiber/fiber.git
synced 2025-02-24 18:44:03 +00:00
🔥 Feature: add proper tests for new logger variables
This commit is contained in:
parent
7c36b32194
commit
9c18716885
@ -137,15 +137,37 @@ func Test_Logger_All(t *testing.T) {
|
|||||||
|
|
||||||
app := fiber.New()
|
app := fiber.New()
|
||||||
app.Use(New(Config{
|
app.Use(New(Config{
|
||||||
Format: "${pid}${referer}${protocol}${ip}${ips}${host}${url}${ua}${body}${resBody}${queryParams}${route}${black}${red}${green}${yellow}${blue}${magenta}${cyan}${white}${reset}${error}${header:test}${query:test}${form:test}${cookie:test}${non}",
|
Format: "${pid}${referer}${protocol}${ip}${ips}${host}${url}${ua}${body}${route}${black}${red}${green}${yellow}${blue}${magenta}${cyan}${white}${reset}${error}${header:test}${query:test}${form:test}${cookie:test}${non}",
|
||||||
Output: buf,
|
Output: buf,
|
||||||
}))
|
}))
|
||||||
|
|
||||||
resp, err := app.Test(httptest.NewRequest("GET", "/", nil))
|
resp, err := app.Test(httptest.NewRequest("GET", "/?foo=bar", nil))
|
||||||
utils.AssertEqual(t, nil, err)
|
utils.AssertEqual(t, nil, err)
|
||||||
utils.AssertEqual(t, fiber.StatusNotFound, resp.StatusCode)
|
utils.AssertEqual(t, fiber.StatusNotFound, resp.StatusCode)
|
||||||
|
|
||||||
expected := fmt.Sprintf("%dhttp0.0.0.0example.com//%s%s%s%s%s%s%s%s%s-", os.Getpid(), cBlack, cRed, cGreen, cYellow, cBlue, cMagenta, cCyan, cWhite, cReset)
|
expected := fmt.Sprintf("%dhttp0.0.0.0example.com/?foo=bar/%s%s%s%s%s%s%s%s%s-", os.Getpid(), cBlack, cRed, cGreen, cYellow, cBlue, cMagenta, cCyan, cWhite, cReset)
|
||||||
|
utils.AssertEqual(t, expected, buf.String())
|
||||||
|
}
|
||||||
|
|
||||||
|
// go test -run Test_Query_Params_Response_Body
|
||||||
|
func Test_Query_Params(t *testing.T) {
|
||||||
|
buf := bytebufferpool.Get()
|
||||||
|
defer bytebufferpool.Put(buf)
|
||||||
|
|
||||||
|
app := fiber.New()
|
||||||
|
app.Use(New(Config{
|
||||||
|
Format: "${queryParams}${resBody}",
|
||||||
|
Output: buf,
|
||||||
|
}))
|
||||||
|
|
||||||
|
app.Get("/", func(c *fiber.Ctx) error {
|
||||||
|
return c.SendString("Sample response body")
|
||||||
|
})
|
||||||
|
|
||||||
|
_, err := app.Test(httptest.NewRequest("GET", "/?foo=bar&baz=moz", nil))
|
||||||
|
utils.AssertEqual(t, nil, err)
|
||||||
|
|
||||||
|
expected := fmt.Sprintf("foo=bar&baz=mozSample response body")
|
||||||
utils.AssertEqual(t, expected, buf.String())
|
utils.AssertEqual(t, expected, buf.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user