Skip to content

Commit

Permalink
satellite/metabase: TestingGetAllObjects for spanner
Browse files Browse the repository at this point in the history
Change-Id: Id1538dfb070473d0b79c36ef913c5f357b48231d
  • Loading branch information
thepaul authored and Storj Robot committed May 6, 2024
1 parent 6d475df commit c5591ed
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 1 deletion.
15 changes: 15 additions & 0 deletions satellite/metabase/commit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,21 @@ func TestBeginObjectNextVersion(t *testing.T) {
})
}

// Test that TestingGetAllObjects works at least nominally.
// This will probably not be necessary once TestBeginObjectExactVersion
// includes a spanner adapter.
func TestTestingGetAllObjects(t *testing.T) {
metabasetest.Run(t, func(ctx *testcontext.Context, t *testing.T, db *metabase.DB) {
objs, err := db.TestingAllObjects(ctx)
if err != nil {
t.Fatalf("could not query all objects: %v", err)
}
if len(objs) != 0 {
t.Fatalf("expected no objects, but got %+v", objs)
}
}, metabasetest.WithSpanner())
}

func TestBeginObjectExactVersion(t *testing.T) {
metabasetest.Run(t, func(ctx *testcontext.Context, t *testing.T, db *metabase.DB) {
obj := metabasetest.RandObjectStream()
Expand Down
62 changes: 61 additions & 1 deletion satellite/metabase/raw.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,67 @@ func (p *PostgresAdapter) TestingGetAllObjects(ctx context.Context) (_ []RawObje

// TestingGetAllObjects returns the state of the database.
func (s *SpannerAdapter) TestingGetAllObjects(ctx context.Context) (_ []RawObject, err error) {
return nil, nil
objs := []RawObject{}

result := s.client.Single().Query(ctx, spanner.Statement{
SQL: `
SELECT
project_id, bucket_name, object_key, version, stream_id,
created_at, expires_at,
status, segment_count,
encrypted_metadata_nonce, encrypted_metadata, encrypted_metadata_encrypted_key,
total_plain_size, total_encrypted_size, fixed_segment_size,
encryption,
zombie_deletion_deadline
FROM objects
ORDER BY project_id ASC, bucket_name ASC, object_key ASC, version ASC
`,
})
defer result.Stop()

for {
row, err := result.Next()
if err != nil {
if errors.Is(err, iterator.Done) {
break
}
return nil, Error.New("testingGetAllObjects query: %w", err)
}
var obj RawObject
err = row.Columns(
&obj.ProjectID,
&obj.BucketName,
&obj.ObjectKey,
&obj.Version,
&obj.StreamID,

&obj.CreatedAt,
&obj.ExpiresAt,

&obj.Status,
spannerutil.Int(&obj.SegmentCount),

&obj.EncryptedMetadataNonce,
&obj.EncryptedMetadata,
&obj.EncryptedMetadataEncryptedKey,

&obj.TotalPlainSize,
&obj.TotalEncryptedSize,
spannerutil.Int(&obj.FixedSegmentSize),

encryptionParameters{&obj.Encryption},
&obj.ZombieDeletionDeadline,
)
if err != nil {
return nil, Error.New("testingGetAllObjects scan failed: %w", err)
}
objs = append(objs, obj)
}

if len(objs) == 0 {
return nil, nil
}
return objs, nil
}

// TestingBatchInsertObjects batch inserts objects for testing.
Expand Down

0 comments on commit c5591ed

Please sign in to comment.