2020-10-28 15:28:06 +00:00
|
|
|
// Copyright (C) 2020 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
package metabasetest
|
2020-10-28 15:28:06 +00:00
|
|
|
|
|
|
|
import (
|
2021-05-14 09:57:14 +01: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"
|
2021-04-21 13:42:57 +01:00
|
|
|
"storj.io/storj/satellite/metabase"
|
2020-10-28 15:28:06 +00:00
|
|
|
)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
// BeginObjectNextVersion is for testing metabase.BeginObjectNextVersion.
|
2020-10-28 15:28:06 +00:00
|
|
|
type BeginObjectNextVersion struct {
|
|
|
|
Opts metabase.BeginObjectNextVersion
|
|
|
|
Version metabase.Version
|
|
|
|
ErrClass *errs.Class
|
|
|
|
ErrText string
|
|
|
|
}
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
// Check runs the test.
|
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)
|
|
|
|
}
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
// BeginObjectExactVersion is for testing metabase.BeginObjectExactVersion.
|
2020-10-28 15:28:06 +00:00
|
|
|
type BeginObjectExactVersion struct {
|
|
|
|
Opts metabase.BeginObjectExactVersion
|
|
|
|
Version metabase.Version
|
|
|
|
ErrClass *errs.Class
|
|
|
|
ErrText string
|
|
|
|
}
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
// Check runs the test.
|
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)
|
2021-05-06 12:42:20 +01:00
|
|
|
|
|
|
|
gotDeadline := got.ZombieDeletionDeadline
|
|
|
|
optsDeadline := step.Opts.ZombieDeletionDeadline
|
|
|
|
if optsDeadline == nil {
|
|
|
|
require.WithinDuration(t, time.Now().Add(24*time.Hour), *gotDeadline, 5*time.Second)
|
|
|
|
} else {
|
|
|
|
require.WithinDuration(t, *optsDeadline, *gotDeadline, 5*time.Second)
|
|
|
|
}
|
2021-01-12 11:29:13 +00:00
|
|
|
require.Equal(t, step.Opts.Encryption, got.Encryption)
|
|
|
|
}
|
2020-10-28 15:28:06 +00:00
|
|
|
}
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
// CommitObject is for testing metabase.CommitObject.
|
2020-10-28 15:28:06 +00:00
|
|
|
type CommitObject struct {
|
|
|
|
Opts metabase.CommitObject
|
|
|
|
ErrClass *errs.Class
|
|
|
|
ErrText string
|
|
|
|
}
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
// Check runs the test.
|
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
|
|
|
}
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
// CommitObjectWithSegments is for testing metabase.CommitObjectWithSegments.
|
2020-11-12 11:29:19 +00:00
|
|
|
type CommitObjectWithSegments struct {
|
|
|
|
Opts metabase.CommitObjectWithSegments
|
|
|
|
Deleted []metabase.DeletedSegmentInfo
|
|
|
|
ErrClass *errs.Class
|
|
|
|
ErrText string
|
|
|
|
}
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
// Check runs the test.
|
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
|
|
|
|
}
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
// BeginSegment is for testing metabase.BeginSegment.
|
2020-10-28 15:28:06 +00:00
|
|
|
type BeginSegment struct {
|
|
|
|
Opts metabase.BeginSegment
|
|
|
|
ErrClass *errs.Class
|
|
|
|
ErrText string
|
|
|
|
}
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
// Check runs the test.
|
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)
|
|
|
|
}
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
// CommitSegment is for testing metabase.CommitSegment.
|
2020-10-28 15:28:06 +00:00
|
|
|
type CommitSegment struct {
|
|
|
|
Opts metabase.CommitSegment
|
|
|
|
ErrClass *errs.Class
|
|
|
|
ErrText string
|
|
|
|
}
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
// Check runs the test.
|
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)
|
|
|
|
}
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
// CommitInlineSegment is for testing metabase.CommitInlineSegment.
|
2020-10-28 15:28:06 +00:00
|
|
|
type CommitInlineSegment struct {
|
|
|
|
Opts metabase.CommitInlineSegment
|
|
|
|
ErrClass *errs.Class
|
|
|
|
ErrText string
|
|
|
|
}
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
// Check runs the test.
|
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)
|
|
|
|
}
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
// DeleteBucketObjects is for testing metabase.DeleteBucketObjects.
|
2020-12-09 12:24:37 +00:00
|
|
|
type DeleteBucketObjects struct {
|
|
|
|
Opts metabase.DeleteBucketObjects
|
|
|
|
Deleted int64
|
|
|
|
ErrClass *errs.Class
|
|
|
|
ErrText string
|
|
|
|
}
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
// Check runs the test.
|
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)
|
|
|
|
}
|
|
|
|
|
2021-07-08 15:50:37 +01:00
|
|
|
// UpdateObjectMetadata is for testing metabase.UpdateObjectMetadata.
|
|
|
|
type UpdateObjectMetadata struct {
|
|
|
|
Opts metabase.UpdateObjectMetadata
|
2020-11-02 16:32:24 +00:00
|
|
|
ErrClass *errs.Class
|
|
|
|
ErrText string
|
|
|
|
}
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
// Check runs the test.
|
2021-07-08 15:50:37 +01:00
|
|
|
func (step UpdateObjectMetadata) Check(ctx *testcontext.Context, t testing.TB, db *metabase.DB) {
|
|
|
|
err := db.UpdateObjectMetadata(ctx, step.Opts)
|
2020-11-02 16:32:24 +00:00
|
|
|
checkError(t, err, step.ErrClass, step.ErrText)
|
|
|
|
}
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
// UpdateSegmentPieces is for testing metabase.UpdateSegmentPieces.
|
2020-12-11 12:09:59 +00:00
|
|
|
type UpdateSegmentPieces struct {
|
|
|
|
Opts metabase.UpdateSegmentPieces
|
|
|
|
ErrClass *errs.Class
|
|
|
|
ErrText string
|
|
|
|
}
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
// Check runs the test.
|
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)
|
|
|
|
}
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
// GetObjectExactVersion is for testing metabase.GetObjectExactVersion.
|
2020-10-28 15:28:06 +00:00
|
|
|
type GetObjectExactVersion struct {
|
|
|
|
Opts metabase.GetObjectExactVersion
|
|
|
|
Result metabase.Object
|
|
|
|
ErrClass *errs.Class
|
|
|
|
ErrText string
|
|
|
|
}
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
// Check runs the test.
|
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)
|
2021-02-01 18:02:15 +00:00
|
|
|
checkError(t, err, step.ErrClass, step.ErrText)
|
|
|
|
|
|
|
|
diff := cmp.Diff(step.Result, result, cmpopts.EquateApproxTime(5*time.Second))
|
|
|
|
require.Zero(t, diff)
|
|
|
|
}
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
// GetSegmentByPosition is for testing metabase.GetSegmentByPosition.
|
2020-10-28 15:28:06 +00:00
|
|
|
type GetSegmentByPosition struct {
|
|
|
|
Opts metabase.GetSegmentByPosition
|
|
|
|
Result metabase.Segment
|
|
|
|
ErrClass *errs.Class
|
|
|
|
ErrText string
|
|
|
|
}
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
// Check runs the test.
|
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)
|
|
|
|
}
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
// GetLatestObjectLastSegment is for testing metabase.GetLatestObjectLastSegment.
|
2020-11-03 15:03:20 +00:00
|
|
|
type GetLatestObjectLastSegment struct {
|
|
|
|
Opts metabase.GetLatestObjectLastSegment
|
|
|
|
Result metabase.Segment
|
|
|
|
ErrClass *errs.Class
|
|
|
|
ErrText string
|
|
|
|
}
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
// Check runs the test.
|
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)
|
|
|
|
}
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
// GetSegmentByOffset is for testing metabase.GetSegmentByOffset.
|
2020-11-10 09:17:25 +00:00
|
|
|
type GetSegmentByOffset struct {
|
|
|
|
Opts metabase.GetSegmentByOffset
|
|
|
|
Result metabase.Segment
|
|
|
|
ErrClass *errs.Class
|
|
|
|
ErrText string
|
|
|
|
}
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
// Check runs the test.
|
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)
|
|
|
|
}
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
// BucketEmpty is for testing metabase.BucketEmpty.
|
2020-11-17 17:37:58 +00:00
|
|
|
type BucketEmpty struct {
|
|
|
|
Opts metabase.BucketEmpty
|
|
|
|
Result bool
|
|
|
|
ErrClass *errs.Class
|
|
|
|
ErrText string
|
|
|
|
}
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
// Check runs the test.
|
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)
|
|
|
|
}
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
// ListSegments is for testing metabase.ListSegments.
|
2020-11-05 12:59:19 +00:00
|
|
|
type ListSegments struct {
|
|
|
|
Opts metabase.ListSegments
|
|
|
|
Result metabase.ListSegmentsResult
|
|
|
|
ErrClass *errs.Class
|
|
|
|
ErrText string
|
|
|
|
}
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
// Check runs the test.
|
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)
|
|
|
|
}
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
// ListStreamPositions is for testing metabase.ListStreamPositions.
|
2021-03-08 12:09:22 +00:00
|
|
|
type ListStreamPositions struct {
|
|
|
|
Opts metabase.ListStreamPositions
|
|
|
|
Result metabase.ListStreamPositionsResult
|
|
|
|
ErrClass *errs.Class
|
|
|
|
ErrText string
|
|
|
|
}
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
// Check runs the test.
|
2021-03-08 12:09:22 +00:00
|
|
|
func (step ListStreamPositions) Check(ctx *testcontext.Context, t testing.TB, db *metabase.DB) {
|
|
|
|
result, err := db.ListStreamPositions(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-04-26 10:35:44 +01:00
|
|
|
// GetStreamPieceCountByNodeID is for testing metabase.GetStreamPieceCountByNodeID.
|
2021-03-08 13:09:32 +00:00
|
|
|
type GetStreamPieceCountByNodeID struct {
|
|
|
|
Opts metabase.GetStreamPieceCountByNodeID
|
|
|
|
Result map[storj.NodeID]int64
|
|
|
|
ErrClass *errs.Class
|
|
|
|
ErrText string
|
|
|
|
}
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
// Check runs the test.
|
2021-03-08 13:09:32 +00:00
|
|
|
func (step GetStreamPieceCountByNodeID) Check(ctx *testcontext.Context, t testing.TB, db *metabase.DB) {
|
|
|
|
result, err := db.GetStreamPieceCountByNodeID(ctx, step.Opts)
|
|
|
|
checkError(t, err, step.ErrClass, step.ErrText)
|
|
|
|
|
|
|
|
diff := cmp.Diff(step.Result, result)
|
|
|
|
require.Zero(t, diff)
|
|
|
|
}
|
|
|
|
|
2021-05-14 09:57:14 +01:00
|
|
|
// IterateLoopSegments is for testing metabase.IterateLoopSegments.
|
|
|
|
type IterateLoopSegments struct {
|
|
|
|
Opts metabase.IterateLoopSegments
|
|
|
|
Result []metabase.LoopSegmentEntry
|
|
|
|
ErrClass *errs.Class
|
|
|
|
ErrText string
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check runs the test.
|
|
|
|
func (step IterateLoopSegments) Check(ctx *testcontext.Context, t testing.TB, db *metabase.DB) {
|
|
|
|
result := make([]metabase.LoopSegmentEntry, 0, 10)
|
|
|
|
err := db.IterateLoopSegments(ctx, step.Opts,
|
|
|
|
func(ctx context.Context, iterator metabase.LoopSegmentsIterator) error {
|
|
|
|
var entry metabase.LoopSegmentEntry
|
|
|
|
for iterator.Next(ctx, &entry) {
|
|
|
|
result = append(result, entry)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
checkError(t, err, step.ErrClass, step.ErrText)
|
|
|
|
|
|
|
|
if len(result) == 0 {
|
|
|
|
result = nil
|
|
|
|
}
|
|
|
|
|
|
|
|
sort.Slice(step.Result, func(i, j int) bool {
|
|
|
|
return bytes.Compare(step.Result[i].StreamID[:], step.Result[j].StreamID[:]) < 0
|
|
|
|
})
|
|
|
|
diff := cmp.Diff(step.Result, result, cmpopts.EquateApproxTime(5*time.Second))
|
|
|
|
require.Zero(t, diff)
|
|
|
|
}
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
// DeleteObjectExactVersion is for testing metabase.DeleteObjectExactVersion.
|
2020-10-28 15:28:06 +00:00
|
|
|
type DeleteObjectExactVersion struct {
|
|
|
|
Opts metabase.DeleteObjectExactVersion
|
|
|
|
Result metabase.DeleteObjectResult
|
|
|
|
ErrClass *errs.Class
|
|
|
|
ErrText string
|
|
|
|
}
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
// Check runs the test.
|
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)
|
|
|
|
|
2021-05-07 10:36:02 +01:00
|
|
|
sortObjects(result.Objects)
|
|
|
|
sortObjects(step.Result.Objects)
|
|
|
|
|
|
|
|
sortDeletedSegments(result.Segments)
|
|
|
|
sortDeletedSegments(step.Result.Segments)
|
|
|
|
|
2020-10-28 15:28:06 +00:00
|
|
|
diff := cmp.Diff(step.Result, result, cmpopts.EquateApproxTime(5*time.Second))
|
|
|
|
require.Zero(t, diff)
|
|
|
|
}
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
// DeletePendingObject is for testing metabase.DeletePendingObject.
|
2020-12-01 23:17:05 +00:00
|
|
|
type DeletePendingObject struct {
|
|
|
|
Opts metabase.DeletePendingObject
|
|
|
|
Result metabase.DeleteObjectResult
|
|
|
|
ErrClass *errs.Class
|
|
|
|
ErrText string
|
|
|
|
}
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
// Check runs the test.
|
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)
|
|
|
|
|
2021-05-07 10:36:02 +01:00
|
|
|
sortObjects(result.Objects)
|
|
|
|
sortObjects(step.Result.Objects)
|
|
|
|
|
|
|
|
sortDeletedSegments(result.Segments)
|
|
|
|
sortDeletedSegments(step.Result.Segments)
|
|
|
|
|
2020-12-01 23:17:05 +00:00
|
|
|
diff := cmp.Diff(step.Result, result, cmpopts.EquateApproxTime(5*time.Second))
|
|
|
|
require.Zero(t, diff)
|
|
|
|
}
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
// DeleteObjectAnyStatusAllVersions is for testing metabase.DeleteObjectAnyStatusAllVersions.
|
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-04-26 10:35:44 +01:00
|
|
|
// Check runs the test.
|
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)
|
|
|
|
|
2021-05-07 10:36:02 +01:00
|
|
|
sortObjects(result.Objects)
|
|
|
|
sortObjects(step.Result.Objects)
|
|
|
|
|
|
|
|
sortDeletedSegments(result.Segments)
|
|
|
|
sortDeletedSegments(step.Result.Segments)
|
|
|
|
|
2020-10-28 15:28:06 +00:00
|
|
|
diff := cmp.Diff(step.Result, result, cmpopts.EquateApproxTime(5*time.Second))
|
|
|
|
require.Zero(t, diff)
|
|
|
|
}
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
// DeleteObjectsAllVersions is for testing metabase.DeleteObjectsAllVersions.
|
2020-11-03 15:51:03 +00:00
|
|
|
type DeleteObjectsAllVersions struct {
|
|
|
|
Opts metabase.DeleteObjectsAllVersions
|
|
|
|
Result metabase.DeleteObjectResult
|
|
|
|
ErrClass *errs.Class
|
|
|
|
ErrText string
|
|
|
|
}
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
// Check runs the test.
|
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
|
|
|
|
2021-05-07 10:36:02 +01:00
|
|
|
sortDeletedSegments(result.Segments)
|
|
|
|
sortDeletedSegments(step.Result.Segments)
|
|
|
|
|
2020-11-03 15:51:03 +00:00
|
|
|
diff := cmp.Diff(step.Result, result, cmpopts.EquateApproxTime(5*time.Second))
|
|
|
|
require.Zero(t, diff)
|
|
|
|
}
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
// DeleteExpiredObjects is for testing metabase.DeleteExpiredObjects.
|
2020-11-09 14:55:10 +00:00
|
|
|
type DeleteExpiredObjects struct {
|
2021-04-16 10:14:27 +01:00
|
|
|
Opts metabase.DeleteExpiredObjects
|
|
|
|
|
2020-11-09 14:55:10 +00:00
|
|
|
ErrClass *errs.Class
|
|
|
|
ErrText string
|
|
|
|
}
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
// Check runs the test.
|
2021-01-22 17:34:08 +00:00
|
|
|
func (step DeleteExpiredObjects) Check(ctx *testcontext.Context, t testing.TB, db *metabase.DB) {
|
2021-04-16 10:14:27 +01:00
|
|
|
err := db.DeleteExpiredObjects(ctx, step.Opts)
|
2020-11-09 14:55:10 +00:00
|
|
|
checkError(t, err, step.ErrClass, step.ErrText)
|
|
|
|
}
|
|
|
|
|
2021-04-29 10:21:29 +01:00
|
|
|
// DeleteZombieObjects is for testing metabase.DeleteZombieObjects.
|
|
|
|
type DeleteZombieObjects struct {
|
|
|
|
Opts metabase.DeleteZombieObjects
|
|
|
|
|
|
|
|
ErrClass *errs.Class
|
|
|
|
ErrText string
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check runs the test.
|
|
|
|
func (step DeleteZombieObjects) Check(ctx *testcontext.Context, t testing.TB, db *metabase.DB) {
|
|
|
|
err := db.DeleteZombieObjects(ctx, step.Opts)
|
|
|
|
checkError(t, err, step.ErrClass, step.ErrText)
|
|
|
|
}
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
// IterateCollector is for testing metabase.IterateCollector.
|
2020-10-29 18:10:46 +00:00
|
|
|
type IterateCollector []metabase.ObjectEntry
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
// Add adds object entries from iterator to the collection.
|
2020-10-29 18:10:46 +00:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
// LoopIterateCollector is for testing metabase.LoopIterateCollector.
|
2021-03-01 14:29:03 +00:00
|
|
|
type LoopIterateCollector []metabase.LoopObjectEntry
|
2021-02-18 12:54:09 +00:00
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
// Add adds object entries from iterator to the collection.
|
2021-03-01 14:29:03 +00:00
|
|
|
func (coll *LoopIterateCollector) Add(ctx context.Context, it metabase.LoopObjectsIterator) error {
|
|
|
|
var item metabase.LoopObjectEntry
|
2021-02-18 12:54:09 +00:00
|
|
|
|
|
|
|
for it.Next(ctx, &item) {
|
|
|
|
*coll = append(*coll, item)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
// IterateObjects is for testing metabase.IterateObjects.
|
2020-12-21 16:43:08 +00:00
|
|
|
type IterateObjects struct {
|
|
|
|
Opts metabase.IterateObjects
|
|
|
|
|
|
|
|
Result []metabase.ObjectEntry
|
|
|
|
ErrClass *errs.Class
|
|
|
|
ErrText string
|
|
|
|
}
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
// Check runs the test.
|
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)
|
|
|
|
}
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
// IteratePendingObjectsByKey is for testing metabase.IteratePendingObjectsByKey.
|
2021-01-11 12:06:04 +00:00
|
|
|
type IteratePendingObjectsByKey struct {
|
|
|
|
Opts metabase.IteratePendingObjectsByKey
|
|
|
|
|
|
|
|
Result []metabase.ObjectEntry
|
|
|
|
ErrClass *errs.Class
|
|
|
|
ErrText string
|
|
|
|
}
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
// Check runs the test.
|
2021-01-11 12:06:04 +00:00
|
|
|
func (step IteratePendingObjectsByKey) Check(ctx *testcontext.Context, t *testing.T, db *metabase.DB) {
|
|
|
|
var collector IterateCollector
|
|
|
|
|
|
|
|
err := db.IteratePendingObjectsByKey(ctx, step.Opts, collector.Add)
|
|
|
|
checkError(t, err, step.ErrClass, step.ErrText)
|
|
|
|
|
|
|
|
result := []metabase.ObjectEntry(collector)
|
|
|
|
|
|
|
|
diff := cmp.Diff(step.Result, result, cmpopts.EquateApproxTime(5*time.Second))
|
|
|
|
require.Zero(t, diff)
|
|
|
|
}
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
// IterateObjectsWithStatus is for testing metabase.IterateObjectsWithStatus.
|
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-04-26 10:35:44 +01:00
|
|
|
// Check runs the test.
|
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-02-18 12:54:09 +00:00
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
// IterateLoopObjects is for testing metabase.IterateLoopObjects.
|
2021-03-01 14:29:03 +00:00
|
|
|
type IterateLoopObjects struct {
|
|
|
|
Opts metabase.IterateLoopObjects
|
2021-02-18 12:54:09 +00:00
|
|
|
|
2021-03-01 14:29:03 +00:00
|
|
|
Result []metabase.LoopObjectEntry
|
2021-02-18 12:54:09 +00:00
|
|
|
ErrClass *errs.Class
|
|
|
|
ErrText string
|
|
|
|
}
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
// Check runs the test.
|
2021-03-01 14:29:03 +00:00
|
|
|
func (step IterateLoopObjects) Check(ctx *testcontext.Context, t testing.TB, db *metabase.DB) {
|
|
|
|
var result LoopIterateCollector
|
2021-02-18 12:54:09 +00:00
|
|
|
|
2021-03-01 14:29:03 +00:00
|
|
|
err := db.IterateLoopObjects(ctx, step.Opts, result.Add)
|
2021-02-18 12:54:09 +00:00
|
|
|
checkError(t, err, step.ErrClass, step.ErrText)
|
|
|
|
|
2021-03-01 14:29:03 +00:00
|
|
|
diff := cmp.Diff(step.Result, []metabase.LoopObjectEntry(result), cmpopts.EquateApproxTime(5*time.Second))
|
2021-02-18 12:54:09 +00:00
|
|
|
require.Zero(t, diff)
|
|
|
|
}
|
2020-10-29 18:10:46 +00:00
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
// EnsureNodeAliases is for testing metabase.EnsureNodeAliases.
|
2021-02-04 15:12:34 +00:00
|
|
|
type EnsureNodeAliases struct {
|
|
|
|
Opts metabase.EnsureNodeAliases
|
|
|
|
|
|
|
|
ErrClass *errs.Class
|
|
|
|
ErrText string
|
|
|
|
}
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
// Check runs the test.
|
2021-02-04 15:12:34 +00:00
|
|
|
func (step EnsureNodeAliases) Check(ctx *testcontext.Context, t testing.TB, db *metabase.DB) {
|
|
|
|
err := db.EnsureNodeAliases(ctx, step.Opts)
|
|
|
|
checkError(t, err, step.ErrClass, step.ErrText)
|
|
|
|
}
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
// ListNodeAliases is for testing metabase.ListNodeAliases.
|
2021-02-04 15:12:34 +00:00
|
|
|
type ListNodeAliases struct {
|
|
|
|
ErrClass *errs.Class
|
|
|
|
ErrText string
|
|
|
|
}
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
// Check runs the test.
|
2021-02-04 15:12:34 +00:00
|
|
|
func (step ListNodeAliases) Check(ctx *testcontext.Context, t testing.TB, db *metabase.DB) []metabase.NodeAliasEntry {
|
|
|
|
result, err := db.ListNodeAliases(ctx)
|
|
|
|
checkError(t, err, step.ErrClass, step.ErrText)
|
|
|
|
return result
|
|
|
|
}
|
2021-04-30 12:02:24 +01:00
|
|
|
|
2021-06-07 10:20:06 +01:00
|
|
|
// GetTableStats is for testing metabase.GetTableStats.
|
|
|
|
type GetTableStats struct {
|
|
|
|
Opts metabase.GetTableStats
|
|
|
|
Result metabase.TableStats
|
|
|
|
ErrClass *errs.Class
|
|
|
|
ErrText string
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check runs the test.
|
|
|
|
func (step GetTableStats) Check(ctx *testcontext.Context, t testing.TB, db *metabase.DB) metabase.TableStats {
|
|
|
|
result, err := db.GetTableStats(ctx, step.Opts)
|
|
|
|
checkError(t, err, step.ErrClass, step.ErrText)
|
|
|
|
|
|
|
|
diff := cmp.Diff(step.Result, result)
|
|
|
|
require.Zero(t, diff)
|
|
|
|
|
|
|
|
return result
|
|
|
|
}
|
2021-08-16 13:04:33 +01:00
|
|
|
|
|
|
|
// BeginMoveObject is for testing metabase.BeginMoveObject.
|
|
|
|
type BeginMoveObject struct {
|
|
|
|
Opts metabase.BeginMoveObject
|
|
|
|
Result metabase.BeginMoveObjectResult
|
|
|
|
ErrClass *errs.Class
|
|
|
|
ErrText string
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check runs the test.
|
|
|
|
func (step BeginMoveObject) Check(ctx *testcontext.Context, t testing.TB, db *metabase.DB) {
|
|
|
|
result, err := db.BeginMoveObject(ctx, step.Opts)
|
|
|
|
checkError(t, err, step.ErrClass, step.ErrText)
|
|
|
|
|
|
|
|
diff := cmp.Diff(step.Result, result)
|
|
|
|
require.Zero(t, diff)
|
|
|
|
}
|
2021-08-31 12:44:18 +01:00
|
|
|
|
|
|
|
// FinishMoveObject is for testing metabase.FinishMoveObject.
|
|
|
|
type FinishMoveObject struct {
|
|
|
|
Opts metabase.FinishMoveObject
|
|
|
|
ErrClass *errs.Class
|
|
|
|
ErrText string
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check runs the test.
|
|
|
|
func (step FinishMoveObject) Check(ctx *testcontext.Context, t testing.TB, db *metabase.DB) {
|
|
|
|
err := db.FinishMoveObject(ctx, step.Opts)
|
|
|
|
checkError(t, err, step.ErrClass, step.ErrText)
|
|
|
|
}
|
2021-11-22 13:56:58 +00:00
|
|
|
|
2022-01-27 00:01:03 +00:00
|
|
|
// BeginCopyObject is for testing metabase.BeginCopyObject.
|
|
|
|
type BeginCopyObject struct {
|
|
|
|
Opts metabase.BeginCopyObject
|
|
|
|
Result metabase.BeginCopyObjectResult
|
|
|
|
ErrClass *errs.Class
|
|
|
|
ErrText string
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check runs the test.
|
|
|
|
func (step BeginCopyObject) Check(ctx *testcontext.Context, t testing.TB, db *metabase.DB) {
|
|
|
|
result, err := db.BeginCopyObject(ctx, step.Opts)
|
|
|
|
checkError(t, err, step.ErrClass, step.ErrText)
|
|
|
|
|
|
|
|
diff := cmp.Diff(step.Result, result)
|
|
|
|
require.Zero(t, diff)
|
|
|
|
}
|
|
|
|
|
|
|
|
// FinishCopyObject is for testing metabase.FinishCopyObject.
|
|
|
|
type FinishCopyObject struct {
|
|
|
|
Opts metabase.FinishCopyObject
|
2022-02-24 10:54:57 +00:00
|
|
|
Result metabase.Object
|
2022-01-27 00:01:03 +00:00
|
|
|
ErrClass *errs.Class
|
|
|
|
ErrText string
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check runs the test.
|
|
|
|
func (step FinishCopyObject) Check(ctx *testcontext.Context, t testing.TB, db *metabase.DB) {
|
2022-02-24 10:54:57 +00:00
|
|
|
result, err := db.FinishCopyObject(ctx, step.Opts)
|
2022-01-27 00:01:03 +00:00
|
|
|
checkError(t, err, step.ErrClass, step.ErrText)
|
2022-02-24 10:54:57 +00:00
|
|
|
|
|
|
|
diff := cmp.Diff(step.Result, result, cmpopts.EquateApproxTime(5*time.Second))
|
|
|
|
require.Zero(t, diff)
|
2022-01-27 00:01:03 +00:00
|
|
|
}
|
|
|
|
|
2021-11-22 13:56:58 +00:00
|
|
|
// GetProjectSegmentCount is for testing metabase.GetProjectSegmentCount.
|
|
|
|
type GetProjectSegmentCount struct {
|
|
|
|
Opts metabase.GetProjectSegmentCount
|
|
|
|
Result int64
|
|
|
|
ErrClass *errs.Class
|
|
|
|
ErrText string
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check runs the test.
|
|
|
|
func (step GetProjectSegmentCount) Check(ctx *testcontext.Context, t testing.TB, db *metabase.DB) {
|
|
|
|
result, err := db.GetProjectSegmentCount(ctx, step.Opts)
|
|
|
|
checkError(t, err, step.ErrClass, step.ErrText)
|
|
|
|
require.Equal(t, step.Result, result)
|
|
|
|
}
|