Skip to content

Commit

Permalink
refactor(middleware/session): Add unit test for session middleware store
Browse files Browse the repository at this point in the history
  • Loading branch information
sixcolors committed Sep 13, 2024
1 parent b479895 commit afab580
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions middleware/session/middleware_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -441,3 +441,29 @@ func Test_Session_Next(t *testing.T) {
h(ctx)
require.Equal(t, fiber.StatusInternalServerError, ctx.Response.StatusCode())
}

func Test_Session_Middleware_Store(t *testing.T) {
t.Parallel()
app := fiber.New()

handler, sessionStore := NewWithStore()

app.Use(handler)

app.Get("/", func(c fiber.Ctx) error {
sess := FromContext(c)
st := sess.Store()
if st != sessionStore {
return c.SendStatus(fiber.StatusInternalServerError)
}
return c.SendStatus(fiber.StatusOK)
})

h := app.Handler()

// Test GET request
ctx := &fasthttp.RequestCtx{}
ctx.Request.Header.SetMethod(fiber.MethodGet)
h(ctx)
require.Equal(t, fiber.StatusOK, ctx.Response.StatusCode())
}

0 comments on commit afab580

Please sign in to comment.