From dca7b5bc368915bc8587d0908110254b43f1bd2a Mon Sep 17 00:00:00 2001 From: Denis Kirillov Date: Fri, 24 Jun 2022 12:26:43 +0300 Subject: [PATCH] [#547] Fix tests Signed-off-by: Denis Kirillov --- api/cache/cache_test.go | 16 ++++++++-------- api/cache/objects_test.go | 16 +++++++++++----- api/handler/head_test.go | 5 +++-- 3 files changed, 22 insertions(+), 15 deletions(-) diff --git a/api/cache/cache_test.go b/api/cache/cache_test.go index 388b53d5a..4e97535fd 100644 --- a/api/cache/cache_test.go +++ b/api/cache/cache_test.go @@ -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) { diff --git a/api/cache/objects_test.go b/api/cache/objects_test.go index 2cbf1271d..ab53617d0 100644 --- a/api/cache/objects_test.go +++ b/api/cache/objects_test.go @@ -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) }) } diff --git a/api/handler/head_test.go b/api/handler/head_test.go index f6beb2729..ff6f3e73c 100644 --- a/api/handler/head_test.go +++ b/api/handler/head_test.go @@ -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)