2021-08-13 14:13:14 +00:00
|
|
|
package layer
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"context"
|
2023-07-06 13:37:53 +00:00
|
|
|
"io"
|
2021-08-13 14:13:14 +00:00
|
|
|
"testing"
|
|
|
|
|
2023-03-07 14:38:08 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-s3-gw/api/data"
|
2023-07-05 14:05:45 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-s3-gw/api/middleware"
|
2023-03-07 14:38:08 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-s3-gw/creds/accessbox"
|
|
|
|
bearertest "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/bearer/test"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object"
|
|
|
|
oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id"
|
2023-10-25 13:35:23 +00:00
|
|
|
oidtest "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id/test"
|
2023-03-07 14:38:08 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/user"
|
2021-08-13 14:13:14 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
|
|
|
"github.com/stretchr/testify/require"
|
2022-03-22 10:22:00 +00:00
|
|
|
"go.uber.org/zap"
|
2021-08-13 14:13:14 +00:00
|
|
|
)
|
|
|
|
|
2021-09-10 06:56:56 +00:00
|
|
|
func (tc *testContext) putObject(content []byte) *data.ObjectInfo {
|
2022-10-14 14:36:43 +00:00
|
|
|
extObjInfo, err := tc.layer.PutObject(tc.ctx, &PutObjectParams{
|
2022-03-18 13:04:09 +00:00
|
|
|
BktInfo: tc.bktInfo,
|
|
|
|
Object: tc.obj,
|
2024-09-12 15:48:00 +00:00
|
|
|
Size: ptr(uint64(len(content))),
|
2022-03-18 13:04:09 +00:00
|
|
|
Reader: bytes.NewReader(content),
|
|
|
|
Header: make(map[string]string),
|
2021-08-13 14:13:14 +00:00
|
|
|
})
|
|
|
|
require.NoError(tc.t, err)
|
|
|
|
|
2022-10-14 14:36:43 +00:00
|
|
|
return extObjInfo.ObjectInfo
|
2021-08-13 14:13:14 +00:00
|
|
|
}
|
|
|
|
|
2021-09-10 06:56:56 +00:00
|
|
|
func (tc *testContext) getObject(objectName, versionID string, needError bool) (*data.ObjectInfo, []byte) {
|
2023-07-06 13:37:53 +00:00
|
|
|
headPrm := &HeadObjectParams{
|
2022-03-18 13:04:09 +00:00
|
|
|
BktInfo: tc.bktInfo,
|
2021-08-13 14:13:14 +00:00
|
|
|
Object: objectName,
|
|
|
|
VersionID: versionID,
|
2023-07-06 13:37:53 +00:00
|
|
|
}
|
|
|
|
objInfo, err := tc.layer.GetObjectInfo(tc.ctx, headPrm)
|
2021-08-13 14:13:14 +00:00
|
|
|
if needError {
|
|
|
|
require.Error(tc.t, err)
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
require.NoError(tc.t, err)
|
|
|
|
|
2023-07-06 13:37:53 +00:00
|
|
|
objPayload, err := tc.layer.GetObject(tc.ctx, &GetObjectParams{
|
2022-08-05 00:54:21 +00:00
|
|
|
ObjectInfo: objInfo,
|
2023-07-06 13:37:53 +00:00
|
|
|
Versioned: headPrm.Versioned(),
|
2022-06-02 17:01:00 +00:00
|
|
|
BucketInfo: tc.bktInfo,
|
2021-08-13 14:13:14 +00:00
|
|
|
})
|
|
|
|
require.NoError(tc.t, err)
|
|
|
|
|
2023-07-06 13:37:53 +00:00
|
|
|
payload, err := io.ReadAll(objPayload)
|
|
|
|
require.NoError(tc.t, err)
|
|
|
|
|
|
|
|
return objInfo, payload
|
2021-08-13 14:13:14 +00:00
|
|
|
}
|
|
|
|
|
2022-06-24 12:39:30 +00:00
|
|
|
func (tc *testContext) deleteObject(objectName, versionID string, settings *data.BucketSettings) {
|
2022-03-31 06:24:29 +00:00
|
|
|
p := &DeleteObjectParams{
|
2022-06-24 12:39:30 +00:00
|
|
|
BktInfo: tc.bktInfo,
|
|
|
|
Settings: settings,
|
2022-03-31 06:24:29 +00:00
|
|
|
Objects: []*VersionedObject{
|
|
|
|
{Name: objectName, VersionID: versionID},
|
|
|
|
},
|
|
|
|
}
|
2022-06-24 12:39:30 +00:00
|
|
|
deletedObjects := tc.layer.DeleteObjects(tc.ctx, p)
|
2021-09-07 06:17:12 +00:00
|
|
|
for _, obj := range deletedObjects {
|
|
|
|
require.NoError(tc.t, obj.Error)
|
2021-08-13 14:13:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-01-22 07:01:24 +00:00
|
|
|
func (tc *testContext) listObjectsV1() []*data.ExtendedNodeVersion {
|
2021-08-13 14:13:14 +00:00
|
|
|
res, err := tc.layer.ListObjectsV1(tc.ctx, &ListObjectsParamsV1{
|
|
|
|
ListObjectsParamsCommon: ListObjectsParamsCommon{
|
2022-03-18 13:04:09 +00:00
|
|
|
BktInfo: tc.bktInfo,
|
2021-08-13 14:13:14 +00:00
|
|
|
MaxKeys: 1000,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
require.NoError(tc.t, err)
|
|
|
|
return res.Objects
|
|
|
|
}
|
|
|
|
|
2024-01-22 07:01:24 +00:00
|
|
|
func (tc *testContext) listObjectsV2() []*data.ExtendedNodeVersion {
|
2021-08-13 14:13:14 +00:00
|
|
|
res, err := tc.layer.ListObjectsV2(tc.ctx, &ListObjectsParamsV2{
|
|
|
|
ListObjectsParamsCommon: ListObjectsParamsCommon{
|
2022-03-18 13:04:09 +00:00
|
|
|
BktInfo: tc.bktInfo,
|
2021-08-13 14:13:14 +00:00
|
|
|
MaxKeys: 1000,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
require.NoError(tc.t, err)
|
|
|
|
return res.Objects
|
|
|
|
}
|
|
|
|
|
|
|
|
func (tc *testContext) listVersions() *ListObjectVersionsInfo {
|
|
|
|
res, err := tc.layer.ListObjectVersions(tc.ctx, &ListObjectVersionsParams{
|
2022-03-18 13:04:09 +00:00
|
|
|
BktInfo: tc.bktInfo,
|
2021-08-13 14:13:14 +00:00
|
|
|
MaxKeys: 1000,
|
|
|
|
})
|
|
|
|
require.NoError(tc.t, err)
|
|
|
|
return res
|
|
|
|
}
|
|
|
|
|
2022-05-25 17:25:43 +00:00
|
|
|
func (tc *testContext) checkListObjects(ids ...oid.ID) {
|
2021-08-13 14:13:14 +00:00
|
|
|
objs := tc.listObjectsV1()
|
|
|
|
require.Equal(tc.t, len(ids), len(objs))
|
|
|
|
for _, id := range ids {
|
|
|
|
require.Contains(tc.t, ids, id)
|
|
|
|
}
|
|
|
|
|
|
|
|
objs = tc.listObjectsV2()
|
|
|
|
require.Equal(tc.t, len(ids), len(objs))
|
|
|
|
for _, id := range ids {
|
|
|
|
require.Contains(tc.t, ids, id)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-26 13:11:14 +00:00
|
|
|
func (tc *testContext) getObjectByID(objID oid.ID) *object.Object {
|
2022-12-20 08:38:58 +00:00
|
|
|
for _, obj := range tc.testFrostFS.Objects() {
|
2022-05-26 13:11:14 +00:00
|
|
|
id, _ := obj.ID()
|
|
|
|
if id.Equals(objID) {
|
|
|
|
return obj
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2021-08-13 14:13:14 +00:00
|
|
|
type testContext struct {
|
2022-12-20 08:38:58 +00:00
|
|
|
t *testing.T
|
|
|
|
ctx context.Context
|
2024-06-25 12:57:55 +00:00
|
|
|
layer *Layer
|
2022-12-20 08:38:58 +00:00
|
|
|
bktInfo *data.BucketInfo
|
|
|
|
obj string
|
|
|
|
testFrostFS *TestFrostFS
|
2021-08-13 14:13:14 +00:00
|
|
|
}
|
|
|
|
|
2021-09-21 13:08:06 +00:00
|
|
|
func prepareContext(t *testing.T, cachesConfig ...*CachesConfig) *testContext {
|
2022-06-06 08:01:12 +00:00
|
|
|
logger := zap.NewExample()
|
|
|
|
|
2021-08-13 14:13:14 +00:00
|
|
|
key, err := keys.NewPrivateKey()
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2022-04-25 09:57:58 +00:00
|
|
|
bearerToken := bearertest.Token()
|
|
|
|
require.NoError(t, bearerToken.Sign(key.PrivateKey))
|
2022-03-01 19:02:24 +00:00
|
|
|
|
2024-04-16 08:20:35 +00:00
|
|
|
ctx := middleware.SetBox(context.Background(), &middleware.Box{AccessBox: &accessbox.Box{
|
2021-08-13 14:13:14 +00:00
|
|
|
Gate: &accessbox.GateData{
|
2022-04-25 09:57:58 +00:00
|
|
|
BearerToken: &bearerToken,
|
2021-08-13 14:13:14 +00:00
|
|
|
GateKey: key.PublicKey(),
|
|
|
|
},
|
2024-04-16 08:20:35 +00:00
|
|
|
}})
|
2023-08-03 12:08:22 +00:00
|
|
|
tp := NewTestFrostFS(key)
|
2021-08-13 14:13:14 +00:00
|
|
|
|
|
|
|
bktName := "testbucket1"
|
2023-08-25 10:06:43 +00:00
|
|
|
res, err := tp.CreateContainer(ctx, PrmContainerCreate{
|
2022-03-01 19:02:24 +00:00
|
|
|
Name: bktName,
|
|
|
|
})
|
2021-08-13 14:13:14 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2022-06-06 08:01:12 +00:00
|
|
|
config := DefaultCachesConfigs(logger)
|
2021-09-21 13:08:06 +00:00
|
|
|
if len(cachesConfig) != 0 {
|
|
|
|
config = cachesConfig[0]
|
|
|
|
}
|
|
|
|
|
2022-10-04 08:31:09 +00:00
|
|
|
var owner user.ID
|
|
|
|
user.IDFromKey(&owner, key.PrivateKey.PublicKey)
|
|
|
|
|
2021-11-22 09:16:05 +00:00
|
|
|
layerCfg := &Config{
|
2024-01-22 09:33:59 +00:00
|
|
|
Cache: NewCache(config),
|
2022-05-20 15:02:00 +00:00
|
|
|
AnonKey: AnonymousKey{Key: key},
|
2022-05-31 08:12:53 +00:00
|
|
|
TreeService: NewTreeService(),
|
2023-08-21 13:05:16 +00:00
|
|
|
Features: &FeatureSettingsMock{},
|
2024-01-19 06:26:58 +00:00
|
|
|
GateOwner: owner,
|
2021-11-22 09:16:05 +00:00
|
|
|
}
|
|
|
|
|
2021-08-13 14:13:14 +00:00
|
|
|
return &testContext{
|
2022-02-28 08:02:05 +00:00
|
|
|
ctx: ctx,
|
2022-06-06 08:01:12 +00:00
|
|
|
layer: NewLayer(logger, tp, layerCfg),
|
2022-02-28 08:02:05 +00:00
|
|
|
bktInfo: &data.BucketInfo{
|
2023-08-25 10:06:43 +00:00
|
|
|
Name: bktName,
|
|
|
|
Owner: owner,
|
|
|
|
CID: res.ContainerID,
|
|
|
|
HomomorphicHashDisabled: res.HomomorphicHashDisabled,
|
2022-02-28 08:02:05 +00:00
|
|
|
},
|
2022-12-20 08:38:58 +00:00
|
|
|
obj: "obj1",
|
|
|
|
t: t,
|
|
|
|
testFrostFS: tp,
|
2021-08-13 14:13:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestSimpleVersioning(t *testing.T) {
|
|
|
|
tc := prepareContext(t)
|
2022-02-28 08:02:05 +00:00
|
|
|
err := tc.layer.PutBucketSettings(tc.ctx, &PutSettingsParams{
|
|
|
|
BktInfo: tc.bktInfo,
|
2022-07-20 10:30:19 +00:00
|
|
|
Settings: &data.BucketSettings{Versioning: data.VersioningEnabled},
|
2021-08-13 14:13:14 +00:00
|
|
|
})
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
obj1Content1 := []byte("content obj1 v1")
|
|
|
|
obj1v1 := tc.putObject(obj1Content1)
|
|
|
|
|
|
|
|
obj1Content2 := []byte("content obj1 v2")
|
|
|
|
obj1v2 := tc.putObject(obj1Content2)
|
|
|
|
|
2022-05-20 15:02:00 +00:00
|
|
|
_, buffer2 := tc.getObject(tc.obj, "", false)
|
2021-08-13 14:13:14 +00:00
|
|
|
require.Equal(t, obj1Content2, buffer2)
|
|
|
|
|
2022-05-25 17:25:43 +00:00
|
|
|
_, buffer1 := tc.getObject(tc.obj, obj1v1.ID.EncodeToString(), false)
|
2021-08-13 14:13:14 +00:00
|
|
|
require.Equal(t, obj1Content1, buffer1)
|
|
|
|
|
2021-08-27 21:33:50 +00:00
|
|
|
tc.checkListObjects(obj1v2.ID)
|
2021-08-13 14:13:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestSimpleNoVersioning(t *testing.T) {
|
|
|
|
tc := prepareContext(t)
|
|
|
|
|
|
|
|
obj1Content1 := []byte("content obj1 v1")
|
|
|
|
obj1v1 := tc.putObject(obj1Content1)
|
|
|
|
|
|
|
|
obj1Content2 := []byte("content obj1 v2")
|
|
|
|
obj1v2 := tc.putObject(obj1Content2)
|
|
|
|
|
2022-05-20 15:02:00 +00:00
|
|
|
_, buffer2 := tc.getObject(tc.obj, "", false)
|
2021-08-13 14:13:14 +00:00
|
|
|
require.Equal(t, obj1Content2, buffer2)
|
|
|
|
|
2022-05-25 17:25:43 +00:00
|
|
|
tc.getObject(tc.obj, obj1v1.ID.EncodeToString(), true)
|
2021-08-27 21:33:50 +00:00
|
|
|
tc.checkListObjects(obj1v2.ID)
|
2021-08-13 14:13:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestVersioningDeleteObject(t *testing.T) {
|
|
|
|
tc := prepareContext(t)
|
2022-07-20 10:30:19 +00:00
|
|
|
settings := &data.BucketSettings{Versioning: data.VersioningEnabled}
|
2022-02-28 08:02:05 +00:00
|
|
|
err := tc.layer.PutBucketSettings(tc.ctx, &PutSettingsParams{
|
|
|
|
BktInfo: tc.bktInfo,
|
2022-03-31 06:24:29 +00:00
|
|
|
Settings: settings,
|
2021-08-13 14:13:14 +00:00
|
|
|
})
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
tc.putObject([]byte("content obj1 v1"))
|
|
|
|
tc.putObject([]byte("content obj1 v2"))
|
|
|
|
|
2022-06-24 12:39:30 +00:00
|
|
|
tc.deleteObject(tc.obj, "", settings)
|
2021-08-13 14:13:14 +00:00
|
|
|
tc.getObject(tc.obj, "", true)
|
|
|
|
|
|
|
|
tc.checkListObjects()
|
|
|
|
}
|
|
|
|
|
2022-05-31 08:12:53 +00:00
|
|
|
func TestGetUnversioned(t *testing.T) {
|
|
|
|
tc := prepareContext(t)
|
|
|
|
|
|
|
|
objContent := []byte("content obj1 v1")
|
|
|
|
objInfo := tc.putObject(objContent)
|
|
|
|
|
2022-07-20 10:30:19 +00:00
|
|
|
settings := &data.BucketSettings{Versioning: data.VersioningUnversioned}
|
2022-05-31 08:12:53 +00:00
|
|
|
err := tc.layer.PutBucketSettings(tc.ctx, &PutSettingsParams{
|
|
|
|
BktInfo: tc.bktInfo,
|
|
|
|
Settings: settings,
|
|
|
|
})
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2022-08-05 01:41:33 +00:00
|
|
|
resInfo, buffer := tc.getObject(tc.obj, data.UnversionedObjectVersionID, false)
|
2022-05-31 08:12:53 +00:00
|
|
|
require.Equal(t, objContent, buffer)
|
2022-08-04 17:31:33 +00:00
|
|
|
require.Equal(t, objInfo.VersionID(), resInfo.VersionID())
|
2022-05-31 08:12:53 +00:00
|
|
|
}
|
|
|
|
|
2021-08-13 14:13:14 +00:00
|
|
|
func TestVersioningDeleteSpecificObjectVersion(t *testing.T) {
|
|
|
|
tc := prepareContext(t)
|
2022-07-20 10:30:19 +00:00
|
|
|
settings := &data.BucketSettings{Versioning: data.VersioningEnabled}
|
2022-02-28 08:02:05 +00:00
|
|
|
err := tc.layer.PutBucketSettings(tc.ctx, &PutSettingsParams{
|
|
|
|
BktInfo: tc.bktInfo,
|
2022-03-31 06:24:29 +00:00
|
|
|
Settings: settings,
|
2021-08-13 14:13:14 +00:00
|
|
|
})
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
tc.putObject([]byte("content obj1 v1"))
|
|
|
|
objV2Info := tc.putObject([]byte("content obj1 v2"))
|
|
|
|
objV3Content := []byte("content obj1 v3")
|
|
|
|
objV3Info := tc.putObject(objV3Content)
|
|
|
|
|
2022-08-04 17:31:33 +00:00
|
|
|
tc.deleteObject(tc.obj, objV2Info.VersionID(), settings)
|
|
|
|
tc.getObject(tc.obj, objV2Info.VersionID(), true)
|
2021-08-13 14:13:14 +00:00
|
|
|
|
|
|
|
_, buffer3 := tc.getObject(tc.obj, "", false)
|
|
|
|
require.Equal(t, objV3Content, buffer3)
|
|
|
|
|
2022-06-24 12:39:30 +00:00
|
|
|
tc.deleteObject(tc.obj, "", settings)
|
2021-08-13 14:13:14 +00:00
|
|
|
tc.getObject(tc.obj, "", true)
|
|
|
|
|
2022-05-31 15:03:58 +00:00
|
|
|
versions := tc.listVersions()
|
2023-10-09 06:57:33 +00:00
|
|
|
require.Len(t, versions.DeleteMarker, 1)
|
2022-05-31 15:03:58 +00:00
|
|
|
for _, ver := range versions.DeleteMarker {
|
2021-08-13 14:13:14 +00:00
|
|
|
if ver.IsLatest {
|
2024-01-17 14:26:02 +00:00
|
|
|
tc.deleteObject(tc.obj, ver.NodeVersion.OID.EncodeToString(), settings)
|
2021-08-13 14:13:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
resInfo, buffer := tc.getObject(tc.obj, "", false)
|
|
|
|
require.Equal(t, objV3Content, buffer)
|
2022-08-04 17:31:33 +00:00
|
|
|
require.Equal(t, objV3Info.VersionID(), resInfo.VersionID())
|
2021-08-13 14:13:14 +00:00
|
|
|
}
|
|
|
|
|
2022-02-08 16:54:04 +00:00
|
|
|
func TestNoVersioningDeleteObject(t *testing.T) {
|
|
|
|
tc := prepareContext(t)
|
|
|
|
|
|
|
|
tc.putObject([]byte("content obj1 v1"))
|
|
|
|
tc.putObject([]byte("content obj1 v2"))
|
|
|
|
|
2022-06-24 12:39:30 +00:00
|
|
|
settings, err := tc.layer.GetBucketSettings(tc.ctx, tc.bktInfo)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
tc.deleteObject(tc.obj, "", settings)
|
2022-02-08 16:54:04 +00:00
|
|
|
tc.getObject(tc.obj, "", true)
|
|
|
|
tc.checkListObjects()
|
|
|
|
}
|
2023-10-25 13:35:23 +00:00
|
|
|
|
|
|
|
func TestFilterVersionsByMarker(t *testing.T) {
|
|
|
|
n := 10
|
|
|
|
testOIDs := make([]oid.ID, n)
|
|
|
|
for i := 0; i < n; i++ {
|
|
|
|
testOIDs[i] = oidtest.ID()
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tc := range []struct {
|
|
|
|
name string
|
2024-01-17 14:26:02 +00:00
|
|
|
objects []*data.ExtendedNodeVersion
|
2023-10-25 13:35:23 +00:00
|
|
|
params *ListObjectVersionsParams
|
2024-01-17 14:26:02 +00:00
|
|
|
expected []*data.ExtendedNodeVersion
|
2023-10-25 13:35:23 +00:00
|
|
|
error bool
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "missed key marker",
|
2024-01-17 14:26:02 +00:00
|
|
|
objects: []*data.ExtendedNodeVersion{
|
|
|
|
{NodeVersion: &data.NodeVersion{BaseNodeVersion: data.BaseNodeVersion{FilePath: "obj0", OID: testOIDs[0]}}},
|
|
|
|
{NodeVersion: &data.NodeVersion{BaseNodeVersion: data.BaseNodeVersion{FilePath: "obj0", OID: testOIDs[1]}}},
|
2023-10-25 13:35:23 +00:00
|
|
|
},
|
|
|
|
params: &ListObjectVersionsParams{KeyMarker: "", VersionIDMarker: "dummy"},
|
2024-01-17 14:26:02 +00:00
|
|
|
expected: []*data.ExtendedNodeVersion{
|
|
|
|
{NodeVersion: &data.NodeVersion{BaseNodeVersion: data.BaseNodeVersion{FilePath: "obj0", OID: testOIDs[0]}}},
|
|
|
|
{NodeVersion: &data.NodeVersion{BaseNodeVersion: data.BaseNodeVersion{FilePath: "obj0", OID: testOIDs[1]}}},
|
2023-10-25 13:35:23 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "last version id",
|
2024-01-17 14:26:02 +00:00
|
|
|
objects: []*data.ExtendedNodeVersion{
|
|
|
|
{NodeVersion: &data.NodeVersion{BaseNodeVersion: data.BaseNodeVersion{FilePath: "obj0", OID: testOIDs[0]}}},
|
|
|
|
{NodeVersion: &data.NodeVersion{BaseNodeVersion: data.BaseNodeVersion{FilePath: "obj0", OID: testOIDs[1]}}},
|
2023-10-25 13:35:23 +00:00
|
|
|
},
|
|
|
|
params: &ListObjectVersionsParams{KeyMarker: "obj0", VersionIDMarker: testOIDs[1].EncodeToString()},
|
2024-01-17 14:26:02 +00:00
|
|
|
expected: []*data.ExtendedNodeVersion{},
|
2023-10-25 13:35:23 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "same name, different versions",
|
2024-01-17 14:26:02 +00:00
|
|
|
objects: []*data.ExtendedNodeVersion{
|
|
|
|
{NodeVersion: &data.NodeVersion{BaseNodeVersion: data.BaseNodeVersion{FilePath: "obj0", OID: testOIDs[0]}}},
|
|
|
|
{NodeVersion: &data.NodeVersion{BaseNodeVersion: data.BaseNodeVersion{FilePath: "obj0", OID: testOIDs[1]}}},
|
2023-10-25 13:35:23 +00:00
|
|
|
},
|
|
|
|
params: &ListObjectVersionsParams{KeyMarker: "obj0", VersionIDMarker: testOIDs[0].EncodeToString()},
|
2024-01-17 14:26:02 +00:00
|
|
|
expected: []*data.ExtendedNodeVersion{
|
|
|
|
{NodeVersion: &data.NodeVersion{BaseNodeVersion: data.BaseNodeVersion{FilePath: "obj0", OID: testOIDs[1]}}},
|
2023-10-25 13:35:23 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "different name, different versions",
|
2024-01-17 14:26:02 +00:00
|
|
|
objects: []*data.ExtendedNodeVersion{
|
|
|
|
{NodeVersion: &data.NodeVersion{BaseNodeVersion: data.BaseNodeVersion{FilePath: "obj0", OID: testOIDs[0]}}},
|
|
|
|
{NodeVersion: &data.NodeVersion{BaseNodeVersion: data.BaseNodeVersion{FilePath: "obj1", OID: testOIDs[1]}}},
|
2023-10-25 13:35:23 +00:00
|
|
|
},
|
|
|
|
params: &ListObjectVersionsParams{KeyMarker: "obj0", VersionIDMarker: testOIDs[0].EncodeToString()},
|
2024-01-17 14:26:02 +00:00
|
|
|
expected: []*data.ExtendedNodeVersion{
|
|
|
|
{NodeVersion: &data.NodeVersion{BaseNodeVersion: data.BaseNodeVersion{FilePath: "obj1", OID: testOIDs[1]}}},
|
2023-10-25 13:35:23 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "not matched name alphabetically less",
|
2024-01-17 14:26:02 +00:00
|
|
|
objects: []*data.ExtendedNodeVersion{
|
|
|
|
{NodeVersion: &data.NodeVersion{BaseNodeVersion: data.BaseNodeVersion{FilePath: "obj0", OID: testOIDs[0]}}},
|
|
|
|
{NodeVersion: &data.NodeVersion{BaseNodeVersion: data.BaseNodeVersion{FilePath: "obj1", OID: testOIDs[1]}}},
|
2023-10-25 13:35:23 +00:00
|
|
|
},
|
|
|
|
params: &ListObjectVersionsParams{KeyMarker: "obj", VersionIDMarker: ""},
|
2024-01-17 14:26:02 +00:00
|
|
|
expected: []*data.ExtendedNodeVersion{
|
|
|
|
{NodeVersion: &data.NodeVersion{BaseNodeVersion: data.BaseNodeVersion{FilePath: "obj0", OID: testOIDs[0]}}},
|
|
|
|
{NodeVersion: &data.NodeVersion{BaseNodeVersion: data.BaseNodeVersion{FilePath: "obj1", OID: testOIDs[1]}}},
|
2023-10-25 13:35:23 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "not matched name alphabetically less with dummy version id",
|
2024-01-17 14:26:02 +00:00
|
|
|
objects: []*data.ExtendedNodeVersion{
|
|
|
|
{NodeVersion: &data.NodeVersion{BaseNodeVersion: data.BaseNodeVersion{FilePath: "obj0", OID: testOIDs[0]}}},
|
2023-10-25 13:35:23 +00:00
|
|
|
},
|
|
|
|
params: &ListObjectVersionsParams{KeyMarker: "obj", VersionIDMarker: "dummy"},
|
|
|
|
error: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "not matched name alphabetically greater",
|
2024-01-17 14:26:02 +00:00
|
|
|
objects: []*data.ExtendedNodeVersion{
|
|
|
|
{NodeVersion: &data.NodeVersion{BaseNodeVersion: data.BaseNodeVersion{FilePath: "obj0", OID: testOIDs[0]}}},
|
|
|
|
{NodeVersion: &data.NodeVersion{BaseNodeVersion: data.BaseNodeVersion{FilePath: "obj1", OID: testOIDs[1]}}},
|
2023-10-25 13:35:23 +00:00
|
|
|
},
|
|
|
|
params: &ListObjectVersionsParams{KeyMarker: "obj2", VersionIDMarker: testOIDs[2].EncodeToString()},
|
2024-01-17 14:26:02 +00:00
|
|
|
expected: []*data.ExtendedNodeVersion{},
|
2023-10-25 13:35:23 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "not found version id",
|
2024-01-17 14:26:02 +00:00
|
|
|
objects: []*data.ExtendedNodeVersion{
|
|
|
|
{NodeVersion: &data.NodeVersion{BaseNodeVersion: data.BaseNodeVersion{FilePath: "obj0", OID: testOIDs[0]}}},
|
|
|
|
{NodeVersion: &data.NodeVersion{BaseNodeVersion: data.BaseNodeVersion{FilePath: "obj0", OID: testOIDs[1]}}},
|
|
|
|
{NodeVersion: &data.NodeVersion{BaseNodeVersion: data.BaseNodeVersion{FilePath: "obj1", OID: testOIDs[2]}}},
|
2023-10-25 13:35:23 +00:00
|
|
|
},
|
|
|
|
params: &ListObjectVersionsParams{KeyMarker: "obj0", VersionIDMarker: "dummy"},
|
|
|
|
error: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "not found version id, obj last",
|
2024-01-17 14:26:02 +00:00
|
|
|
objects: []*data.ExtendedNodeVersion{
|
|
|
|
{NodeVersion: &data.NodeVersion{BaseNodeVersion: data.BaseNodeVersion{FilePath: "obj0", OID: testOIDs[0]}}},
|
|
|
|
{NodeVersion: &data.NodeVersion{BaseNodeVersion: data.BaseNodeVersion{FilePath: "obj0", OID: testOIDs[1]}}},
|
2023-10-25 13:35:23 +00:00
|
|
|
},
|
|
|
|
params: &ListObjectVersionsParams{KeyMarker: "obj0", VersionIDMarker: "dummy"},
|
|
|
|
error: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "not found version id, obj last",
|
2024-01-17 14:26:02 +00:00
|
|
|
objects: []*data.ExtendedNodeVersion{
|
|
|
|
{NodeVersion: &data.NodeVersion{BaseNodeVersion: data.BaseNodeVersion{FilePath: "obj0", OID: testOIDs[0]}}},
|
|
|
|
{NodeVersion: &data.NodeVersion{BaseNodeVersion: data.BaseNodeVersion{FilePath: "obj0", OID: testOIDs[1]}}},
|
|
|
|
{NodeVersion: &data.NodeVersion{BaseNodeVersion: data.BaseNodeVersion{FilePath: "obj1", OID: testOIDs[2]}}},
|
2023-10-25 13:35:23 +00:00
|
|
|
},
|
|
|
|
params: &ListObjectVersionsParams{KeyMarker: "obj0", VersionIDMarker: ""},
|
2024-01-17 14:26:02 +00:00
|
|
|
expected: []*data.ExtendedNodeVersion{
|
|
|
|
{NodeVersion: &data.NodeVersion{BaseNodeVersion: data.BaseNodeVersion{FilePath: "obj1", OID: testOIDs[2]}}},
|
2023-10-25 13:35:23 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
} {
|
|
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
|
|
actual, err := filterVersionsByMarker(tc.objects, tc.params)
|
|
|
|
if tc.error {
|
|
|
|
require.Error(t, err)
|
|
|
|
} else {
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, tc.expected, actual)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|