2021-08-14 22:03:20 +00:00
|
|
|
package cache
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
2021-11-15 12:56:16 +00:00
|
|
|
"github.com/nspcc-dev/neofs-sdk-go/object"
|
|
|
|
objecttest "github.com/nspcc-dev/neofs-sdk-go/object/test"
|
2021-08-14 22:03:20 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
2021-09-10 06:56:56 +00:00
|
|
|
func getTestConfig() *Config {
|
|
|
|
return &Config{
|
|
|
|
Size: 10,
|
|
|
|
Lifetime: 5 * time.Second,
|
|
|
|
}
|
|
|
|
}
|
2021-08-14 22:03:20 +00:00
|
|
|
|
|
|
|
func TestCache(t *testing.T) {
|
2021-08-18 13:48:58 +00:00
|
|
|
obj := objecttest.Object()
|
|
|
|
address := object.NewAddress()
|
|
|
|
address.SetContainerID(obj.ContainerID())
|
|
|
|
address.SetObjectID(obj.ID())
|
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)
|
|
|
|
|
|
|
|
actual := cache.Get(address)
|
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)
|
|
|
|
|
|
|
|
cache.Delete(address)
|
|
|
|
actual := cache.Get(address)
|
|
|
|
require.Nil(t, actual)
|
|
|
|
})
|
|
|
|
}
|