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/api/data"
|
||||||
"github.com/nspcc-dev/neofs-s3-gw/creds/accessbox"
|
"github.com/nspcc-dev/neofs-s3-gw/creds/accessbox"
|
||||||
cidtest "github.com/nspcc-dev/neofs-sdk-go/container/id/test"
|
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"
|
oid "github.com/nspcc-dev/neofs-sdk-go/object/id"
|
||||||
oidtest "github.com/nspcc-dev/neofs-sdk-go/object/id/test"
|
oidtest "github.com/nspcc-dev/neofs-sdk-go/object/id/test"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
@ -72,19 +71,20 @@ func TestObjectCacheType(t *testing.T) {
|
||||||
cache := New(DefaultObjectsConfig(logger))
|
cache := New(DefaultObjectsConfig(logger))
|
||||||
|
|
||||||
addr := oidtest.Address()
|
addr := oidtest.Address()
|
||||||
obj := object.New()
|
objInfo := &data.ObjectInfo{
|
||||||
obj.SetContainerID(addr.Container())
|
ID: addr.Object(),
|
||||||
obj.SetID(addr.Object())
|
CID: addr.Container(),
|
||||||
|
}
|
||||||
|
|
||||||
err := cache.Put(*obj)
|
err := cache.PutObject(objInfo)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
val := cache.Get(addr)
|
val := cache.GetObject(addr)
|
||||||
require.Equal(t, obj, val)
|
require.Equal(t, objInfo, val)
|
||||||
require.Equal(t, 0, observedLog.Len())
|
require.Equal(t, 0, observedLog.Len())
|
||||||
|
|
||||||
err = cache.cache.Set(addr.EncodeToString(), "tmp")
|
err = cache.cache.Set(addr.EncodeToString(), "tmp")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assertInvalidCacheEntry(t, cache.Get(addr), observedLog)
|
assertInvalidCacheEntry(t, cache.GetObject(addr), observedLog)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestObjectsListCacheType(t *testing.T) {
|
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"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/nspcc-dev/neofs-s3-gw/api/data"
|
||||||
oid "github.com/nspcc-dev/neofs-sdk-go/object/id"
|
oid "github.com/nspcc-dev/neofs-sdk-go/object/id"
|
||||||
objecttest "github.com/nspcc-dev/neofs-sdk-go/object/test"
|
objecttest "github.com/nspcc-dev/neofs-sdk-go/object/test"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
@ -27,22 +28,27 @@ func TestCache(t *testing.T) {
|
||||||
addr.SetContainer(cnrID)
|
addr.SetContainer(cnrID)
|
||||||
addr.SetObject(objID)
|
addr.SetObject(objID)
|
||||||
|
|
||||||
|
objInfo := &data.ObjectInfo{
|
||||||
|
ID: addr.Object(),
|
||||||
|
CID: addr.Container(),
|
||||||
|
}
|
||||||
|
|
||||||
t.Run("check get", func(t *testing.T) {
|
t.Run("check get", func(t *testing.T) {
|
||||||
cache := New(getTestConfig())
|
cache := New(getTestConfig())
|
||||||
err := cache.Put(*obj)
|
err := cache.PutObject(objInfo)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
actual := cache.Get(addr)
|
actual := cache.GetObject(addr)
|
||||||
require.Equal(t, obj, actual)
|
require.Equal(t, objInfo, actual)
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("check delete", func(t *testing.T) {
|
t.Run("check delete", func(t *testing.T) {
|
||||||
cache := New(getTestConfig())
|
cache := New(getTestConfig())
|
||||||
err := cache.Put(*obj)
|
err := cache.PutObject(objInfo)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
cache.Delete(addr)
|
cache.Delete(addr)
|
||||||
actual := cache.Get(addr)
|
actual := cache.GetObject(addr)
|
||||||
require.Nil(t, actual)
|
require.Nil(t, actual)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,7 @@ func TestConditionalHead(t *testing.T) {
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
objName := "object"
|
objName := "object"
|
||||||
createTestObject(ctx, t, tc, bktInfo, objName)
|
objInfo := createTestObject(ctx, t, tc, bktInfo, objName)
|
||||||
|
|
||||||
w, r := prepareTestRequest(t, bktName, objName, nil)
|
w, r := prepareTestRequest(t, bktName, objName, nil)
|
||||||
tc.Handler().HeadObjectHandler(w, r)
|
tc.Handler().HeadObjectHandler(w, r)
|
||||||
|
@ -41,7 +41,8 @@ func TestConditionalHead(t *testing.T) {
|
||||||
assertStatus(t, w, http.StatusPreconditionFailed)
|
assertStatus(t, w, http.StatusPreconditionFailed)
|
||||||
|
|
||||||
w, r = prepareTestRequest(t, bktName, objName, nil)
|
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)
|
tc.Handler().HeadObjectHandler(w, r)
|
||||||
assertStatus(t, w, http.StatusOK)
|
assertStatus(t, w, http.StatusOK)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue