satellite/metabase: test list objects with version >1

Assert that listing works with our new object consistency approach.

Half of https://github.com/storj/storj/issues/4868

Change-Id: I5e92f86122b50103cec7bf6d3b2c8ed103caceec
This commit is contained in:
Erik van Velzen 2022-08-26 15:02:57 +02:00 committed by Michal Niewrzal
parent 6ee3993f6c
commit 7c809e2955

View File

@ -5,6 +5,7 @@ package metabase_test
import (
"context"
"math/rand"
"sort"
"strconv"
"testing"
@ -938,6 +939,52 @@ func TestIterateObjectsWithStatus(t *testing.T) {
),
}.Check(ctx, t, db)
})
t.Run("version greater than one", func(t *testing.T) {
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
projectID, bucketName := uuid.UUID{2}, "bucky"
id1 := metabasetest.RandObjectStream()
id1.ProjectID = projectID
id1.BucketName = bucketName
id1.Version = metabase.Version(rand.Int31())
id2 := metabasetest.RandObjectStream()
id2.ProjectID = projectID
id2.BucketName = bucketName
id2.ObjectKey = id1.ObjectKey + "Z" // for deterministic ordering
id2.Version = 1
var objs []metabase.Object
for _, id := range []metabase.ObjectStream{id1, id2} {
obj, _ := metabasetest.CreateTestObject{
BeginObjectExactVersion: &metabase.BeginObjectExactVersion{
ObjectStream: id,
},
CommitObject: &metabase.CommitObject{
ObjectStream: id,
Encryption: metabasetest.DefaultEncryption,
},
}.Run(ctx, t, db, id, 1)
objs = append(objs, obj)
}
metabasetest.IterateObjectsWithStatus{
Opts: metabase.IterateObjectsWithStatus{
ProjectID: projectID,
BucketName: bucketName,
Recursive: true,
Status: metabase.Committed,
BatchSize: 3,
IncludeSystemMetadata: true,
},
Result: []metabase.ObjectEntry{
objectEntryFromRaw(metabase.RawObject(objs[0])),
objectEntryFromRaw(metabase.RawObject(objs[1])),
},
}.Check(ctx, t, db)
})
})
}
@ -1506,6 +1553,7 @@ func objectEntryFromRaw(m metabase.RawObject) metabase.ObjectEntry {
EncryptedMetadata: m.EncryptedMetadata,
EncryptedMetadataEncryptedKey: m.EncryptedMetadataEncryptedKey,
TotalEncryptedSize: m.TotalEncryptedSize,
TotalPlainSize: m.TotalPlainSize,
FixedSegmentSize: m.FixedSegmentSize,
Encryption: m.Encryption,
}