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

Function Test_Session_Store_Reset

middleware/session/session_test.go:297–332  ·  view source on GitHub ↗

go test -run Test_Session_Store_Reset

(t *testing.T)

Source from the content-addressed store, hash-verified

295
296// go test -run Test_Session_Store_Reset
297func Test_Session_Store_Reset(t *testing.T) {
298 t.Parallel()
299 // session store
300 store := NewStore()
301 // fiber instance
302 app := fiber.New()
303 // fiber context
304 ctx := app.AcquireCtx(&fasthttp.RequestCtx{})
305
306 // get session
307 sess, err := store.Get(ctx)
308 require.NoError(t, err)
309 // make sure its new
310 require.True(t, sess.Fresh())
311 // set value & save
312 sess.Set("hello", "world")
313 ctx.Request().Header.SetCookie("session_id", sess.ID())
314 require.NoError(t, sess.Save())
315
316 // reset store
317 require.NoError(t, store.Reset(ctx))
318 id := sess.ID()
319
320 sess.Release()
321 app.ReleaseCtx(ctx)
322 ctx = app.AcquireCtx(&fasthttp.RequestCtx{})
323 defer app.ReleaseCtx(ctx)
324 ctx.Request().Header.SetCookie("session_id", id)
325
326 // make sure the session is recreated
327 sess, err = store.Get(ctx)
328 defer sess.Release()
329 require.NoError(t, err)
330 require.True(t, sess.Fresh())
331 require.Nil(t, sess.Get("hello"))
332}
333
334func Test_Session_KeyTypes(t *testing.T) {
335 // Note: This test cannot run in parallel because it registers types

Callers

nothing calls this directly

Calls 14

GetMethod · 0.95
ResetMethod · 0.95
NewStoreFunction · 0.85
AcquireCtxMethod · 0.80
ReleaseCtxMethod · 0.80
NewMethod · 0.65
FreshMethod · 0.65
SetMethod · 0.65
RequestMethod · 0.65
GetMethod · 0.65
SetCookieMethod · 0.45
IDMethod · 0.45

Tested by

no test coverage detected