2021-08-14 22:03:20 +00:00
|
|
|
package cache
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
2022-05-25 17:25:43 +00:00
|
|
|
oid "github.com/nspcc-dev/neofs-sdk-go/object/id"
|
2021-11-15 12:56:16 +00:00
|
|
|
objecttest "github.com/nspcc-dev/neofs-sdk-go/object/test"
|
2021-08-14 22:03:20 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
2022-06-23 13:54:02 +00:00
|
|
|
"go.uber.org/zap"
|
2021-08-14 22:03:20 +00:00
|
|
|
)
|
|
|
|
|
2021-09-10 06:56:56 +00:00
|
|
|
func getTestConfig() *Config {
|
|
|
|
return &Config{
|
|
|
|
Size: 10,
|
|
|
|
Lifetime: 5 * time.Second,
|
2022-06-23 13:54:02 +00:00
|
|
|
Logger: zap.NewExample(),
|
2021-09-10 06:56:56 +00:00
|
|
|
}
|
|
|
|
}
|
2021-08-14 22:03:20 +00:00
|
|
|
|
|
|
|
func TestCache(t *testing.T) {
|
2021-08-18 13:48:58 +00:00
|
|
|
obj := objecttest.Object()
|
2022-04-25 09:57:58 +00:00
|
|
|
objID, _ := obj.ID()
|
|
|
|
cnrID, _ := obj.ContainerID()
|
2022-05-25 17:25:43 +00:00
|
|
|
|
|
|
|
var addr oid.Address
|
|
|
|
addr.SetContainer(cnrID)
|
|
|
|
addr.SetObject(objID)
|
2021-08-14 22:03:20 +00:00
|
|
|
|
|
|
|
t.Run("check get", func(t *testing.T) {
|
2021-09-10 06:56:56 +00:00
|
|
|
cache := New(getTestConfig())
|
2021-08-18 13:48:58 +00:00
|
|
|
err := cache.Put(*obj)
|
2021-08-14 22:03:20 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2022-02-08 16:54:04 +00:00
|
|
|
actual := cache.Get(addr)
|
2021-08-18 13:48:58 +00:00
|
|
|
require.Equal(t, obj, actual)
|
2021-08-14 22:03:20 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("check delete", func(t *testing.T) {
|
2021-09-10 06:56:56 +00:00
|
|
|
cache := New(getTestConfig())
|
2021-08-18 13:48:58 +00:00
|
|
|
err := cache.Put(*obj)
|
2021-08-14 22:03:20 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2022-02-08 16:54:04 +00:00
|
|
|
cache.Delete(addr)
|
|
|
|
actual := cache.Get(addr)
|
2021-08-14 22:03:20 +00:00
|
|
|
require.Nil(t, actual)
|
|
|
|
})
|
|
|
|
}
|