forked from TrueCloudLab/frostfs-s3-gw
parent
42a761c1f2
commit
dca7b5bc36
3 changed files with 22 additions and 15 deletions
16
api/cache/cache_test.go
vendored
16
api/cache/cache_test.go
vendored
|
@ -6,7 +6,6 @@ import (
|
|||
"github.com/nspcc-dev/neofs-s3-gw/api/data"
|
||||
"github.com/nspcc-dev/neofs-s3-gw/creds/accessbox"
|
||||
cidtest "github.com/nspcc-dev/neofs-sdk-go/container/id/test"
|
||||
"github.com/nspcc-dev/neofs-sdk-go/object"
|
||||
oid "github.com/nspcc-dev/neofs-sdk-go/object/id"
|
||||
oidtest "github.com/nspcc-dev/neofs-sdk-go/object/id/test"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
@ -72,19 +71,20 @@ func TestObjectCacheType(t *testing.T) {
|
|||
cache := New(DefaultObjectsConfig(logger))
|
||||
|
||||
addr := oidtest.Address()
|
||||
obj := object.New()
|
||||
obj.SetContainerID(addr.Container())
|
||||
obj.SetID(addr.Object())
|
||||
objInfo := &data.ObjectInfo{
|
||||
ID: addr.Object(),
|
||||
CID: addr.Container(),
|
||||
}
|
||||
|
||||
err := cache.Put(*obj)
|
||||
err := cache.PutObject(objInfo)
|
||||
require.NoError(t, err)
|
||||
val := cache.Get(addr)
|
||||
require.Equal(t, obj, val)
|
||||
val := cache.GetObject(addr)
|
||||
require.Equal(t, objInfo, val)
|
||||
require.Equal(t, 0, observedLog.Len())
|
||||
|
||||
err = cache.cache.Set(addr.EncodeToString(), "tmp")
|
||||
require.NoError(t, err)
|
||||
assertInvalidCacheEntry(t, cache.Get(addr), observedLog)
|
||||
assertInvalidCacheEntry(t, cache.GetObject(addr), observedLog)
|
||||
}
|
||||
|
||||
func TestObjectsListCacheType(t *testing.T) {
|
||||
|
|
16
api/cache/objects_test.go
vendored
16
api/cache/objects_test.go
vendored
|
@ -4,6 +4,7 @@ import (
|
|||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/nspcc-dev/neofs-s3-gw/api/data"
|
||||
oid "github.com/nspcc-dev/neofs-sdk-go/object/id"
|
||||
objecttest "github.com/nspcc-dev/neofs-sdk-go/object/test"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
@ -27,22 +28,27 @@ func TestCache(t *testing.T) {
|
|||
addr.SetContainer(cnrID)
|
||||
addr.SetObject(objID)
|
||||
|
||||
objInfo := &data.ObjectInfo{
|
||||
ID: addr.Object(),
|
||||
CID: addr.Container(),
|
||||
}
|
||||
|
||||
t.Run("check get", func(t *testing.T) {
|
||||
cache := New(getTestConfig())
|
||||
err := cache.Put(*obj)
|
||||
err := cache.PutObject(objInfo)
|
||||
require.NoError(t, err)
|
||||
|
||||
actual := cache.Get(addr)
|
||||
require.Equal(t, obj, actual)
|
||||
actual := cache.GetObject(addr)
|
||||
require.Equal(t, objInfo, actual)
|
||||
})
|
||||
|
||||
t.Run("check delete", func(t *testing.T) {
|
||||
cache := New(getTestConfig())
|
||||
err := cache.Put(*obj)
|
||||
err := cache.PutObject(objInfo)
|
||||
require.NoError(t, err)
|
||||
|
||||
cache.Delete(addr)
|
||||
actual := cache.Get(addr)
|
||||
actual := cache.GetObject(addr)
|
||||
require.Nil(t, actual)
|
||||
})
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@ func TestConditionalHead(t *testing.T) {
|
|||
require.NoError(t, err)
|
||||
|
||||
objName := "object"
|
||||
createTestObject(ctx, t, tc, bktInfo, objName)
|
||||
objInfo := createTestObject(ctx, t, tc, bktInfo, objName)
|
||||
|
||||
w, r := prepareTestRequest(t, bktName, objName, nil)
|
||||
tc.Handler().HeadObjectHandler(w, r)
|
||||
|
@ -41,7 +41,8 @@ func TestConditionalHead(t *testing.T) {
|
|||
assertStatus(t, w, http.StatusPreconditionFailed)
|
||||
|
||||
w, r = prepareTestRequest(t, bktName, objName, nil)
|
||||
r.Header.Set(api.IfUnmodifiedSince, time.Now().UTC().Format(http.TimeFormat))
|
||||
unmodifiedSince := objInfo.Created.Add(time.Minute)
|
||||
r.Header.Set(api.IfUnmodifiedSince, unmodifiedSince.Format(http.TimeFormat))
|
||||
tc.Handler().HeadObjectHandler(w, r)
|
||||
assertStatus(t, w, http.StatusOK)
|
||||
|
||||
|
|
Loading…
Reference in a new issue