2021-08-14 22:03:20 +00:00
|
|
|
package cache
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
2022-12-14 16:58:00 +00:00
|
|
|
"github.com/TrueCloudLab/frostfs-s3-gw/api/data"
|
|
|
|
oid "github.com/TrueCloudLab/frostfs-sdk-go/object/id"
|
|
|
|
objecttest "github.com/TrueCloudLab/frostfs-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
|
|
|
|
2022-08-08 22:32:33 +00:00
|
|
|
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,
|
2022-06-24 09:26:43 +00:00
|
|
|
}
|
|
|
|
|
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())
|
2022-08-08 22:32:33 +00:00
|
|
|
err := cache.PutObject(extObjInfo)
|
2021-08-14 22:03:20 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2022-06-24 09:26:43 +00:00
|
|
|
actual := cache.GetObject(addr)
|
2022-08-08 22:32:33 +00:00
|
|
|
require.Equal(t, extObjInfo, 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())
|
2022-08-08 22:32:33 +00:00
|
|
|
err := cache.PutObject(extObjInfo)
|
2021-08-14 22:03:20 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2022-02-08 16:54:04 +00:00
|
|
|
cache.Delete(addr)
|
2022-06-24 09:26:43 +00:00
|
|
|
actual := cache.GetObject(addr)
|
2021-08-14 22:03:20 +00:00
|
|
|
require.Nil(t, actual)
|
|
|
|
})
|
|
|
|
}
|