Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 14 additions & 11 deletions registry/postgres_live_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,25 +55,27 @@ func TestPostgresStores_Live(t *testing.T) {
}

r := registry.NewPostgres(pool)
seedBucket := func(t *testing.T, name string) {
// seedBucket inserts a bucket row directly, bypassing Create, and returns
// the space it was given. space has no default — Create always supplies

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// the space it was given. space has no default — Create always supplies
// the space DID it generated. space has no default — Create always supplies

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this PR was already merged when the suggestion came in, it's applied in a follow-up PR: #89


Generated by Claude Code

// the DID Hilt returns — so the seed supplies one too.
seedBucket := func(t *testing.T, name string) did.DID {
t.Helper()
// space has no default (Create always supplies the DID Hilt
// returns); the seed uses '' — the pre-space sentinel Get maps
// to did.Undef.
if _, err := pool.Exec(ctx, `INSERT INTO ingot.buckets (name, space) VALUES ($1, '')`, name); err != nil {
space := testutil.RandomDID(t)
if _, err := pool.Exec(ctx, `INSERT INTO ingot.buckets (name, space) VALUES ($1, $2)`, name, space.String()); err != nil {
t.Fatalf("seed bucket %q: %v", name, err)
}
return space
}
digest := []byte{0x12, 0x20, 0xab, 0xcd} // binary, to exercise bytea round-trips

t.Run("bucket space defaults empty", func(t *testing.T) {
seedBucket(t, "b")
t.Run("bucket space round trips", func(t *testing.T) {
space := seedBucket(t, "b")
st, err := r.Get(ctx, "b")
if err != nil {
t.Fatalf("Get: %v", err)
}
if st.Space != did.Undef {
t.Fatalf("space = %q, want empty default", st.Space)
if st.Space != space {
t.Fatalf("space = %q, want %q", st.Space, space)
}
})

Expand All @@ -83,6 +85,7 @@ func TestPostgresStores_Live(t *testing.T) {
// (a bucket has one space). A second space therefore implies a second
// bucket — bucket "b2" below, not a re-keyed "b".
space := testutil.RandomDID(t)
space2 := testutil.RandomDID(t)
add := func(bucket, key string, sp did.DID) {
if err := r.AddBlobClaim(ctx, registry.BlobClaim{Digest: digest, Bucket: bucket, ObjectKey: key, VersionID: registry.NullVersionID, Space: sp}); err != nil {
t.Fatalf("AddBlobClaim: %v", err)
Expand All @@ -91,11 +94,11 @@ func TestPostgresStores_Live(t *testing.T) {
add("b", "k1", space)
add("b", "k2", space)
add("b", "k1", space) // ON CONFLICT DO NOTHING — does not inflate the count
add("b2", "k1", testutil.RandomDID(t))
add("b2", "k1", space2)
if n, _ := r.CountClaims(ctx, space, digest); n != 2 {
t.Fatalf("count space1 = %d, want 2", n)
}
if n, _ := r.CountClaims(ctx, testutil.RandomDID(t), digest); n != 1 {
if n, _ := r.CountClaims(ctx, space2, digest); n != 1 {
t.Fatalf("count space2 = %d, want 1", n)
}
if err := r.DeleteBlobClaim(ctx, digest, "b", "k1", registry.NullVersionID); err != nil {
Expand Down
Loading