detached 1660658

test(registry): assert SpaceReclaimed in blob GC test

fakeBlobStorage.DeleteBlob previously always returned 0, so the
service accumulation logic was never exercised. Add blobSizes map
to the fake and verify the GC test aggregates the correct total.
commit
16606581f4dba44b75ea14434784c61255a3482e
author
brice · · 2026-03-27 19:03 UTC
parent
52cf0df
signature
GPG VerifiedCD88F9E564E0102646FB6077A1A07C7C7C3E349D · arch-gpg Verified for the committer email
1 file · +11 -2
M internal/usecase/images/service_test.go +11 -2
@@ -318,13 +318,17 @@ func TestService_PruneRegistry_GarbageCollectsUnreferencedBlobs(t *testing.T) {
318318 manifestStorage.modTimes[manifestRefKey("gordon/api", "latest")] = time.Date(2026, 2, 8, 12, 0, 0, 0, time.UTC)
319319 manifestStorage.manifests[manifestRefKey("gordon/api", "latest")] = mustManifestJSON(t, "sha256:cfg-live", "sha256:layer-live")
320320
321- blobStorage := &fakeBlobStorage{blobs: []string{"sha256:cfg-live", "sha256:layer-live", "sha256:orphan"}}
321+ blobStorage := &fakeBlobStorage{
322+ blobs: []string{"sha256:cfg-live", "sha256:layer-live", "sha256:orphan"},
323+ blobSizes: map[string]int64{"sha256:orphan": 4096},
324+ }
322325 svc := NewService(&fakeRuntime{}, manifestStorage, blobStorage, zerowrap.Default())
323326
324327 report, err := svc.PruneRegistry(context.Background(), 1)
325328
326329 require.NoError(t, err)
327330 assert.Equal(t, 1, report.Registry.BlobsRemoved)
331+ assert.Equal(t, int64(4096), report.Registry.SpaceReclaimed)
328332 assert.Equal(t, []string{"sha256:orphan"}, blobStorage.deletedBlobs)
329333 }
330334
@@ -663,6 +667,7 @@ type fakeBlobStorage struct {
663667 out.BlobStorage
664668
665669 blobs []string
670+ blobSizes map[string]int64
666671 deletedBlobs []string
667672 }
668673
@@ -791,6 +796,10 @@ func (f *fakeBlobStorage) ListBlobs() ([]string, error) {
791796
792797 func (f *fakeBlobStorage) DeleteBlob(digest string) (int64, error) {
793798 f.deletedBlobs = append(f.deletedBlobs, digest)
799+ var size int64
800+ if f.blobSizes != nil {
801+ size = f.blobSizes[digest]
802+ }
794803 for i, existing := range f.blobs {
795804 if existing != digest {
796805 continue
@@ -798,7 +807,7 @@ func (f *fakeBlobStorage) DeleteBlob(digest string) (int64, error) {
798807 f.blobs = append(f.blobs[:i], f.blobs[i+1:]...)
799808 break
800809 }
801- return 0, nil
810+ return size, nil
802811 }
803812
804813 func (f *fakeBlobStorage) CleanupStaleUploads(_ time.Duration) (int, int64, error) {
@@ -318,13 +318,17 @@ func TestService_PruneRegistry_GarbageCollectsUnreferencedBlobs(t *testing.T) {
318 manifestStorage.modTimes[manifestRefKey("gordon/api", "latest")] = time.Date(2026, 2, 8, 12, 0, 0, 0, time.UTC)318 manifestStorage.modTimes[manifestRefKey("gordon/api", "latest")] = time.Date(2026, 2, 8, 12, 0, 0, 0, time.UTC)
319 manifestStorage.manifests[manifestRefKey("gordon/api", "latest")] = mustManifestJSON(t, "sha256:cfg-live", "sha256:layer-live")319 manifestStorage.manifests[manifestRefKey("gordon/api", "latest")] = mustManifestJSON(t, "sha256:cfg-live", "sha256:layer-live")
320 320
321- blobStorage := &fakeBlobStorage{blobs: []string{"sha256:cfg-live", "sha256:layer-live", "sha256:orphan"}}321+ blobStorage := &fakeBlobStorage{
322+ blobs: []string{"sha256:cfg-live", "sha256:layer-live", "sha256:orphan"},
323+ blobSizes: map[string]int64{"sha256:orphan": 4096},
324+ }
322 svc := NewService(&fakeRuntime{}, manifestStorage, blobStorage, zerowrap.Default())325 svc := NewService(&fakeRuntime{}, manifestStorage, blobStorage, zerowrap.Default())
323 326
324 report, err := svc.PruneRegistry(context.Background(), 1)327 report, err := svc.PruneRegistry(context.Background(), 1)
325 328
326 require.NoError(t, err)329 require.NoError(t, err)
327 assert.Equal(t, 1, report.Registry.BlobsRemoved)330 assert.Equal(t, 1, report.Registry.BlobsRemoved)
331+ assert.Equal(t, int64(4096), report.Registry.SpaceReclaimed)
328 assert.Equal(t, []string{"sha256:orphan"}, blobStorage.deletedBlobs)332 assert.Equal(t, []string{"sha256:orphan"}, blobStorage.deletedBlobs)
329 }333 }
330 334
@@ -663,6 +667,7 @@ type fakeBlobStorage struct {
663 out.BlobStorage667 out.BlobStorage
664 668
665 blobs []string669 blobs []string
670+ blobSizes map[string]int64
666 deletedBlobs []string671 deletedBlobs []string
667 }672 }
668 673
@@ -791,6 +796,10 @@ func (f *fakeBlobStorage) ListBlobs() ([]string, error) {
791 796
792 func (f *fakeBlobStorage) DeleteBlob(digest string) (int64, error) {797 func (f *fakeBlobStorage) DeleteBlob(digest string) (int64, error) {
793 f.deletedBlobs = append(f.deletedBlobs, digest)798 f.deletedBlobs = append(f.deletedBlobs, digest)
799+ var size int64
800+ if f.blobSizes != nil {
801+ size = f.blobSizes[digest]
802+ }
794 for i, existing := range f.blobs {803 for i, existing := range f.blobs {
795 if existing != digest {804 if existing != digest {
796 continue805 continue
@@ -798,7 +807,7 @@ func (f *fakeBlobStorage) DeleteBlob(digest string) (int64, error) {
798 f.blobs = append(f.blobs[:i], f.blobs[i+1:]...)807 f.blobs = append(f.blobs[:i], f.blobs[i+1:]...)
799 break808 break
800 }809 }
801- return 0, nil810+ return size, nil
802 }811 }
803 812
804 func (f *fakeBlobStorage) CleanupStaleUploads(_ time.Duration) (int, int64, error) {813 func (f *fakeBlobStorage) CleanupStaleUploads(_ time.Duration) (int, int64, error) {

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 7

Tags 106

↑↓ moveenter openesc close