🧪 add benchmark to basicauth

pull/895/head
Fenny 2020-10-07 13:51:18 +02:00
parent b37789836d
commit e30d9dad39
1 changed files with 31 additions and 0 deletions

View File

@ -10,6 +10,7 @@ import (
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/utils"
"github.com/valyala/fasthttp"
)
// go test -run Test_BasicAuth_Next
@ -90,3 +91,33 @@ func Test_Middleware_BasicAuth(t *testing.T) {
}
}
}
// go test -v -run=^$ -bench=Benchmark_Middleware_BasicAuth -benchmem -count=4
func Benchmark_Middleware_BasicAuth(b *testing.B) {
app := fiber.New()
app.Use(New(Config{
Users: map[string]string{
"john": "doe",
},
}))
app.Get("/", func(c *fiber.Ctx) error {
return c.SendStatus(fiber.StatusTeapot)
})
h := app.Handler()
fctx := &fasthttp.RequestCtx{}
fctx.Request.Header.SetMethod("GET")
fctx.Request.SetRequestURI("/")
fctx.Request.Header.Set(fiber.HeaderAuthorization, "basic am9objpkb2U=") // john:doe
b.ReportAllocs()
b.ResetTimer()
for n := 0; n < b.N; n++ {
h(fctx)
}
utils.AssertEqual(b, fiber.StatusTeapot, fctx.Response.Header.StatusCode())
}