aboutsummaryrefslogtreecommitdiff
path: root/internal/api/api_test.go
diff options
context:
space:
mode:
authorRanXom <saiyedshizain@gmail.com>2026-07-13 19:39:06 +0530
committerRanXom <saiyedshizain@gmail.com>2026-07-13 19:39:06 +0530
commit5f9a07afe0fd42cd9870c864eb30941343bf51e9 (patch)
treeaa6c1a124ab26b11345ae5f4f60bde72de394b2e /internal/api/api_test.go
parentb0857d4bf6f899426c5e1a115a60799332636afc (diff)
downloadgalleryd-5f9a07afe0fd42cd9870c864eb30941343bf51e9.tar.xz
galleryd-5f9a07afe0fd42cd9870c864eb30941343bf51e9.zip
test(api): add thumbnail endpoint tests
Diffstat (limited to 'internal/api/api_test.go')
-rw-r--r--internal/api/api_test.go62
1 files changed, 62 insertions, 0 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,
+ )
+ }
+}