Skip to content

Commit

Permalink
testing: assert metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
peterjan committed Dec 20, 2023
1 parent dfb3471 commit 36d72ab
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
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 36d72ab

Please sign in to comment.