Skip to content

Commit

Permalink
stores: fix ListObjects not returning etag or mimetype
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisSchinnerl committed Mar 13, 2024
1 parent 148bf94 commit 1ee2f04
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
7 changes: 7 additions & 0 deletions internal/test/e2e/s3_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,13 @@ func TestS3List(t *testing.T) {
if !cmp.Equal(test.want, got) {
t.Errorf("test %d: unexpected response, want %v got %v", i, test.want, got)
}
for _, obj := range result.Contents {
if obj.ETag == "" {
t.Fatal("expected non-empty ETag")
} else if obj.LastModified.IsZero() {
t.Fatal("expected non-zero LastModified")
}
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion stores/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -2894,7 +2894,7 @@ func (s *SQLStore) ListObjects(ctx context.Context, bucket, prefix, sortBy, sort
}
var rows []rawObjectMetadata
if err := s.db.
Select("o.object_id as Name, o.size as Size, o.health as Health, o.mime_type as mimeType, o.created_at as ModTime").
Select("o.object_id as Name, o.size as Size, o.health as Health, o.mime_type as MimeType, o.created_at as ModTime, o.etag as ETag").
Model(&dbObject{}).
Table("objects o").
Joins("INNER JOIN buckets b ON o.db_bucket_id = b.id").
Expand Down
7 changes: 7 additions & 0 deletions stores/metadata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3492,6 +3492,13 @@ func TestListObjects(t *testing.T) {
{"/foo", "size", "ASC", "", []api.ObjectMetadata{{Name: "/foo/bar", Size: 1, Health: 1}, {Name: "/foo/bat", Size: 2, Health: 1}, {Name: "/foo/baz/quux", Size: 3, Health: .75}, {Name: "/foo/baz/quuz", Size: 4, Health: .5}}},
{"/foo", "size", "DESC", "", []api.ObjectMetadata{{Name: "/foo/baz/quuz", Size: 4, Health: .5}, {Name: "/foo/baz/quux", Size: 3, Health: .75}, {Name: "/foo/bat", Size: 2, Health: 1}, {Name: "/foo/bar", Size: 1, Health: 1}}},
}
// set common fields
for i := range tests {
for j := range tests[i].want {
tests[i].want[j].ETag = testETag
tests[i].want[j].MimeType = testMimeType
}
}
for _, test := range tests {
res, err := ss.ListObjects(ctx, api.DefaultBucketName, test.prefix, test.sortBy, test.sortDir, "", -1)
if err != nil {
Expand Down

0 comments on commit 1ee2f04

Please sign in to comment.