aboutsummaryrefslogtreecommitdiff
path: root/internal/api/api_test.go
diff options
context:
space:
mode:
authorSaiyed Shizain <saiyedshizain@gmail.com>2026-07-17 11:10:53 +0530
committerGitHub <noreply@github.com>2026-07-17 11:10:53 +0530
commit6afb80ab754da137939dd523ee419818026f9fb5 (patch)
treef9f94ec69ac87abe8060cefca8708572bc13bdd6 /internal/api/api_test.go
parentbcfb199ac8e5399e1a92cfbbc28af3674f80959d (diff)
parent5ae787be3d1d9de3355f8b5662fea857204e693c (diff)
downloadgalleryd-6afb80ab754da137939dd523ee419818026f9fb5.tar.xz
galleryd-6afb80ab754da137939dd523ee419818026f9fb5.zip
Merge pull request #11 from RanXom/feat/live-gallery
Feat/live-gallery: live gallery with automatic filesystem reloads
Diffstat (limited to 'internal/api/api_test.go')
-rw-r--r--internal/api/api_test.go46
1 files changed, 42 insertions, 4 deletions
diff --git a/internal/api/api_test.go b/internal/api/api_test.go
index c1980fd..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) Load(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,
+ )
+ }
+}