Skip to content

Commit

Permalink
add ctx releases for the test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
ReneWerner87 committed Oct 23, 2024
1 parent f77fa8f commit b54c954
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion middleware/session/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ func Test_Store_getSessionID(t *testing.T) {
store := NewStore()
// fiber context
ctx := app.AcquireCtx(&fasthttp.RequestCtx{})
defer app.ReleaseCtx(ctx)

// set cookie
ctx.Request().Header.SetCookie(store.sessionName, expectedID)
Expand All @@ -38,6 +39,7 @@ func Test_Store_getSessionID(t *testing.T) {
})
// fiber context
ctx := app.AcquireCtx(&fasthttp.RequestCtx{})
defer app.ReleaseCtx(ctx)

// set header
ctx.Request().Header.Set(store.sessionName, expectedID)
Expand All @@ -53,6 +55,7 @@ func Test_Store_getSessionID(t *testing.T) {
})
// fiber context
ctx := app.AcquireCtx(&fasthttp.RequestCtx{})
defer app.ReleaseCtx(ctx)

// set url parameter
ctx.Request().SetRequestURI(fmt.Sprintf("/path?%s=%s", store.sessionName, expectedID))
Expand All @@ -76,6 +79,7 @@ func Test_Store_Get(t *testing.T) {
store := NewStore()
// fiber context
ctx := app.AcquireCtx(&fasthttp.RequestCtx{})
defer app.ReleaseCtx(ctx)

// set cookie
ctx.Request().Header.SetCookie(store.sessionName, unexpectedID)
Expand All @@ -97,6 +101,7 @@ func Test_Store_DeleteSession(t *testing.T) {

// fiber context
ctx := app.AcquireCtx(&fasthttp.RequestCtx{})
defer app.ReleaseCtx(ctx)

// Create a new session
session, err := store.Get(ctx)
Expand All @@ -123,6 +128,7 @@ func TestStore_Get_SessionAlreadyLoaded(t *testing.T) {

// Create a new context
ctx := app.AcquireCtx(&fasthttp.RequestCtx{})
defer app.ReleaseCtx(ctx)

// Mock middleware and set it in the context
middleware := &Middleware{}
Expand Down Expand Up @@ -178,10 +184,12 @@ func Test_Store_GetByID(t *testing.T) {

t.Run("valid session ID", func(t *testing.T) {
t.Parallel()
app := fiber.New()
// Create a new session
ctx := fiber.New().AcquireCtx(&fasthttp.RequestCtx{})
ctx := app.AcquireCtx(&fasthttp.RequestCtx{})
session, err := store.Get(ctx)
defer session.Release()
defer app.ReleaseCtx(ctx)
require.NoError(t, err)

// Save the session ID
Expand Down

0 comments on commit b54c954

Please sign in to comment.