MCPcopy
hub / github.com/gofiber/fiber / Test_Integration_Domain_WithMiddleware

Function Test_Integration_Domain_WithMiddleware

app_integration_test.go:704–742  ·  view source on GitHub ↗

Integration tests for domain routing

(t *testing.T)

Source from the content-addressed store, hash-verified

702// Integration tests for domain routing
703
704func Test_Integration_Domain_WithMiddleware(t *testing.T) {
705 t.Parallel()
706
707 app := fiber.New()
708 app.Use(helmet.New())
709 app.Use(requestid.New())
710
711 // Domain-specific route with middleware
712 app.Domain("api.example.com").Get("/users", func(c fiber.Ctx) error {
713 return c.SendString("api users")
714 })
715
716 // Fallback route
717 app.Get("/users", func(c fiber.Ctx) error {
718 return c.SendString("default users")
719 })
720
721 // Test matching domain
722 req := httptest.NewRequest(http.MethodGet, "/users", http.NoBody)
723 req.Host = "api.example.com"
724 resp, err := app.Test(req)
725 require.NoError(t, err)
726 require.Equal(t, fiber.StatusOK, resp.StatusCode)
727 body, err := io.ReadAll(resp.Body)
728 require.NoError(t, err)
729 require.Equal(t, "api users", string(body))
730 require.NotEmpty(t, resp.Header.Get("X-Request-ID"))
731 require.Equal(t, "nosniff", resp.Header.Get(fiber.HeaderXContentTypeOptions))
732
733 // Test non-matching domain (fallback)
734 req = httptest.NewRequest(http.MethodGet, "/users", http.NoBody)
735 req.Host = "www.example.com"
736 resp, err = app.Test(req)
737 require.NoError(t, err)
738 require.Equal(t, fiber.StatusOK, resp.StatusCode)
739 body, err = io.ReadAll(resp.Body)
740 require.NoError(t, err)
741 require.Equal(t, "default users", string(body))
742}
743
744func Test_Integration_Domain_WithCORS(t *testing.T) {
745 t.Parallel()

Callers

nothing calls this directly

Calls 8

NewFunction · 0.92
NewFunction · 0.92
TestMethod · 0.80
NewMethod · 0.65
UseMethod · 0.65
GetMethod · 0.65
DomainMethod · 0.65
SendStringMethod · 0.65

Tested by

no test coverage detected