Skip to content

Commit 2fb6627

Browse files
authored
test(registry): seed live buckets with a real space DID (#88)
Get parses the bucket's space column into a did.DID, so the '' sentinel the seed inserted now fails the parse and takes three subtests down with it. Give each seeded bucket a random DID and assert the round-trip instead of the empty default. The claim-count subtest also generated a fresh DID for its second space on every use, so the count query looked up a space nothing was written under; hold it in a variable and reuse it. Assisted-by: Claude:claude-opus-5 Signed-off-by: Miroslav Bajtoš <oss@bajtos.net>
1 parent 5dae11d commit 2fb6627

1 file changed

Lines changed: 14 additions & 11 deletions

File tree

registry/postgres_live_test.go

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -55,25 +55,27 @@ func TestPostgresStores_Live(t *testing.T) {
5555
}
5656

5757
r := registry.NewPostgres(pool)
58-
seedBucket := func(t *testing.T, name string) {
58+
// seedBucket inserts a bucket row directly, bypassing Create, and returns
59+
// the space it was given. space has no default — Create always supplies
60+
// the DID Hilt returns — so the seed supplies one too.
61+
seedBucket := func(t *testing.T, name string) did.DID {
5962
t.Helper()
60-
// space has no default (Create always supplies the DID Hilt
61-
// returns); the seed uses '' — the pre-space sentinel Get maps
62-
// to did.Undef.
63-
if _, err := pool.Exec(ctx, `INSERT INTO ingot.buckets (name, space) VALUES ($1, '')`, name); err != nil {
63+
space := testutil.RandomDID(t)
64+
if _, err := pool.Exec(ctx, `INSERT INTO ingot.buckets (name, space) VALUES ($1, $2)`, name, space.String()); err != nil {
6465
t.Fatalf("seed bucket %q: %v", name, err)
6566
}
67+
return space
6668
}
6769
digest := []byte{0x12, 0x20, 0xab, 0xcd} // binary, to exercise bytea round-trips
6870

69-
t.Run("bucket space defaults empty", func(t *testing.T) {
70-
seedBucket(t, "b")
71+
t.Run("bucket space round trips", func(t *testing.T) {
72+
space := seedBucket(t, "b")
7173
st, err := r.Get(ctx, "b")
7274
if err != nil {
7375
t.Fatalf("Get: %v", err)
7476
}
75-
if st.Space != did.Undef {
76-
t.Fatalf("space = %q, want empty default", st.Space)
77+
if st.Space != space {
78+
t.Fatalf("space = %q, want %q", st.Space, space)
7779
}
7880
})
7981

@@ -83,6 +85,7 @@ func TestPostgresStores_Live(t *testing.T) {
8385
// (a bucket has one space). A second space therefore implies a second
8486
// bucket — bucket "b2" below, not a re-keyed "b".
8587
space := testutil.RandomDID(t)
88+
space2 := testutil.RandomDID(t)
8689
add := func(bucket, key string, sp did.DID) {
8790
if err := r.AddBlobClaim(ctx, registry.BlobClaim{Digest: digest, Bucket: bucket, ObjectKey: key, VersionID: registry.NullVersionID, Space: sp}); err != nil {
8891
t.Fatalf("AddBlobClaim: %v", err)
@@ -91,11 +94,11 @@ func TestPostgresStores_Live(t *testing.T) {
9194
add("b", "k1", space)
9295
add("b", "k2", space)
9396
add("b", "k1", space) // ON CONFLICT DO NOTHING — does not inflate the count
94-
add("b2", "k1", testutil.RandomDID(t))
97+
add("b2", "k1", space2)
9598
if n, _ := r.CountClaims(ctx, space, digest); n != 2 {
9699
t.Fatalf("count space1 = %d, want 2", n)
97100
}
98-
if n, _ := r.CountClaims(ctx, testutil.RandomDID(t), digest); n != 1 {
101+
if n, _ := r.CountClaims(ctx, space2, digest); n != 1 {
99102
t.Fatalf("count space2 = %d, want 1", n)
100103
}
101104
if err := r.DeleteBlobClaim(ctx, digest, "b", "k1", registry.NullVersionID); err != nil {

0 commit comments

Comments
 (0)