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

Function Test_Middleware_ResetWithContext

middleware/session/middleware_test.go:793–821  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

791}
792
793func Test_Middleware_ResetWithContext(t *testing.T) {
794 t.Parallel()
795
796 handler, store := NewWithStore()
797 app := fiber.New()
798 app.Use(handler)
799
800 app.Get("/reset", func(c fiber.Ctx) error {
801 sess := FromContext(c)
802 originalID := sess.ID()
803 sess.Set("key", "value")
804 if err := sess.ResetWithContext(t.Context()); err != nil {
805 return err
806 }
807 // Assert the actual effect: data is cleared and a new ID is issued.
808 if sess.ID() == originalID || sess.Get("key") != nil {
809 return c.SendStatus(fiber.StatusInternalServerError)
810 }
811 return c.SendStatus(fiber.StatusOK)
812 })
813
814 h := app.Handler()
815 ctx := &fasthttp.RequestCtx{}
816 ctx.Request.Header.SetMethod(fiber.MethodGet)
817 ctx.Request.SetRequestURI("/reset")
818 h(ctx)
819 require.Equal(t, fiber.StatusOK, ctx.Response.StatusCode())
820 _ = store
821}
822
823func Test_Middleware_RegenerateWithContext(t *testing.T) {
824 t.Parallel()

Callers

nothing calls this directly

Calls 13

NewWithStoreFunction · 0.85
HandlerMethod · 0.80
SetMethodMethod · 0.80
FromContextFunction · 0.70
NewMethod · 0.65
UseMethod · 0.65
GetMethod · 0.65
SetMethod · 0.65
ResetWithContextMethod · 0.65
ContextMethod · 0.65
SendStatusMethod · 0.65
IDMethod · 0.45

Tested by

no test coverage detected