satellite/metabase/metabasetest: condense creation logic
Change-Id: I7f82c34fe5aab2a49e4c8feeacddc8fa0f8809e5
This commit is contained in:
parent
25c4e4eec1
commit
ca9ab74df8
@ -42,7 +42,7 @@ func RandEncryptedKeyAndNonce(position int) metabase.EncryptedKeyAndNonce {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// CreatePendingObject creates a new pending object with the specified number of segments.
|
// CreatePendingObject creates a new pending object with the specified number of segments.
|
||||||
func CreatePendingObject(ctx *testcontext.Context, t *testing.T, db *metabase.DB, obj metabase.ObjectStream, numberOfSegments byte) {
|
func CreatePendingObject(ctx *testcontext.Context, t testing.TB, db *metabase.DB, obj metabase.ObjectStream, numberOfSegments byte) {
|
||||||
BeginObjectExactVersion{
|
BeginObjectExactVersion{
|
||||||
Opts: metabase.BeginObjectExactVersion{
|
Opts: metabase.BeginObjectExactVersion{
|
||||||
ObjectStream: obj,
|
ObjectStream: obj,
|
||||||
@ -50,42 +50,12 @@ func CreatePendingObject(ctx *testcontext.Context, t *testing.T, db *metabase.DB
|
|||||||
},
|
},
|
||||||
}.Check(ctx, t, db)
|
}.Check(ctx, t, db)
|
||||||
|
|
||||||
for i := byte(0); i < numberOfSegments; i++ {
|
CreateSegments(ctx, t, db, obj, nil, numberOfSegments)
|
||||||
BeginSegment{
|
|
||||||
Opts: metabase.BeginSegment{
|
|
||||||
ObjectStream: obj,
|
|
||||||
Position: metabase.SegmentPosition{Part: 0, Index: uint32(i)},
|
|
||||||
RootPieceID: storj.PieceID{i + 1},
|
|
||||||
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},
|
|
||||||
EncryptedETag: []byte{5},
|
|
||||||
|
|
||||||
EncryptedSize: 1024,
|
|
||||||
PlainSize: 512,
|
|
||||||
PlainOffset: 0,
|
|
||||||
Redundancy: DefaultRedundancy,
|
|
||||||
},
|
|
||||||
}.Check(ctx, t, db)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreatePendingObjectNew creates a new pending object with the specified number of segments.
|
// CreatePendingObjectNew creates a new pending object with the specified number of segments.
|
||||||
// TODO CreatePendingObject will be removed when transition to pending_objects table will be complete.
|
// TODO CreatePendingObject will be removed when transition to pending_objects table will be complete.
|
||||||
func CreatePendingObjectNew(ctx *testcontext.Context, t *testing.T, db *metabase.DB, obj metabase.ObjectStream, numberOfSegments byte) {
|
func CreatePendingObjectNew(ctx *testcontext.Context, t testing.TB, db *metabase.DB, obj metabase.ObjectStream, numberOfSegments byte) {
|
||||||
obj.Version = metabase.NextVersion
|
obj.Version = metabase.NextVersion
|
||||||
BeginObjectNextVersion{
|
BeginObjectNextVersion{
|
||||||
Opts: metabase.BeginObjectNextVersion{
|
Opts: metabase.BeginObjectNextVersion{
|
||||||
@ -132,45 +102,8 @@ func CreatePendingObjectNew(ctx *testcontext.Context, t *testing.T, db *metabase
|
|||||||
}
|
}
|
||||||
|
|
||||||
// CreateObject creates a new committed object with the specified number of segments.
|
// CreateObject creates a new committed object with the specified number of segments.
|
||||||
func CreateObject(ctx *testcontext.Context, t require.TestingT, db *metabase.DB, obj metabase.ObjectStream, numberOfSegments byte) metabase.Object {
|
func CreateObject(ctx *testcontext.Context, t testing.TB, db *metabase.DB, obj metabase.ObjectStream, numberOfSegments byte) metabase.Object {
|
||||||
BeginObjectExactVersion{
|
CreatePendingObject(ctx, t, db, obj, numberOfSegments)
|
||||||
Opts: metabase.BeginObjectExactVersion{
|
|
||||||
ObjectStream: obj,
|
|
||||||
Encryption: DefaultEncryption,
|
|
||||||
},
|
|
||||||
}.Check(ctx, t, db)
|
|
||||||
|
|
||||||
for i := byte(0); i < numberOfSegments; i++ {
|
|
||||||
BeginSegment{
|
|
||||||
Opts: metabase.BeginSegment{
|
|
||||||
ObjectStream: obj,
|
|
||||||
Position: metabase.SegmentPosition{Part: 0, Index: uint32(i)},
|
|
||||||
RootPieceID: storj.PieceID{i + 1},
|
|
||||||
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},
|
|
||||||
EncryptedETag: []byte{5},
|
|
||||||
|
|
||||||
EncryptedSize: 1024,
|
|
||||||
PlainSize: 512,
|
|
||||||
PlainOffset: 0,
|
|
||||||
Redundancy: DefaultRedundancy,
|
|
||||||
},
|
|
||||||
}.Check(ctx, t, db)
|
|
||||||
}
|
|
||||||
|
|
||||||
return CommitObject{
|
return CommitObject{
|
||||||
Opts: metabase.CommitObject{
|
Opts: metabase.CommitObject{
|
||||||
@ -180,45 +113,8 @@ func CreateObject(ctx *testcontext.Context, t require.TestingT, db *metabase.DB,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// CreateObjectVersioned creates a new committed object with the specified number of segments.
|
// CreateObjectVersioned creates a new committed object with the specified number of segments.
|
||||||
func CreateObjectVersioned(ctx *testcontext.Context, t require.TestingT, db *metabase.DB, obj metabase.ObjectStream, numberOfSegments byte) metabase.Object {
|
func CreateObjectVersioned(ctx *testcontext.Context, t testing.TB, db *metabase.DB, obj metabase.ObjectStream, numberOfSegments byte) metabase.Object {
|
||||||
BeginObjectExactVersion{
|
CreatePendingObject(ctx, t, db, obj, numberOfSegments)
|
||||||
Opts: metabase.BeginObjectExactVersion{
|
|
||||||
ObjectStream: obj,
|
|
||||||
Encryption: DefaultEncryption,
|
|
||||||
},
|
|
||||||
}.Check(ctx, t, db)
|
|
||||||
|
|
||||||
for i := byte(0); i < numberOfSegments; i++ {
|
|
||||||
BeginSegment{
|
|
||||||
Opts: metabase.BeginSegment{
|
|
||||||
ObjectStream: obj,
|
|
||||||
Position: metabase.SegmentPosition{Part: 0, Index: uint32(i)},
|
|
||||||
RootPieceID: storj.PieceID{i + 1},
|
|
||||||
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},
|
|
||||||
EncryptedETag: []byte{5},
|
|
||||||
|
|
||||||
EncryptedSize: 1024,
|
|
||||||
PlainSize: 512,
|
|
||||||
PlainOffset: 0,
|
|
||||||
Redundancy: DefaultRedundancy,
|
|
||||||
},
|
|
||||||
}.Check(ctx, t, db)
|
|
||||||
}
|
|
||||||
|
|
||||||
return CommitObject{
|
return CommitObject{
|
||||||
Opts: metabase.CommitObject{
|
Opts: metabase.CommitObject{
|
||||||
@ -229,7 +125,7 @@ func CreateObjectVersioned(ctx *testcontext.Context, t require.TestingT, db *met
|
|||||||
}
|
}
|
||||||
|
|
||||||
// CreateExpiredObject creates a new committed expired object with the specified number of segments.
|
// CreateExpiredObject creates a new committed expired object with the specified number of segments.
|
||||||
func CreateExpiredObject(ctx *testcontext.Context, t *testing.T, db *metabase.DB, obj metabase.ObjectStream, numberOfSegments byte, expiresAt time.Time) metabase.Object {
|
func CreateExpiredObject(ctx *testcontext.Context, t testing.TB, db *metabase.DB, obj metabase.ObjectStream, numberOfSegments byte, expiresAt time.Time) metabase.Object {
|
||||||
BeginObjectExactVersion{
|
BeginObjectExactVersion{
|
||||||
Opts: metabase.BeginObjectExactVersion{
|
Opts: metabase.BeginObjectExactVersion{
|
||||||
ObjectStream: obj,
|
ObjectStream: obj,
|
||||||
@ -238,38 +134,7 @@ func CreateExpiredObject(ctx *testcontext.Context, t *testing.T, db *metabase.DB
|
|||||||
},
|
},
|
||||||
}.Check(ctx, t, db)
|
}.Check(ctx, t, db)
|
||||||
|
|
||||||
for i := byte(0); i < numberOfSegments; i++ {
|
CreateSegments(ctx, t, db, obj, &expiresAt, numberOfSegments)
|
||||||
BeginSegment{
|
|
||||||
Opts: metabase.BeginSegment{
|
|
||||||
ObjectStream: obj,
|
|
||||||
Position: metabase.SegmentPosition{Part: 0, Index: uint32(i)},
|
|
||||||
RootPieceID: storj.PieceID{i + 1},
|
|
||||||
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)},
|
|
||||||
ExpiresAt: &expiresAt,
|
|
||||||
RootPieceID: storj.PieceID{1},
|
|
||||||
Pieces: metabase.Pieces{{Number: 0, StorageNode: storj.NodeID{2}}},
|
|
||||||
|
|
||||||
EncryptedKey: []byte{3},
|
|
||||||
EncryptedKeyNonce: []byte{4},
|
|
||||||
EncryptedETag: []byte{5},
|
|
||||||
|
|
||||||
EncryptedSize: 1024,
|
|
||||||
PlainSize: 512,
|
|
||||||
PlainOffset: 0,
|
|
||||||
Redundancy: DefaultRedundancy,
|
|
||||||
},
|
|
||||||
}.Check(ctx, t, db)
|
|
||||||
}
|
|
||||||
|
|
||||||
return CommitObject{
|
return CommitObject{
|
||||||
Opts: metabase.CommitObject{
|
Opts: metabase.CommitObject{
|
||||||
@ -279,7 +144,7 @@ func CreateExpiredObject(ctx *testcontext.Context, t *testing.T, db *metabase.DB
|
|||||||
}
|
}
|
||||||
|
|
||||||
// CreateFullObjectsWithKeys creates multiple objects with the specified keys.
|
// CreateFullObjectsWithKeys creates multiple objects with the specified keys.
|
||||||
func CreateFullObjectsWithKeys(ctx *testcontext.Context, t *testing.T, db *metabase.DB, projectID uuid.UUID, bucketName string, keys []metabase.ObjectKey) map[metabase.ObjectKey]metabase.LoopObjectEntry {
|
func CreateFullObjectsWithKeys(ctx *testcontext.Context, t testing.TB, db *metabase.DB, projectID uuid.UUID, bucketName string, keys []metabase.ObjectKey) map[metabase.ObjectKey]metabase.LoopObjectEntry {
|
||||||
objects := make(map[metabase.ObjectKey]metabase.LoopObjectEntry, len(keys))
|
objects := make(map[metabase.ObjectKey]metabase.LoopObjectEntry, len(keys))
|
||||||
for _, key := range keys {
|
for _, key := range keys {
|
||||||
obj := RandObjectStream()
|
obj := RandObjectStream()
|
||||||
@ -299,6 +164,44 @@ func CreateFullObjectsWithKeys(ctx *testcontext.Context, t *testing.T, db *metab
|
|||||||
return objects
|
return objects
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CreateSegments creates multiple segments for the specified object.
|
||||||
|
func CreateSegments(ctx *testcontext.Context, t testing.TB, db *metabase.DB, obj metabase.ObjectStream, expiresAt *time.Time, numberOfSegments byte) {
|
||||||
|
for i := byte(0); i < numberOfSegments; i++ {
|
||||||
|
BeginSegment{
|
||||||
|
Opts: metabase.BeginSegment{
|
||||||
|
ObjectStream: obj,
|
||||||
|
Position: metabase.SegmentPosition{Part: 0, Index: uint32(i)},
|
||||||
|
RootPieceID: storj.PieceID{i + 1},
|
||||||
|
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},
|
||||||
|
|
||||||
|
ExpiresAt: expiresAt,
|
||||||
|
|
||||||
|
Pieces: metabase.Pieces{{Number: 0, StorageNode: storj.NodeID{2}}},
|
||||||
|
|
||||||
|
EncryptedKey: []byte{3},
|
||||||
|
EncryptedKeyNonce: []byte{4},
|
||||||
|
EncryptedETag: []byte{5},
|
||||||
|
|
||||||
|
EncryptedSize: 1024,
|
||||||
|
PlainSize: 512,
|
||||||
|
PlainOffset: 0,
|
||||||
|
Redundancy: DefaultRedundancy,
|
||||||
|
},
|
||||||
|
}.Check(ctx, t, db)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// CreateTestObject is for testing metabase.CreateTestObject.
|
// CreateTestObject is for testing metabase.CreateTestObject.
|
||||||
type CreateTestObject struct {
|
type CreateTestObject struct {
|
||||||
BeginObjectExactVersion *metabase.BeginObjectExactVersion
|
BeginObjectExactVersion *metabase.BeginObjectExactVersion
|
||||||
|
Loading…
Reference in New Issue
Block a user