2020-10-28 15:28:06 +00:00
|
|
|
// Copyright (C) 2020 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
package metabase_test
|
|
|
|
|
|
|
|
import (
|
2020-11-09 14:55:10 +00:00
|
|
|
"bytes"
|
2020-10-29 18:10:46 +00:00
|
|
|
"context"
|
2020-11-03 15:51:03 +00:00
|
|
|
"sort"
|
2020-10-28 15:28:06 +00:00
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/google/go-cmp/cmp"
|
|
|
|
"github.com/google/go-cmp/cmp/cmpopts"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"github.com/zeebo/errs"
|
|
|
|
|
2020-11-02 15:28:51 +00:00
|
|
|
"storj.io/common/storj"
|
2020-10-28 15:28:06 +00:00
|
|
|
"storj.io/common/testcontext"
|
2020-11-02 15:28:51 +00:00
|
|
|
"storj.io/common/testrand"
|
2020-10-28 15:28:06 +00:00
|
|
|
"storj.io/storj/satellite/metainfo/metabase"
|
|
|
|
)
|
|
|
|
|
|
|
|
type BeginObjectNextVersion struct {
|
|
|
|
Opts metabase.BeginObjectNextVersion
|
|
|
|
Version metabase.Version
|
|
|
|
ErrClass *errs.Class
|
|
|
|
ErrText string
|
|
|
|
}
|
|
|
|
|
2021-01-22 17:34:08 +00:00
|
|
|
func (step BeginObjectNextVersion) Check(ctx *testcontext.Context, t testing.TB, db *metabase.DB) {
|
2020-10-28 15:28:06 +00:00
|
|
|
got, err := db.BeginObjectNextVersion(ctx, step.Opts)
|
|
|
|
checkError(t, err, step.ErrClass, step.ErrText)
|
|
|
|
require.Equal(t, step.Version, got)
|
|
|
|
}
|
|
|
|
|
|
|
|
type BeginObjectExactVersion struct {
|
|
|
|
Opts metabase.BeginObjectExactVersion
|
|
|
|
Version metabase.Version
|
|
|
|
ErrClass *errs.Class
|
|
|
|
ErrText string
|
|
|
|
}
|
|
|
|
|
2021-01-22 17:34:08 +00:00
|
|
|
func (step BeginObjectExactVersion) Check(ctx *testcontext.Context, t testing.TB, db *metabase.DB) {
|
2020-10-28 15:28:06 +00:00
|
|
|
got, err := db.BeginObjectExactVersion(ctx, step.Opts)
|
|
|
|
checkError(t, err, step.ErrClass, step.ErrText)
|
2021-01-12 11:29:13 +00:00
|
|
|
if step.ErrClass == nil {
|
|
|
|
require.Equal(t, step.Version, got.Version)
|
|
|
|
require.WithinDuration(t, time.Now(), got.CreatedAt, 5*time.Second)
|
|
|
|
require.Equal(t, step.Opts.ObjectStream, got.ObjectStream)
|
|
|
|
require.Equal(t, step.Opts.ExpiresAt, got.ExpiresAt)
|
|
|
|
require.Equal(t, step.Opts.ZombieDeletionDeadline, got.ZombieDeletionDeadline)
|
|
|
|
require.Equal(t, step.Opts.Encryption, got.Encryption)
|
|
|
|
}
|
2020-10-28 15:28:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type CommitObject struct {
|
|
|
|
Opts metabase.CommitObject
|
|
|
|
ErrClass *errs.Class
|
|
|
|
ErrText string
|
|
|
|
}
|
|
|
|
|
2021-01-22 17:34:08 +00:00
|
|
|
func (step CommitObject) Check(ctx *testcontext.Context, t testing.TB, db *metabase.DB) metabase.Object {
|
2020-11-02 17:25:58 +00:00
|
|
|
object, err := db.CommitObject(ctx, step.Opts)
|
2020-10-28 15:28:06 +00:00
|
|
|
checkError(t, err, step.ErrClass, step.ErrText)
|
2020-11-02 17:25:58 +00:00
|
|
|
if err == nil {
|
|
|
|
require.Equal(t, step.Opts.ObjectStream, object.ObjectStream)
|
|
|
|
}
|
|
|
|
return object
|
2020-10-28 15:28:06 +00:00
|
|
|
}
|
|
|
|
|
2020-11-12 11:29:19 +00:00
|
|
|
type CommitObjectWithSegments struct {
|
|
|
|
Opts metabase.CommitObjectWithSegments
|
|
|
|
Deleted []metabase.DeletedSegmentInfo
|
|
|
|
ErrClass *errs.Class
|
|
|
|
ErrText string
|
|
|
|
}
|
|
|
|
|
2021-01-22 17:34:08 +00:00
|
|
|
func (step CommitObjectWithSegments) Check(ctx *testcontext.Context, t testing.TB, db *metabase.DB) metabase.Object {
|
2020-11-12 11:29:19 +00:00
|
|
|
object, deleted, err := db.CommitObjectWithSegments(ctx, step.Opts)
|
|
|
|
checkError(t, err, step.ErrClass, step.ErrText)
|
|
|
|
if err == nil {
|
|
|
|
require.Equal(t, step.Opts.ObjectStream, object.ObjectStream)
|
|
|
|
}
|
|
|
|
require.Equal(t, step.Deleted, deleted)
|
|
|
|
return object
|
|
|
|
}
|
|
|
|
|
2020-10-28 15:28:06 +00:00
|
|
|
type BeginSegment struct {
|
|
|
|
Opts metabase.BeginSegment
|
|
|
|
ErrClass *errs.Class
|
|
|
|
ErrText string
|
|
|
|
}
|
|
|
|
|
2021-01-22 17:34:08 +00:00
|
|
|
func (step BeginSegment) Check(ctx *testcontext.Context, t testing.TB, db *metabase.DB) {
|
2020-10-28 15:28:06 +00:00
|
|
|
err := db.BeginSegment(ctx, step.Opts)
|
|
|
|
checkError(t, err, step.ErrClass, step.ErrText)
|
|
|
|
}
|
|
|
|
|
|
|
|
type CommitSegment struct {
|
|
|
|
Opts metabase.CommitSegment
|
|
|
|
ErrClass *errs.Class
|
|
|
|
ErrText string
|
|
|
|
}
|
|
|
|
|
2021-01-22 17:34:08 +00:00
|
|
|
func (step CommitSegment) Check(ctx *testcontext.Context, t testing.TB, db *metabase.DB) {
|
2020-10-28 15:28:06 +00:00
|
|
|
err := db.CommitSegment(ctx, step.Opts)
|
|
|
|
checkError(t, err, step.ErrClass, step.ErrText)
|
|
|
|
}
|
|
|
|
|
|
|
|
type CommitInlineSegment struct {
|
|
|
|
Opts metabase.CommitInlineSegment
|
|
|
|
ErrClass *errs.Class
|
|
|
|
ErrText string
|
|
|
|
}
|
|
|
|
|
2021-01-22 17:34:08 +00:00
|
|
|
func (step CommitInlineSegment) Check(ctx *testcontext.Context, t testing.TB, db *metabase.DB) {
|
2020-10-28 15:28:06 +00:00
|
|
|
err := db.CommitInlineSegment(ctx, step.Opts)
|
|
|
|
checkError(t, err, step.ErrClass, step.ErrText)
|
|
|
|
}
|
|
|
|
|
2020-12-09 12:24:37 +00:00
|
|
|
type DeleteBucketObjects struct {
|
|
|
|
Opts metabase.DeleteBucketObjects
|
|
|
|
Deleted int64
|
|
|
|
ErrClass *errs.Class
|
|
|
|
ErrText string
|
|
|
|
}
|
|
|
|
|
2021-01-22 17:34:08 +00:00
|
|
|
func (step DeleteBucketObjects) Check(ctx *testcontext.Context, t testing.TB, db *metabase.DB) {
|
2020-12-09 12:24:37 +00:00
|
|
|
deleted, err := db.DeleteBucketObjects(ctx, step.Opts)
|
|
|
|
require.Equal(t, step.Deleted, deleted)
|
|
|
|
checkError(t, err, step.ErrClass, step.ErrText)
|
|
|
|
}
|
|
|
|
|
2020-11-02 16:32:24 +00:00
|
|
|
type UpdateObjectMetadata struct {
|
|
|
|
Opts metabase.UpdateObjectMetadata
|
|
|
|
ErrClass *errs.Class
|
|
|
|
ErrText string
|
|
|
|
}
|
|
|
|
|
2021-01-22 17:34:08 +00:00
|
|
|
func (step UpdateObjectMetadata) Check(ctx *testcontext.Context, t testing.TB, db *metabase.DB) {
|
2020-11-02 16:32:24 +00:00
|
|
|
err := db.UpdateObjectMetadata(ctx, step.Opts)
|
|
|
|
checkError(t, err, step.ErrClass, step.ErrText)
|
|
|
|
}
|
|
|
|
|
2020-12-11 12:09:59 +00:00
|
|
|
type UpdateSegmentPieces struct {
|
|
|
|
Opts metabase.UpdateSegmentPieces
|
|
|
|
ErrClass *errs.Class
|
|
|
|
ErrText string
|
|
|
|
}
|
|
|
|
|
2021-01-22 17:34:08 +00:00
|
|
|
func (step UpdateSegmentPieces) Check(ctx *testcontext.Context, t testing.TB, db *metabase.DB) {
|
2020-12-11 12:09:59 +00:00
|
|
|
err := db.UpdateSegmentPieces(ctx, step.Opts)
|
|
|
|
checkError(t, err, step.ErrClass, step.ErrText)
|
|
|
|
}
|
|
|
|
|
2020-10-28 15:28:06 +00:00
|
|
|
type GetObjectExactVersion struct {
|
|
|
|
Opts metabase.GetObjectExactVersion
|
|
|
|
Result metabase.Object
|
|
|
|
ErrClass *errs.Class
|
|
|
|
ErrText string
|
|
|
|
}
|
|
|
|
|
2021-01-22 17:34:08 +00:00
|
|
|
func (step GetObjectExactVersion) Check(ctx *testcontext.Context, t testing.TB, db *metabase.DB) {
|
2020-10-28 15:28:06 +00:00
|
|
|
result, err := db.GetObjectExactVersion(ctx, step.Opts)
|
|
|
|
checkError(t, err, step.ErrClass, step.ErrText)
|
|
|
|
|
|
|
|
diff := cmp.Diff(step.Result, result, cmpopts.EquateApproxTime(5*time.Second))
|
|
|
|
require.Zero(t, diff)
|
|
|
|
}
|
|
|
|
|
|
|
|
type GetObjectLatestVersion struct {
|
|
|
|
Opts metabase.GetObjectLatestVersion
|
|
|
|
Result metabase.Object
|
|
|
|
ErrClass *errs.Class
|
|
|
|
ErrText string
|
|
|
|
}
|
|
|
|
|
2021-01-22 17:34:08 +00:00
|
|
|
func (step GetObjectLatestVersion) Check(ctx *testcontext.Context, t testing.TB, db *metabase.DB) {
|
2020-10-28 15:28:06 +00:00
|
|
|
result, err := db.GetObjectLatestVersion(ctx, step.Opts)
|
|
|
|
checkError(t, err, step.ErrClass, step.ErrText)
|
|
|
|
|
|
|
|
diff := cmp.Diff(step.Result, result, cmpopts.EquateApproxTime(5*time.Second))
|
|
|
|
require.Zero(t, diff)
|
|
|
|
}
|
|
|
|
|
|
|
|
type GetSegmentByPosition struct {
|
|
|
|
Opts metabase.GetSegmentByPosition
|
|
|
|
Result metabase.Segment
|
|
|
|
ErrClass *errs.Class
|
|
|
|
ErrText string
|
|
|
|
}
|
|
|
|
|
2021-01-22 17:34:08 +00:00
|
|
|
func (step GetSegmentByPosition) Check(ctx *testcontext.Context, t testing.TB, db *metabase.DB) {
|
2020-10-28 15:28:06 +00:00
|
|
|
result, err := db.GetSegmentByPosition(ctx, step.Opts)
|
|
|
|
checkError(t, err, step.ErrClass, step.ErrText)
|
|
|
|
|
|
|
|
diff := cmp.Diff(step.Result, result, cmpopts.EquateApproxTime(5*time.Second))
|
|
|
|
require.Zero(t, diff)
|
|
|
|
}
|
|
|
|
|
2020-11-03 15:03:20 +00:00
|
|
|
type GetLatestObjectLastSegment struct {
|
|
|
|
Opts metabase.GetLatestObjectLastSegment
|
|
|
|
Result metabase.Segment
|
|
|
|
ErrClass *errs.Class
|
|
|
|
ErrText string
|
|
|
|
}
|
|
|
|
|
2021-01-22 17:34:08 +00:00
|
|
|
func (step GetLatestObjectLastSegment) Check(ctx *testcontext.Context, t testing.TB, db *metabase.DB) {
|
2020-11-03 15:03:20 +00:00
|
|
|
result, err := db.GetLatestObjectLastSegment(ctx, step.Opts)
|
|
|
|
checkError(t, err, step.ErrClass, step.ErrText)
|
|
|
|
|
|
|
|
diff := cmp.Diff(step.Result, result, cmpopts.EquateApproxTime(5*time.Second))
|
|
|
|
require.Zero(t, diff)
|
|
|
|
}
|
|
|
|
|
2020-11-10 09:17:25 +00:00
|
|
|
type GetSegmentByOffset struct {
|
|
|
|
Opts metabase.GetSegmentByOffset
|
|
|
|
Result metabase.Segment
|
|
|
|
ErrClass *errs.Class
|
|
|
|
ErrText string
|
|
|
|
}
|
|
|
|
|
2021-01-22 17:34:08 +00:00
|
|
|
func (step GetSegmentByOffset) Check(ctx *testcontext.Context, t testing.TB, db *metabase.DB) {
|
2020-11-10 09:17:25 +00:00
|
|
|
result, err := db.GetSegmentByOffset(ctx, step.Opts)
|
|
|
|
checkError(t, err, step.ErrClass, step.ErrText)
|
|
|
|
|
|
|
|
diff := cmp.Diff(step.Result, result, cmpopts.EquateApproxTime(5*time.Second))
|
|
|
|
require.Zero(t, diff)
|
|
|
|
}
|
|
|
|
|
2020-11-17 17:37:58 +00:00
|
|
|
type BucketEmpty struct {
|
|
|
|
Opts metabase.BucketEmpty
|
|
|
|
Result bool
|
|
|
|
ErrClass *errs.Class
|
|
|
|
ErrText string
|
|
|
|
}
|
|
|
|
|
2021-01-22 17:34:08 +00:00
|
|
|
func (step BucketEmpty) Check(ctx *testcontext.Context, t testing.TB, db *metabase.DB) {
|
2020-11-17 17:37:58 +00:00
|
|
|
result, err := db.BucketEmpty(ctx, step.Opts)
|
|
|
|
checkError(t, err, step.ErrClass, step.ErrText)
|
|
|
|
|
|
|
|
require.Equal(t, step.Result, result)
|
|
|
|
}
|
|
|
|
|
2020-11-05 12:59:19 +00:00
|
|
|
type ListSegments struct {
|
|
|
|
Opts metabase.ListSegments
|
|
|
|
Result metabase.ListSegmentsResult
|
|
|
|
ErrClass *errs.Class
|
|
|
|
ErrText string
|
|
|
|
}
|
|
|
|
|
2021-01-22 17:34:08 +00:00
|
|
|
func (step ListSegments) Check(ctx *testcontext.Context, t testing.TB, db *metabase.DB) {
|
2020-11-05 12:59:19 +00:00
|
|
|
result, err := db.ListSegments(ctx, step.Opts)
|
|
|
|
checkError(t, err, step.ErrClass, step.ErrText)
|
|
|
|
|
|
|
|
diff := cmp.Diff(step.Result, result, cmpopts.EquateApproxTime(5*time.Second))
|
|
|
|
require.Zero(t, diff)
|
|
|
|
}
|
|
|
|
|
2020-10-28 15:28:06 +00:00
|
|
|
type DeleteObjectExactVersion struct {
|
|
|
|
Opts metabase.DeleteObjectExactVersion
|
|
|
|
Result metabase.DeleteObjectResult
|
|
|
|
ErrClass *errs.Class
|
|
|
|
ErrText string
|
|
|
|
}
|
|
|
|
|
2021-01-22 17:34:08 +00:00
|
|
|
func (step DeleteObjectExactVersion) Check(ctx *testcontext.Context, t testing.TB, db *metabase.DB) {
|
2020-10-28 15:28:06 +00:00
|
|
|
result, err := db.DeleteObjectExactVersion(ctx, step.Opts)
|
|
|
|
checkError(t, err, step.ErrClass, step.ErrText)
|
|
|
|
|
|
|
|
diff := cmp.Diff(step.Result, result, cmpopts.EquateApproxTime(5*time.Second))
|
|
|
|
require.Zero(t, diff)
|
|
|
|
}
|
|
|
|
|
2020-12-01 23:17:05 +00:00
|
|
|
type DeletePendingObject struct {
|
|
|
|
Opts metabase.DeletePendingObject
|
|
|
|
Result metabase.DeleteObjectResult
|
|
|
|
ErrClass *errs.Class
|
|
|
|
ErrText string
|
|
|
|
}
|
|
|
|
|
2021-01-22 17:34:08 +00:00
|
|
|
func (step DeletePendingObject) Check(ctx *testcontext.Context, t testing.TB, db *metabase.DB) {
|
2020-12-01 23:17:05 +00:00
|
|
|
result, err := db.DeletePendingObject(ctx, step.Opts)
|
|
|
|
checkError(t, err, step.ErrClass, step.ErrText)
|
|
|
|
|
|
|
|
diff := cmp.Diff(step.Result, result, cmpopts.EquateApproxTime(5*time.Second))
|
|
|
|
require.Zero(t, diff)
|
|
|
|
}
|
|
|
|
|
2020-10-28 15:28:06 +00:00
|
|
|
type DeleteObjectLatestVersion struct {
|
|
|
|
Opts metabase.DeleteObjectLatestVersion
|
|
|
|
Result metabase.DeleteObjectResult
|
|
|
|
ErrClass *errs.Class
|
|
|
|
ErrText string
|
|
|
|
}
|
|
|
|
|
2021-01-22 17:34:08 +00:00
|
|
|
func (step DeleteObjectLatestVersion) Check(ctx *testcontext.Context, t testing.TB, db *metabase.DB) {
|
2020-10-28 15:28:06 +00:00
|
|
|
result, err := db.DeleteObjectLatestVersion(ctx, step.Opts)
|
|
|
|
checkError(t, err, step.ErrClass, step.ErrText)
|
|
|
|
|
|
|
|
diff := cmp.Diff(step.Result, result, cmpopts.EquateApproxTime(5*time.Second))
|
|
|
|
require.Zero(t, diff)
|
|
|
|
}
|
|
|
|
|
2021-01-11 10:08:18 +00:00
|
|
|
type DeleteObjectAnyStatusAllVersions struct {
|
|
|
|
Opts metabase.DeleteObjectAnyStatusAllVersions
|
2020-10-28 15:28:06 +00:00
|
|
|
Result metabase.DeleteObjectResult
|
|
|
|
ErrClass *errs.Class
|
|
|
|
ErrText string
|
|
|
|
}
|
|
|
|
|
2021-01-22 17:34:08 +00:00
|
|
|
func (step DeleteObjectAnyStatusAllVersions) Check(ctx *testcontext.Context, t testing.TB, db *metabase.DB) {
|
2021-01-11 10:08:18 +00:00
|
|
|
result, err := db.DeleteObjectAnyStatusAllVersions(ctx, step.Opts)
|
2020-10-28 15:28:06 +00:00
|
|
|
checkError(t, err, step.ErrClass, step.ErrText)
|
|
|
|
|
|
|
|
diff := cmp.Diff(step.Result, result, cmpopts.EquateApproxTime(5*time.Second))
|
|
|
|
require.Zero(t, diff)
|
|
|
|
}
|
|
|
|
|
2020-11-03 15:51:03 +00:00
|
|
|
type DeleteObjectsAllVersions struct {
|
|
|
|
Opts metabase.DeleteObjectsAllVersions
|
|
|
|
Result metabase.DeleteObjectResult
|
|
|
|
ErrClass *errs.Class
|
|
|
|
ErrText string
|
|
|
|
}
|
|
|
|
|
2021-01-22 17:34:08 +00:00
|
|
|
func (step DeleteObjectsAllVersions) Check(ctx *testcontext.Context, t testing.TB, db *metabase.DB) {
|
2020-11-03 15:51:03 +00:00
|
|
|
result, err := db.DeleteObjectsAllVersions(ctx, step.Opts)
|
|
|
|
checkError(t, err, step.ErrClass, step.ErrText)
|
|
|
|
|
2020-11-09 14:55:10 +00:00
|
|
|
sortObjects(result.Objects)
|
|
|
|
sortObjects(step.Result.Objects)
|
2020-11-03 15:51:03 +00:00
|
|
|
|
|
|
|
diff := cmp.Diff(step.Result, result, cmpopts.EquateApproxTime(5*time.Second))
|
|
|
|
require.Zero(t, diff)
|
|
|
|
}
|
|
|
|
|
2020-11-09 14:55:10 +00:00
|
|
|
type DeleteExpiredObjects struct {
|
|
|
|
ErrClass *errs.Class
|
|
|
|
ErrText string
|
|
|
|
}
|
|
|
|
|
2021-01-22 17:34:08 +00:00
|
|
|
func (step DeleteExpiredObjects) Check(ctx *testcontext.Context, t testing.TB, db *metabase.DB) {
|
2020-11-09 14:55:10 +00:00
|
|
|
err := db.DeleteExpiredObjects(ctx, time.Now())
|
|
|
|
checkError(t, err, step.ErrClass, step.ErrText)
|
|
|
|
}
|
|
|
|
|
2020-10-29 18:10:46 +00:00
|
|
|
type IterateCollector []metabase.ObjectEntry
|
|
|
|
|
|
|
|
func (coll *IterateCollector) Add(ctx context.Context, it metabase.ObjectsIterator) error {
|
|
|
|
var item metabase.ObjectEntry
|
|
|
|
|
|
|
|
for it.Next(ctx, &item) {
|
|
|
|
*coll = append(*coll, item)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-12-21 16:43:08 +00:00
|
|
|
type IterateObjects struct {
|
|
|
|
Opts metabase.IterateObjects
|
|
|
|
|
|
|
|
Result []metabase.ObjectEntry
|
|
|
|
ErrClass *errs.Class
|
|
|
|
ErrText string
|
|
|
|
}
|
|
|
|
|
2021-01-22 17:34:08 +00:00
|
|
|
func (step IterateObjects) Check(ctx *testcontext.Context, t testing.TB, db *metabase.DB) {
|
2020-12-21 16:43:08 +00:00
|
|
|
var collector IterateCollector
|
|
|
|
|
|
|
|
err := db.IterateObjectsAllVersions(ctx, step.Opts, collector.Add)
|
|
|
|
checkError(t, err, step.ErrClass, step.ErrText)
|
|
|
|
|
|
|
|
result := []metabase.ObjectEntry(collector)
|
|
|
|
sort.Slice(result, func(i, j int) bool {
|
|
|
|
return result[i].ObjectKey < result[j].ObjectKey
|
|
|
|
})
|
|
|
|
diff := cmp.Diff(step.Result, result, cmpopts.EquateApproxTime(5*time.Second))
|
|
|
|
require.Zero(t, diff)
|
|
|
|
}
|
|
|
|
|
2020-12-21 15:07:00 +00:00
|
|
|
type IterateObjectsWithStatus struct {
|
|
|
|
Opts metabase.IterateObjectsWithStatus
|
2020-10-29 18:10:46 +00:00
|
|
|
|
|
|
|
Result []metabase.ObjectEntry
|
|
|
|
ErrClass *errs.Class
|
|
|
|
ErrText string
|
|
|
|
}
|
|
|
|
|
2021-01-22 17:34:08 +00:00
|
|
|
func (step IterateObjectsWithStatus) Check(ctx *testcontext.Context, t testing.TB, db *metabase.DB) {
|
2020-10-29 18:10:46 +00:00
|
|
|
var result IterateCollector
|
|
|
|
|
2020-12-21 15:07:00 +00:00
|
|
|
err := db.IterateObjectsAllVersionsWithStatus(ctx, step.Opts, result.Add)
|
2020-10-29 18:10:46 +00:00
|
|
|
checkError(t, err, step.ErrClass, step.ErrText)
|
|
|
|
|
|
|
|
diff := cmp.Diff(step.Result, []metabase.ObjectEntry(result), cmpopts.EquateApproxTime(5*time.Second))
|
|
|
|
require.Zero(t, diff)
|
|
|
|
}
|
|
|
|
|
2021-01-22 17:34:08 +00:00
|
|
|
func checkError(t testing.TB, err error, errClass *errs.Class, errText string) {
|
2020-10-28 15:28:06 +00:00
|
|
|
if errClass != nil {
|
|
|
|
require.True(t, errClass.Has(err), "expected an error %v got %v", *errClass, err)
|
|
|
|
}
|
|
|
|
if errText != "" {
|
|
|
|
require.EqualError(t, err, errClass.New(errText).Error())
|
|
|
|
}
|
|
|
|
if errClass == nil && errText == "" {
|
|
|
|
require.NoError(t, err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-09 14:55:10 +00:00
|
|
|
func sortObjects(objects []metabase.Object) {
|
2020-11-03 15:51:03 +00:00
|
|
|
sort.Slice(objects, func(i, j int) bool {
|
2020-11-09 14:55:10 +00:00
|
|
|
return bytes.Compare(objects[i].StreamID[:], objects[j].StreamID[:]) < 0
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func sortRawObjects(objects []metabase.RawObject) {
|
|
|
|
sort.Slice(objects, func(i, j int) bool {
|
|
|
|
return bytes.Compare(objects[i].StreamID[:], objects[j].StreamID[:]) < 0
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func sortRawSegments(segments []metabase.RawSegment) {
|
|
|
|
sort.Slice(segments, func(i, j int) bool {
|
|
|
|
return bytes.Compare(segments[i].StreamID[:], segments[j].StreamID[:]) < 0
|
2020-11-03 15:51:03 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2020-10-28 15:28:06 +00:00
|
|
|
type DeleteAll struct{}
|
|
|
|
|
2021-01-22 17:34:08 +00:00
|
|
|
func (step DeleteAll) Check(ctx *testcontext.Context, t testing.TB, db *metabase.DB) {
|
2020-10-28 15:28:06 +00:00
|
|
|
err := db.TestingDeleteAll(ctx)
|
|
|
|
require.NoError(t, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
type Verify metabase.RawState
|
|
|
|
|
2021-01-22 17:34:08 +00:00
|
|
|
func (step Verify) Check(ctx *testcontext.Context, t testing.TB, db *metabase.DB) {
|
2020-10-28 15:28:06 +00:00
|
|
|
state, err := db.TestingGetState(ctx)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2020-11-09 14:55:10 +00:00
|
|
|
sortRawObjects(state.Objects)
|
|
|
|
sortRawObjects(step.Objects)
|
|
|
|
sortRawSegments(state.Segments)
|
|
|
|
sortRawSegments(step.Segments)
|
|
|
|
|
2020-10-28 15:28:06 +00:00
|
|
|
diff := cmp.Diff(metabase.RawState(step), *state,
|
|
|
|
cmpopts.EquateApproxTime(5*time.Second))
|
|
|
|
require.Zero(t, diff)
|
|
|
|
}
|
2020-11-02 15:28:51 +00:00
|
|
|
|
|
|
|
type CreateTestObject struct {
|
|
|
|
BeginObjectExactVersion *metabase.BeginObjectExactVersion
|
|
|
|
CommitObject *metabase.CommitObject
|
|
|
|
// TODO add BeginSegment, CommitSegment
|
|
|
|
}
|
|
|
|
|
2021-01-22 17:34:08 +00:00
|
|
|
func (co CreateTestObject) Run(ctx *testcontext.Context, t testing.TB, db *metabase.DB, obj metabase.ObjectStream, numberOfSegments byte) metabase.Object {
|
2020-11-02 15:28:51 +00:00
|
|
|
boeOpts := metabase.BeginObjectExactVersion{
|
|
|
|
ObjectStream: obj,
|
|
|
|
Encryption: defaultTestEncryption,
|
|
|
|
}
|
|
|
|
if co.BeginObjectExactVersion != nil {
|
|
|
|
boeOpts = *co.BeginObjectExactVersion
|
|
|
|
}
|
|
|
|
|
|
|
|
BeginObjectExactVersion{
|
|
|
|
Opts: boeOpts,
|
|
|
|
Version: obj.Version,
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2020-11-10 09:17:25 +00:00
|
|
|
for i := byte(0); i < numberOfSegments; i++ {
|
2020-11-02 15:28:51 +00:00
|
|
|
BeginSegment{
|
|
|
|
Opts: metabase.BeginSegment{
|
|
|
|
ObjectStream: obj,
|
|
|
|
Position: metabase.SegmentPosition{Part: 0, Index: uint32(i)},
|
2020-11-10 09:17:25 +00:00
|
|
|
RootPieceID: storj.PieceID{i + 1},
|
2020-11-02 15:28:51 +00:00
|
|
|
Pieces: []metabase.Piece{{
|
|
|
|
Number: 1,
|
|
|
|
StorageNode: testrand.NodeID(),
|
|
|
|
}},
|
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
|
|
|
CommitSegment{
|
|
|
|
Opts: metabase.CommitSegment{
|
|
|
|
ObjectStream: obj,
|
|
|
|
Position: metabase.SegmentPosition{Part: 0, Index: uint32(i)},
|
|
|
|
RootPieceID: storj.PieceID{1},
|
|
|
|
Pieces: metabase.Pieces{{Number: 0, StorageNode: storj.NodeID{2}}},
|
|
|
|
|
|
|
|
EncryptedKey: []byte{3},
|
|
|
|
EncryptedKeyNonce: []byte{4},
|
|
|
|
|
2020-11-10 09:17:25 +00:00
|
|
|
EncryptedSize: 1060,
|
2020-11-02 15:28:51 +00:00
|
|
|
PlainSize: 512,
|
2020-11-10 09:17:25 +00:00
|
|
|
PlainOffset: int64(i) * 512,
|
2020-11-02 15:28:51 +00:00
|
|
|
Redundancy: defaultTestRedundancy,
|
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
}
|
|
|
|
|
|
|
|
coOpts := metabase.CommitObject{
|
|
|
|
ObjectStream: obj,
|
|
|
|
}
|
|
|
|
if co.CommitObject != nil {
|
|
|
|
coOpts = *co.CommitObject
|
|
|
|
}
|
|
|
|
|
2020-11-09 14:55:10 +00:00
|
|
|
return CommitObject{
|
2020-11-02 15:28:51 +00:00
|
|
|
Opts: coOpts,
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
}
|