diff --git a/contrib/gofiber/fiber.v2/fiber_test.go b/contrib/gofiber/fiber.v2/fiber_test.go index 6bd0fb786b..05a9eb8bf4 100644 --- a/contrib/gofiber/fiber.v2/fiber_test.go +++ b/contrib/gofiber/fiber.v2/fiber_test.go @@ -6,6 +6,7 @@ package fiber import ( + "context" "fmt" "net/http" "net/http/httptest" @@ -178,11 +179,28 @@ func TestUserContext(t *testing.T) { // setup router := fiber.New() + + // define a custom context key + type contextKey string + const fooKey contextKey = "foo" + + router.Use(func(c *fiber.Ctx) error { + ctx := context.WithValue(context.Background(), fooKey, "bar") + c.SetUserContext(ctx) + return c.Next() + }) + + // add the middleware router.Use(Middleware(WithServiceName("foobar"))) router.Get("/", func(c *fiber.Ctx) error { // check if not default empty context assert.NotEmpty(c.UserContext()) + + // checks that the user context still has the information provided before using the middleware + _, ok := c.UserContext().Value(fooKey).(string) + assert.True(ok) + span, _ := tracer.StartSpanFromContext(c.UserContext(), "http.request") defer span.Finish() return c.SendString("test")