frostfs-s3-gw/api/cache/objects_test.go
Alex Vanin 813aa2f173 Rename package name
Due to source code relocation from GitHub.

Signed-off-by: Alex Vanin <a.vanin@yadro.com>
2023-03-07 17:38:08 +03:00

64 lines
1.3 KiB
Go

package cache
import (
"testing"
"time"
"git.frostfs.info/TrueCloudLab/frostfs-s3-gw/api/data"
oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id"
objecttest "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/test"
"github.com/stretchr/testify/require"
"go.uber.org/zap"
)
func getTestConfig() *Config {
return &Config{
Size: 10,
Lifetime: 5 * time.Second,
Logger: zap.NewExample(),
}
}
func TestCache(t *testing.T) {
obj := objecttest.Object()
objID, _ := obj.ID()
cnrID, _ := obj.ContainerID()
var addr oid.Address
addr.SetContainer(cnrID)
addr.SetObject(objID)
extObjInfo := &data.ExtendedObjectInfo{
ObjectInfo: &data.ObjectInfo{
ID: addr.Object(),
CID: addr.Container(),
},
NodeVersion: &data.NodeVersion{
BaseNodeVersion: data.BaseNodeVersion{
FilePath: "obj",
Size: 50,
},
IsUnversioned: true,
},
IsLatest: true,
}
t.Run("check get", func(t *testing.T) {
cache := New(getTestConfig())
err := cache.PutObject(extObjInfo)
require.NoError(t, err)
actual := cache.GetObject(addr)
require.Equal(t, extObjInfo, actual)
})
t.Run("check delete", func(t *testing.T) {
cache := New(getTestConfig())
err := cache.PutObject(extObjInfo)
require.NoError(t, err)
cache.Delete(addr)
actual := cache.GetObject(addr)
require.Nil(t, actual)
})
}