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 (
|
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-02-01 18:02:15 +00:00
|
|
|
"storj.io/common/uuid"
|
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)
|
|
|
|
require.Equal(t, step.Opts.ZombieDeletionDeadline, got.ZombieDeletionDeadline)
|
|
|
|
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-04-26 10:35:44 +01:00
|
|
|
// UpdateObjectMetadata is for testing metabase.UpdateObjectMetadata.
|
2020-11-02 16:32:24 +00:00
|
|
|
type UpdateObjectMetadata struct {
|
|
|
|
Opts metabase.UpdateObjectMetadata
|
|
|
|
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 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)
|
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
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
|
|
|
// GetObjectLatestVersion is for testing metabase.GetObjectLatestVersion.
|
2020-10-28 15:28:06 +00:00
|
|
|
type GetObjectLatestVersion struct {
|
|
|
|
Opts metabase.GetObjectLatestVersion
|
|
|
|
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 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)
|
|
|
|
}
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
// GetSegmentByLocation is for testing metabase.GetSegmentByLocation.
|
2021-02-01 18:02:15 +00:00
|
|
|
type GetSegmentByLocation struct {
|
|
|
|
Opts metabase.GetSegmentByLocation
|
|
|
|
Result metabase.Segment
|
|
|
|
ErrClass *errs.Class
|
|
|
|
ErrText string
|
|
|
|
}
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
// Check runs the test.
|
2021-02-01 18:02:15 +00:00
|
|
|
func (step GetSegmentByLocation) Check(ctx *testcontext.Context, t testing.TB, db *metabase.DB) {
|
|
|
|
result, err := db.GetSegmentByLocation(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
|
|
|
// 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-04-26 10:35:44 +01:00
|
|
|
// IterateLoopStreams is for testing metabase.IterateLoopStreams.
|
2021-03-01 15:27:04 +00:00
|
|
|
type IterateLoopStreams struct {
|
|
|
|
Opts metabase.IterateLoopStreams
|
|
|
|
Result map[uuid.UUID][]metabase.LoopSegmentEntry
|
2021-02-22 16:24:06 +00:00
|
|
|
ErrClass *errs.Class
|
|
|
|
ErrText string
|
|
|
|
}
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
// Check runs the test.
|
2021-03-01 15:27:04 +00:00
|
|
|
func (step IterateLoopStreams) Check(ctx *testcontext.Context, t testing.TB, db *metabase.DB) {
|
|
|
|
result := make(map[uuid.UUID][]metabase.LoopSegmentEntry)
|
|
|
|
err := db.IterateLoopStreams(ctx, step.Opts,
|
|
|
|
func(ctx context.Context, streamID uuid.UUID, next metabase.SegmentIterator) error {
|
|
|
|
var segments []metabase.LoopSegmentEntry
|
|
|
|
for {
|
|
|
|
var segment metabase.LoopSegmentEntry
|
|
|
|
if !next(&segment) {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
segments = append(segments, segment)
|
|
|
|
}
|
|
|
|
result[streamID] = segments
|
|
|
|
return nil
|
|
|
|
})
|
2021-02-22 16:24: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)
|
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
|
|
|
diff := cmp.Diff(step.Result, result, cmpopts.EquateApproxTime(5*time.Second))
|
|
|
|
require.Zero(t, diff)
|
|
|
|
}
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
// DeleteObjectLatestVersion is for testing metabase.DeleteObjectLatestVersion.
|
2020-10-28 15:28:06 +00:00
|
|
|
type DeleteObjectLatestVersion struct {
|
|
|
|
Opts metabase.DeleteObjectLatestVersion
|
|
|
|
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 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-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)
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
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-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
|
|
|
|
}
|