fiber/middleware/cache/manager_test.go
M. Efe Çetin 192d1dff0d
feat: add context methods to fiber.Storage interface (#3566)
* feat: add context methods to fiber.Storage interface

* fix linter

* create new file for storage interface (storage_interface.go)

* add simple context check to internal storage

* update docs

* add fallback context for session

---------

Co-authored-by: René <rene@gofiber.io>
2025-07-18 03:19:50 +02:00

28 lines
661 B
Go

package cache
import (
"context"
"testing"
"time"
"github.com/gofiber/utils/v2"
"github.com/stretchr/testify/assert"
)
func Test_manager_get(t *testing.T) {
t.Parallel()
cacheManager := newManager(nil)
t.Run("Item not found in cache", func(t *testing.T) {
t.Parallel()
assert.Nil(t, cacheManager.get(context.Background(), utils.UUID()))
})
t.Run("Item found in cache", func(t *testing.T) {
t.Parallel()
id := utils.UUID()
cacheItem := cacheManager.acquire()
cacheItem.body = []byte("test-body")
cacheManager.set(context.Background(), id, cacheItem, 10*time.Second)
assert.NotNil(t, cacheManager.get(context.Background(), id))
})
}