|
| 1 | +package middleware |
| 2 | + |
| 3 | +import ( |
| 4 | + "net/http/httptest" |
| 5 | + "testing" |
| 6 | + |
| 7 | + "github.com/gofiber/fiber" |
| 8 | + "github.com/gofiber/utils" |
| 9 | +) |
| 10 | + |
| 11 | +// go test -run Test_Middleware_Favicon |
| 12 | +func Test_Middleware_Favicon(t *testing.T) { |
| 13 | + app := fiber.New() |
| 14 | + |
| 15 | + app.Use(Favicon()) |
| 16 | + |
| 17 | + app.Get("/", func(ctx *fiber.Ctx) { |
| 18 | + ctx.Send("Hello?") |
| 19 | + }) |
| 20 | + |
| 21 | + resp, err := app.Test(httptest.NewRequest("GET", "/favicon.ico", nil)) |
| 22 | + utils.AssertEqual(t, nil, err, "app.Test(req)") |
| 23 | + utils.AssertEqual(t, 204, resp.StatusCode, "Status code") |
| 24 | + |
| 25 | + resp, err = app.Test(httptest.NewRequest("OPTIONS", "/favicon.ico", nil)) |
| 26 | + utils.AssertEqual(t, nil, err, "app.Test(req)") |
| 27 | + utils.AssertEqual(t, 200, resp.StatusCode, "Status code") |
| 28 | + |
| 29 | + resp, err = app.Test(httptest.NewRequest("PUT", "/favicon.ico", nil)) |
| 30 | + utils.AssertEqual(t, nil, err, "app.Test(req)") |
| 31 | + utils.AssertEqual(t, 405, resp.StatusCode, "Status code") |
| 32 | + utils.AssertEqual(t, "GET, HEAD, OPTIONS", resp.Header.Get(fiber.HeaderAllow)) |
| 33 | +} |
0 commit comments