forked from TrueCloudLab/frostfs-s3-gw
[#192] Add tests to make sure client_cut flag is passed to sdk
Signed-off-by: Denis Kirillov <d.kirillov@yadro.com>
This commit is contained in:
parent
6b1f365e65
commit
6b728fef87
9 changed files with 75 additions and 13 deletions
|
@ -17,7 +17,7 @@ func TestGetObjectPartsAttributes(t *testing.T) {
|
||||||
|
|
||||||
createTestBucket(hc, bktName)
|
createTestBucket(hc, bktName)
|
||||||
|
|
||||||
putObject(t, hc, bktName, objName)
|
putObject(hc, bktName, objName)
|
||||||
result := getObjectAttributes(hc, bktName, objName, objectParts)
|
result := getObjectAttributes(hc, bktName, objName, objectParts)
|
||||||
require.Nil(t, result.ObjectParts)
|
require.Nil(t, result.ObjectParts)
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,7 @@ func TestDeleteBucketOnAlreadyRemovedError(t *testing.T) {
|
||||||
bktName, objName := "bucket-for-removal", "object-to-delete"
|
bktName, objName := "bucket-for-removal", "object-to-delete"
|
||||||
bktInfo := createTestBucket(hc, bktName)
|
bktInfo := createTestBucket(hc, bktName)
|
||||||
|
|
||||||
putObject(t, hc, bktName, objName)
|
putObject(hc, bktName, objName)
|
||||||
|
|
||||||
addr := getAddressOfLastVersion(hc, bktInfo, objName)
|
addr := getAddressOfLastVersion(hc, bktInfo, objName)
|
||||||
hc.tp.SetObjectError(addr, &apistatus.ObjectAlreadyRemoved{})
|
hc.tp.SetObjectError(addr, &apistatus.ObjectAlreadyRemoved{})
|
||||||
|
@ -66,7 +66,7 @@ func TestDeleteBucketOnNotFoundError(t *testing.T) {
|
||||||
bktName, objName := "bucket-for-removal", "object-to-delete"
|
bktName, objName := "bucket-for-removal", "object-to-delete"
|
||||||
bktInfo := createTestBucket(hc, bktName)
|
bktInfo := createTestBucket(hc, bktName)
|
||||||
|
|
||||||
putObject(t, hc, bktName, objName)
|
putObject(hc, bktName, objName)
|
||||||
|
|
||||||
nodeVersion, err := hc.tree.GetUnversioned(hc.context, bktInfo, objName)
|
nodeVersion, err := hc.tree.GetUnversioned(hc.context, bktInfo, objName)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
@ -98,7 +98,7 @@ func TestDeleteObjectFromSuspended(t *testing.T) {
|
||||||
bktName, objName := "bucket-versioned-for-removal", "object-to-delete"
|
bktName, objName := "bucket-versioned-for-removal", "object-to-delete"
|
||||||
|
|
||||||
createSuspendedBucket(t, tc, bktName)
|
createSuspendedBucket(t, tc, bktName)
|
||||||
putObject(t, tc, bktName, objName)
|
putObject(tc, bktName, objName)
|
||||||
|
|
||||||
versionID, isDeleteMarker := deleteObject(t, tc, bktName, objName, emptyVersion)
|
versionID, isDeleteMarker := deleteObject(t, tc, bktName, objName, emptyVersion)
|
||||||
require.True(t, isDeleteMarker)
|
require.True(t, isDeleteMarker)
|
||||||
|
@ -255,7 +255,7 @@ func TestDeleteMarkerSuspended(t *testing.T) {
|
||||||
|
|
||||||
t.Run("remove last unversioned non delete marker", func(t *testing.T) {
|
t.Run("remove last unversioned non delete marker", func(t *testing.T) {
|
||||||
objName := "obj3"
|
objName := "obj3"
|
||||||
putObject(t, tc, bktName, objName)
|
putObject(tc, bktName, objName)
|
||||||
|
|
||||||
nodeVersion, err := tc.tree.GetUnversioned(tc.Context(), bktInfo, objName)
|
nodeVersion, err := tc.tree.GetUnversioned(tc.Context(), bktInfo, objName)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
@ -475,11 +475,11 @@ func getVersion(resp *ListObjectsVersionsResponse, objName string) []*ObjectVers
|
||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
|
||||||
func putObject(t *testing.T, tc *handlerContext, bktName, objName string) {
|
func putObject(hc *handlerContext, bktName, objName string) {
|
||||||
body := bytes.NewReader([]byte("content"))
|
body := bytes.NewReader([]byte("content"))
|
||||||
w, r := prepareTestPayloadRequest(tc, bktName, objName, body)
|
w, r := prepareTestPayloadRequest(hc, bktName, objName, body)
|
||||||
tc.Handler().PutObjectHandler(w, r)
|
hc.Handler().PutObjectHandler(w, r)
|
||||||
assertStatus(t, w, http.StatusOK)
|
assertStatus(hc.t, w, http.StatusOK)
|
||||||
}
|
}
|
||||||
|
|
||||||
func createSuspendedBucket(t *testing.T, tc *handlerContext, bktName string) *data.BucketInfo {
|
func createSuspendedBucket(t *testing.T, tc *handlerContext, bktName string) *data.BucketInfo {
|
||||||
|
|
|
@ -186,7 +186,7 @@ func TestGetObject(t *testing.T) {
|
||||||
bktName, objName := "bucket", "obj"
|
bktName, objName := "bucket", "obj"
|
||||||
bktInfo, objInfo := createVersionedBucketAndObject(hc.t, hc, bktName, objName)
|
bktInfo, objInfo := createVersionedBucketAndObject(hc.t, hc, bktName, objName)
|
||||||
|
|
||||||
putObject(hc.t, hc, bktName, objName)
|
putObject(hc, bktName, objName)
|
||||||
|
|
||||||
checkFound(hc.t, hc, bktName, objName, objInfo.VersionID())
|
checkFound(hc.t, hc, bktName, objName, objInfo.VersionID())
|
||||||
checkFound(hc.t, hc, bktName, objName, emptyVersion)
|
checkFound(hc.t, hc, bktName, objName, emptyVersion)
|
||||||
|
|
|
@ -38,6 +38,8 @@ type handlerContext struct {
|
||||||
tree *tree.Tree
|
tree *tree.Tree
|
||||||
context context.Context
|
context context.Context
|
||||||
kludge *kludgeSettingsMock
|
kludge *kludgeSettingsMock
|
||||||
|
|
||||||
|
layerFeatures *layer.FeatureSettingsMock
|
||||||
}
|
}
|
||||||
|
|
||||||
func (hc *handlerContext) Handler() *handler {
|
func (hc *handlerContext) Handler() *handler {
|
||||||
|
@ -123,11 +125,14 @@ func prepareHandlerContextBase(t *testing.T, minCache bool) *handlerContext {
|
||||||
cacheCfg = getMinCacheConfig(l)
|
cacheCfg = getMinCacheConfig(l)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
features := &layer.FeatureSettingsMock{}
|
||||||
|
|
||||||
layerCfg := &layer.Config{
|
layerCfg := &layer.Config{
|
||||||
Caches: cacheCfg,
|
Caches: cacheCfg,
|
||||||
AnonKey: layer.AnonymousKey{Key: key},
|
AnonKey: layer.AnonymousKey{Key: key},
|
||||||
Resolver: testResolver,
|
Resolver: testResolver,
|
||||||
TreeService: treeMock,
|
TreeService: treeMock,
|
||||||
|
Features: features,
|
||||||
}
|
}
|
||||||
|
|
||||||
var pp netmap.PlacementPolicy
|
var pp netmap.PlacementPolicy
|
||||||
|
@ -154,6 +159,8 @@ func prepareHandlerContextBase(t *testing.T, minCache bool) *handlerContext {
|
||||||
tree: treeMock,
|
tree: treeMock,
|
||||||
context: middleware.SetBoxData(context.Background(), newTestAccessBox(t, key)),
|
context: middleware.SetBoxData(context.Background(), newTestAccessBox(t, key)),
|
||||||
kludge: kludge,
|
kludge: kludge,
|
||||||
|
|
||||||
|
layerFeatures: features,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -114,7 +114,7 @@ func TestHeadObject(t *testing.T) {
|
||||||
bktName, objName := "bucket", "obj"
|
bktName, objName := "bucket", "obj"
|
||||||
bktInfo, objInfo := createVersionedBucketAndObject(hc.t, hc, bktName, objName)
|
bktInfo, objInfo := createVersionedBucketAndObject(hc.t, hc, bktName, objName)
|
||||||
|
|
||||||
putObject(hc.t, hc, bktName, objName)
|
putObject(hc, bktName, objName)
|
||||||
|
|
||||||
checkFound(hc.t, hc, bktName, objName, objInfo.VersionID())
|
checkFound(hc.t, hc, bktName, objName, objInfo.VersionID())
|
||||||
checkFound(hc.t, hc, bktName, objName, emptyVersion)
|
checkFound(hc.t, hc, bktName, objName, emptyVersion)
|
||||||
|
|
|
@ -536,7 +536,7 @@ func TestPutObjectWithLock(t *testing.T) {
|
||||||
createTestBucketWithLock(hc, bktName, lockConfig)
|
createTestBucketWithLock(hc, bktName, lockConfig)
|
||||||
|
|
||||||
objDefault := "obj-default-retention"
|
objDefault := "obj-default-retention"
|
||||||
putObject(t, hc, bktName, objDefault)
|
putObject(hc, bktName, objDefault)
|
||||||
|
|
||||||
getObjectRetentionApproximate(hc, bktName, objDefault, governanceMode, time.Now().Add(24*time.Hour))
|
getObjectRetentionApproximate(hc, bktName, objDefault, governanceMode, time.Now().Add(24*time.Hour))
|
||||||
getObjectLegalHold(hc, bktName, objDefault, legalHoldOff)
|
getObjectLegalHold(hc, bktName, objDefault, legalHoldOff)
|
||||||
|
@ -587,7 +587,7 @@ func TestPutLockErrors(t *testing.T) {
|
||||||
headers[api.AmzObjectLockRetainUntilDate] = "dummy"
|
headers[api.AmzObjectLockRetainUntilDate] = "dummy"
|
||||||
putObjectWithLockFailed(t, hc, bktName, objName, headers, apiErrors.ErrInvalidRetentionDate)
|
putObjectWithLockFailed(t, hc, bktName, objName, headers, apiErrors.ErrInvalidRetentionDate)
|
||||||
|
|
||||||
putObject(t, hc, bktName, objName)
|
putObject(hc, bktName, objName)
|
||||||
|
|
||||||
retention := &data.Retention{Mode: governanceMode}
|
retention := &data.Retention{Mode: governanceMode}
|
||||||
putObjectRetentionFailed(t, hc, bktName, objName, retention, apiErrors.ErrMalformedXML)
|
putObjectRetentionFailed(t, hc, bktName, objName, retention, apiErrors.ErrMalformedXML)
|
||||||
|
|
|
@ -23,6 +23,7 @@ import (
|
||||||
"git.frostfs.info/TrueCloudLab/frostfs-s3-gw/api/layer"
|
"git.frostfs.info/TrueCloudLab/frostfs-s3-gw/api/layer"
|
||||||
"git.frostfs.info/TrueCloudLab/frostfs-s3-gw/api/middleware"
|
"git.frostfs.info/TrueCloudLab/frostfs-s3-gw/api/middleware"
|
||||||
"git.frostfs.info/TrueCloudLab/frostfs-s3-gw/creds/accessbox"
|
"git.frostfs.info/TrueCloudLab/frostfs-s3-gw/creds/accessbox"
|
||||||
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object"
|
||||||
"github.com/aws/aws-sdk-go/aws/credentials"
|
"github.com/aws/aws-sdk-go/aws/credentials"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
@ -309,3 +310,37 @@ func TestCreateBucket(t *testing.T) {
|
||||||
box2, _ := createAccessBox(t)
|
box2, _ := createAccessBox(t)
|
||||||
createBucketAssertS3Error(hc, bktName, box2, s3errors.ErrBucketAlreadyExists)
|
createBucketAssertS3Error(hc, bktName, box2, s3errors.ErrBucketAlreadyExists)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestPutObjectClientCut(t *testing.T) {
|
||||||
|
hc := prepareHandlerContext(t)
|
||||||
|
bktName, objName1, objName2 := "bkt-name", "obj-name1", "obj-name2"
|
||||||
|
createTestBucket(hc, bktName)
|
||||||
|
|
||||||
|
putObject(hc, bktName, objName1)
|
||||||
|
obj1 := getObjectFromLayer(hc, objName1)[0]
|
||||||
|
require.Empty(t, getObjectAttribute(obj1, "s3-client-cut"))
|
||||||
|
|
||||||
|
hc.layerFeatures.SetClientCut(true)
|
||||||
|
putObject(hc, bktName, objName2)
|
||||||
|
obj2 := getObjectFromLayer(hc, objName2)[0]
|
||||||
|
require.Equal(t, "true", getObjectAttribute(obj2, "s3-client-cut"))
|
||||||
|
}
|
||||||
|
|
||||||
|
func getObjectFromLayer(hc *handlerContext, objName string) []*object.Object {
|
||||||
|
var res []*object.Object
|
||||||
|
for _, o := range hc.tp.Objects() {
|
||||||
|
if objName == getObjectAttribute(o, object.AttributeFilePath) {
|
||||||
|
res = append(res, o)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return res
|
||||||
|
}
|
||||||
|
|
||||||
|
func getObjectAttribute(obj *object.Object, attrName string) string {
|
||||||
|
for _, attr := range obj.Attributes() {
|
||||||
|
if attr.Key() == attrName {
|
||||||
|
return attr.Value()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
|
@ -25,6 +25,18 @@ import (
|
||||||
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type FeatureSettingsMock struct {
|
||||||
|
clientCut bool
|
||||||
|
}
|
||||||
|
|
||||||
|
func (k *FeatureSettingsMock) ClientCut() bool {
|
||||||
|
return k.clientCut
|
||||||
|
}
|
||||||
|
|
||||||
|
func (k *FeatureSettingsMock) SetClientCut(clientCut bool) {
|
||||||
|
k.clientCut = clientCut
|
||||||
|
}
|
||||||
|
|
||||||
type TestFrostFS struct {
|
type TestFrostFS struct {
|
||||||
FrostFS
|
FrostFS
|
||||||
|
|
||||||
|
@ -222,6 +234,13 @@ func (t *TestFrostFS) CreateObject(_ context.Context, prm PrmObjectCreate) (oid.
|
||||||
attrs = append(attrs, *a)
|
attrs = append(attrs, *a)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if prm.ClientCut {
|
||||||
|
a := object.NewAttribute()
|
||||||
|
a.SetKey("s3-client-cut")
|
||||||
|
a.SetValue("true")
|
||||||
|
attrs = append(attrs, *a)
|
||||||
|
}
|
||||||
|
|
||||||
for i := range prm.Attributes {
|
for i := range prm.Attributes {
|
||||||
a := object.NewAttribute()
|
a := object.NewAttribute()
|
||||||
a.SetKey(prm.Attributes[i][0])
|
a.SetKey(prm.Attributes[i][0])
|
||||||
|
|
|
@ -170,6 +170,7 @@ func prepareContext(t *testing.T, cachesConfig ...*CachesConfig) *testContext {
|
||||||
Caches: config,
|
Caches: config,
|
||||||
AnonKey: AnonymousKey{Key: key},
|
AnonKey: AnonymousKey{Key: key},
|
||||||
TreeService: NewTreeService(),
|
TreeService: NewTreeService(),
|
||||||
|
Features: &FeatureSettingsMock{},
|
||||||
}
|
}
|
||||||
|
|
||||||
return &testContext{
|
return &testContext{
|
||||||
|
|
Loading…
Reference in a new issue