diff options
Diffstat (limited to 'internal/api')
| -rw-r--r-- | internal/api/api_test.go | 62 | ||||
| -rw-r--r-- | internal/api/config.go | 3 |
2 files changed, 63 insertions, 2 deletions
diff --git a/internal/api/api_test.go b/internal/api/api_test.go index c54514d..c1980fd 100644 --- a/internal/api/api_test.go +++ b/internal/api/api_test.go @@ -11,6 +11,7 @@ import ( "github.com/RanXom/galleryd/internal/gallery" "github.com/RanXom/galleryd/internal/metadata" "github.com/RanXom/galleryd/internal/service" + "github.com/RanXom/galleryd/internal/thumbnail" ) type fakeGalleryService struct { @@ -18,6 +19,24 @@ type fakeGalleryService struct { err error } +type fakeThumbnailGenerator struct { + path string + err error +} + +func (f fakeThumbnailGenerator) Generate( + ctx context.Context, + photo gallery.Photo, +) (thumbnail.Thumbnail, error) { + if f.err != nil { + return thumbnail.Thumbnail{}, f.err + } + + return thumbnail.Thumbnail{ + Path: f.path, + }, nil +} + func (f fakeGalleryService) Load(ctx context.Context) error { return nil } @@ -122,3 +141,46 @@ func TestPhotos(t *testing.T) { ) } } + +func TestThumbnail(t *testing.T) { + srv := New(Config{ + Address: ":0", + + Gallery: fakeGalleryService{ + photos: []gallery.Photo{ + { + ID: "abc123", + }, + }, + }, + + Thumbnails: fakeThumbnailGenerator{ + path: "../scanner/testdata/gallery/vac/image.webp", + }, + }) + + req := httptest.NewRequest( + http.MethodGet, + "/thumb/abc123", + nil, + ) + + rec := httptest.NewRecorder() + + srv.mux.ServeHTTP(rec, req) + + if rec.Code != http.StatusOK { + t.Fatalf( + "expected %d, got %d", + http.StatusOK, + rec.Code, + ) + } + + if got := rec.Header().Get("Content-Type"); got != "image/webp" { + t.Fatalf( + "expected image/webp, got %q", + got, + ) + } +} diff --git a/internal/api/config.go b/internal/api/config.go index a9a72ae..04057a4 100644 --- a/internal/api/config.go +++ b/internal/api/config.go @@ -2,7 +2,6 @@ package api import ( "github.com/RanXom/galleryd/internal/service" - "github.com/RanXom/galleryd/internal/thumbnail" ) // Config configures the HTTP server @@ -10,5 +9,5 @@ type Config struct { Address string Gallery service.GalleryService - Thumbnails *thumbnail.Generator + Thumbnails ThumbnailGenerator } |