frostfs-s3-gw/api/cache/objects_test.go
Denis Kirillov e3c16a32dd [#409] Update SDK
Signed-off-by: Denis Kirillov <denis@nspcc.ru>
2022-04-26 12:51:52 +04:00

45 lines
891 B
Go

package cache
import (
"testing"
"time"
"github.com/nspcc-dev/neofs-sdk-go/object/address"
objecttest "github.com/nspcc-dev/neofs-sdk-go/object/test"
"github.com/stretchr/testify/require"
)
func getTestConfig() *Config {
return &Config{
Size: 10,
Lifetime: 5 * time.Second,
}
}
func TestCache(t *testing.T) {
obj := objecttest.Object()
objID, _ := obj.ID()
cnrID, _ := obj.ContainerID()
addr := address.NewAddress()
addr.SetContainerID(cnrID)
addr.SetObjectID(objID)
t.Run("check get", func(t *testing.T) {
cache := New(getTestConfig())
err := cache.Put(*obj)
require.NoError(t, err)
actual := cache.Get(addr)
require.Equal(t, obj, actual)
})
t.Run("check delete", func(t *testing.T) {
cache := New(getTestConfig())
err := cache.Put(*obj)
require.NoError(t, err)
cache.Delete(addr)
actual := cache.Get(addr)
require.Nil(t, actual)
})
}