Skip to content

Commit

Permalink
all: cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
peterjan committed Dec 20, 2023
1 parent 10a8b97 commit 420f4db
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 4 deletions.
1 change: 0 additions & 1 deletion api/object.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,6 @@ type (
Metadata map[string]string
}

// TODO PJ: add meta (?)
UploadMultipartUploadPartOptions struct {
DisablePreshardingEncryption bool
EncryptionOffset int
Expand Down
2 changes: 1 addition & 1 deletion s3/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ func (s *s3) GetObject(ctx context.Context, bucketName, objectName string, range
res.Metadata = make(map[string]string)
}

// decorate metadata (TODO PJ: not sure if necessary)
// decorate metadata
res.Metadata["Content-Type"] = res.ContentType
res.Metadata["Last-Modified"] = res.LastModified

Expand Down
1 change: 0 additions & 1 deletion stores/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -2617,7 +2617,6 @@ func (s *SQLStore) ListObjects(ctx context.Context, bucket, prefix, sortBy, sort
Model(&dbObject{}).
Table("objects o").
Joins("INNER JOIN buckets b ON o.db_bucket_id = b.id").
Group("o.object_id").
Where("b.name = ? AND ? AND ?", bucket, prefixExpr, markerExpr).
Order(orderBy).
Order(markerOrderBy).
Expand Down
22 changes: 21 additions & 1 deletion stores/metadata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func TestObjectBasic(t *testing.T) {
}
}

func TestObjectMeta(t *testing.T) {
func TestObjectMetadata(t *testing.T) {
ss := newTestSQLStore(t, defaultTestSQLStoreConfig)
defer ss.Close()

Expand Down Expand Up @@ -183,6 +183,26 @@ func TestObjectMeta(t *testing.T) {
if !reflect.DeepEqual(got.Metadata, testMetadata) {
t.Fatal("meta mismatch", cmp.Diff(got.Metadata, testMetadata))
}

// assert metadata CASCADE on object delete
var cnt int64
if err := ss.db.Model(&dbObjectUserMetadata{}).Count(&cnt).Error; err != nil {
t.Fatal(err)
} else if cnt != 2 {
t.Fatal("unexpected number of metadata entries", cnt)
}

// remove the object
if err := ss.RemoveObject(context.Background(), api.DefaultBucketName, t.Name()); err != nil {
t.Fatal(err)
}

// assert records are gone
if err := ss.db.Model(&dbObjectUserMetadata{}).Count(&cnt).Error; err != nil {
t.Fatal(err)
} else if cnt != 0 {
t.Fatal("unexpected number of metadata entries", cnt)
}
}

// TestSQLContractStore tests SQLContractStore functionality.
Expand Down
7 changes: 7 additions & 0 deletions stores/multipart_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ package stores
import (
"context"
"encoding/hex"
"reflect"
"testing"
"time"

"github.com/google/go-cmp/cmp"
"github.com/klauspost/reedsolomon"
"go.sia.tech/core/types"
"go.sia.tech/renterd/api"
Expand Down Expand Up @@ -92,6 +94,11 @@ func TestMultipartUploadWithUploadPackingRegression(t *testing.T) {
t.Fatalf("expected object total size to be %v, got %v", totalSize, obj.TotalSize())
}

// Assert it has the metadata
if !reflect.DeepEqual(obj.Metadata, testMetadata) {
t.Fatal("meta mismatch", cmp.Diff(obj.Metadata, testMetadata))
}

// Upload buffers.
upload := func(ps api.PackedSlab) api.UploadedPackedSlab {
ups := api.UploadedPackedSlab{
Expand Down

0 comments on commit 420f4db

Please sign in to comment.