From 826434a8597122847f643abe835d5c6e5dd74c4c Mon Sep 17 00:00:00 2001 From: RanXom Date: Tue, 14 Jul 2026 10:45:04 +0530 Subject: refactor(service): rename load to reload --- internal/api/api_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'internal/api/api_test.go') diff --git a/internal/api/api_test.go b/internal/api/api_test.go index c1980fd..0b1c68d 100644 --- a/internal/api/api_test.go +++ b/internal/api/api_test.go @@ -37,7 +37,7 @@ func (f fakeThumbnailGenerator) Generate( }, nil } -func (f fakeGalleryService) Load(ctx context.Context) error { +func (f fakeGalleryService) Reload(ctx context.Context) error { return nil } -- cgit v1.2.3 From ed87aebc0296379280fd65d618127b4eeb848a98 Mon Sep 17 00:00:00 2001 From: RanXom Date: Tue, 14 Jul 2026 11:37:22 +0530 Subject: feat(api): add manual gallery reload endpoint --- internal/api/api_test.go | 46 ++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 42 insertions(+), 4 deletions(-) (limited to 'internal/api/api_test.go') diff --git a/internal/api/api_test.go b/internal/api/api_test.go index 0b1c68d..dce42e4 100644 --- a/internal/api/api_test.go +++ b/internal/api/api_test.go @@ -17,6 +17,9 @@ import ( type fakeGalleryService struct { photos []gallery.Photo err error + + reloadCalls int + reloadErr error } type fakeThumbnailGenerator struct { @@ -37,8 +40,9 @@ func (f fakeThumbnailGenerator) Generate( }, nil } -func (f fakeGalleryService) Reload(ctx context.Context) error { - return nil +func (f *fakeGalleryService) Reload(ctx context.Context) error { + f.reloadCalls++ + return f.reloadErr } func (f fakeGalleryService) Gallery(ctx context.Context) ([]gallery.Photo, error) { @@ -62,7 +66,7 @@ func TestPhotos(t *testing.T) { srv := New(Config{ Address: ":0", - Gallery: fakeGalleryService{ + Gallery: &fakeGalleryService{ photos: []gallery.Photo{ { ID: "abc123", @@ -146,7 +150,7 @@ func TestThumbnail(t *testing.T) { srv := New(Config{ Address: ":0", - Gallery: fakeGalleryService{ + Gallery: &fakeGalleryService{ photos: []gallery.Photo{ { ID: "abc123", @@ -184,3 +188,37 @@ func TestThumbnail(t *testing.T) { ) } } + +func TestReload(t *testing.T) { + gallery := &fakeGalleryService{} + + srv := New(Config{ + Address: ":0", + Gallery: gallery, + }) + + req := httptest.NewRequest( + http.MethodPost, + "/api/reload", + nil, + ) + + rec := httptest.NewRecorder() + + srv.mux.ServeHTTP(rec, req) + + if rec.Code != http.StatusNoContent { + t.Fatalf( + "expected %d, got %d", + http.StatusNoContent, + rec.Code, + ) + } + + if gallery.reloadCalls != 1 { + t.Fatalf( + "expected Reload() to be called once, got %d", + gallery.reloadCalls, + ) + } +} -- cgit v1.2.3