summaryrefslogtreecommitdiff
path: root/internal
diff options
context:
space:
mode:
Diffstat (limited to 'internal')
-rw-r--r--internal/api/handlers.go3
-rw-r--r--internal/api/handlers_more_test.go6
-rw-r--r--internal/repository/mock.go34
-rw-r--r--internal/service/gc.go4
-rw-r--r--internal/service/mock_test.go40
-rw-r--r--internal/service/scan.go4
-rw-r--r--internal/service/tag.go3
7 files changed, 52 insertions, 42 deletions
diff --git a/internal/api/handlers.go b/internal/api/handlers.go
index 8da7a9f..2bcf21f 100644
--- a/internal/api/handlers.go
+++ b/internal/api/handlers.go
@@ -2,6 +2,7 @@ package api
import (
"encoding/json"
+ "errors"
"fmt"
"io"
"log/slog"
@@ -28,7 +29,7 @@ func writeJSON(w http.ResponseWriter, status int, data interface{}) {
func readJSON(r *http.Request, dst interface{}) error {
if r.Body == nil {
- return fmt.Errorf("missing body")
+ return errors.New("missing body")
}
defer r.Body.Close()
return json.NewDecoder(r.Body).Decode(dst)
diff --git a/internal/api/handlers_more_test.go b/internal/api/handlers_more_test.go
index 379cc4c..2675483 100644
--- a/internal/api/handlers_more_test.go
+++ b/internal/api/handlers_more_test.go
@@ -1005,7 +1005,7 @@ func TestServer_SharePage(t *testing.T) {
ms := &service.MockMediaService{
GetSharedMediaFunc: func(ctx context.Context, token string) (*service.GetSharedMediaResult, error) {
return &service.GetSharedMediaResult{
- Media: &service.SharedMediaView{ID: 1, FileName: "share.mp4", Type: model.MediaTypeVideo, Duration: 120},
+ Media: &service.SharedMediaView{ID: 1, FileName: "share.mp4", Type: model.MediaTypeVideo, Duration: 120},
StreamURL: "/s/abc/stream",
ThumbURL: "/s/abc/thumbnail",
}, nil
@@ -1032,7 +1032,7 @@ func TestServer_SharePage(t *testing.T) {
ms := &service.MockMediaService{
GetSharedMediaFunc: func(ctx context.Context, token string) (*service.GetSharedMediaResult, error) {
return &service.GetSharedMediaResult{
- Media: &service.SharedMediaView{ID: 1, FileName: "share.mp4", Type: model.MediaTypeVideo, Duration: 120},
+ Media: &service.SharedMediaView{ID: 1, FileName: "share.mp4", Type: model.MediaTypeVideo, Duration: 120},
StreamURL: "/s/abc/stream",
ThumbURL: "/s/abc/thumbnail",
}, nil
@@ -1056,7 +1056,7 @@ func TestServer_SharePage(t *testing.T) {
ms := &service.MockMediaService{
GetSharedMediaFunc: func(ctx context.Context, token string) (*service.GetSharedMediaResult, error) {
return &service.GetSharedMediaResult{
- Media: &service.SharedMediaView{ID: 1, FileName: "share.mp4", Type: model.MediaTypeVideo, Duration: 120},
+ Media: &service.SharedMediaView{ID: 1, FileName: "share.mp4", Type: model.MediaTypeVideo, Duration: 120},
StreamURL: "/s/abc/stream",
ThumbURL: "/s/abc/thumbnail",
}, nil
diff --git a/internal/repository/mock.go b/internal/repository/mock.go
index 533810b..abab4c8 100644
--- a/internal/repository/mock.go
+++ b/internal/repository/mock.go
@@ -10,23 +10,23 @@ import (
// compile-time checks.
var (
- _ Store = (*MockStore)(nil)
- _ MediaServiceStore = (*MockStore)(nil)
- _ AdminServiceStore = (*MockStore)(nil)
- _ AuthServiceStore = (*MockStore)(nil)
- _ ProgressServiceStore = (*MockStore)(nil)
- _ GCStore = (*MockStore)(nil)
- _ ScannerStore = (*MockStore)(nil)
- _ AccessHelperStore = (*MockStore)(nil)
- _ BrowseServiceStore = (*MockStore)(nil)
- _ WriteServiceStore = (*MockStore)(nil)
- _ ShareServiceStore = (*MockStore)(nil)
- _ TagServiceStore = (*MockStore)(nil)
- _ FavoriteServiceStore = (*MockStore)(nil)
- _ NoteServiceStore = (*MockStore)(nil)
- _ TrashServiceStore = (*MockStore)(nil)
- _ UserAdminServiceStore = (*MockStore)(nil)
- _ PermissionAdminServiceStore = (*MockStore)(nil)
+ _ Store = (*MockStore)(nil)
+ _ MediaServiceStore = (*MockStore)(nil)
+ _ AdminServiceStore = (*MockStore)(nil)
+ _ AuthServiceStore = (*MockStore)(nil)
+ _ ProgressServiceStore = (*MockStore)(nil)
+ _ GCStore = (*MockStore)(nil)
+ _ ScannerStore = (*MockStore)(nil)
+ _ AccessHelperStore = (*MockStore)(nil)
+ _ BrowseServiceStore = (*MockStore)(nil)
+ _ WriteServiceStore = (*MockStore)(nil)
+ _ ShareServiceStore = (*MockStore)(nil)
+ _ TagServiceStore = (*MockStore)(nil)
+ _ FavoriteServiceStore = (*MockStore)(nil)
+ _ NoteServiceStore = (*MockStore)(nil)
+ _ TrashServiceStore = (*MockStore)(nil)
+ _ UserAdminServiceStore = (*MockStore)(nil)
+ _ PermissionAdminServiceStore = (*MockStore)(nil)
)
// NewMockStore returns a MockStore with all no-op defaults.
diff --git a/internal/service/gc.go b/internal/service/gc.go
index e4290d3..8ff3204 100644
--- a/internal/service/gc.go
+++ b/internal/service/gc.go
@@ -2,7 +2,7 @@ package service
import (
"context"
- "fmt"
+ "errors"
"log/slog"
"os"
"path/filepath"
@@ -149,7 +149,7 @@ func (w *GCWorker) notifyRunDone() {
// RunOnce performs a single GC run synchronously. Useful for tests.
func (w *GCWorker) RunOnce() error {
if w.interval == 0 {
- return fmt.Errorf("worker not started")
+ return errors.New("worker not started")
}
ctx := w.ctx
if ctx == nil {
diff --git a/internal/service/mock_test.go b/internal/service/mock_test.go
index bb4801c..bb2525c 100644
--- a/internal/service/mock_test.go
+++ b/internal/service/mock_test.go
@@ -56,9 +56,11 @@ func TestMockMediaService_Defaults(t *testing.T) {
func TestMockMediaService_WithFuncs(t *testing.T) {
ctx := context.Background()
m := &MockMediaService{
- ListSetsFunc: func(ctx context.Context, userID int64) ([]model.Set, error) { return nil, nil },
- GetMediaDetailFunc: func(ctx context.Context, mediaID, userID int64) (*MediaDetail, error) { return nil, nil },
- ListMediaFunc: func(ctx context.Context, userID int64, filter MediaQueryFilter) ([]model.Media, error) { return nil, nil },
+ ListSetsFunc: func(ctx context.Context, userID int64) ([]model.Set, error) { return nil, nil },
+ GetMediaDetailFunc: func(ctx context.Context, mediaID, userID int64) (*MediaDetail, error) { return nil, nil },
+ ListMediaFunc: func(ctx context.Context, userID int64, filter MediaQueryFilter) ([]model.Media, error) {
+ return nil, nil
+ },
StreamMediaFunc: func(ctx context.Context, mediaID, userID int64) (*FileResult, error) { return nil, nil },
DownloadMediaFunc: func(ctx context.Context, mediaID, userID int64) (*FileResult, error) { return nil, nil },
GetThumbnailFunc: func(ctx context.Context, mediaID, userID int64) (*FileResult, error) { return nil, nil },
@@ -69,15 +71,19 @@ func TestMockMediaService_WithFuncs(t *testing.T) {
RemoveTagFunc: func(ctx context.Context, mediaID, userID int64, tagName string) error { return nil },
SoftDeleteMediaFunc: func(ctx context.Context, mediaID, userID int64) error { return nil },
RestoreMediaFunc: func(ctx context.Context, mediaID, userID int64) error { return nil },
- UploadMediaFunc: func(ctx context.Context, setID, userID int64, filename string, data io.Reader, size int64) (*model.Media, error) { return nil, nil },
- CreateShareFunc: func(ctx context.Context, userID, mediaID int64, expiresAt time.Time) (*model.Share, error) { return nil, nil },
- ListSharesFunc: func(ctx context.Context, mediaID, userID int64) ([]model.Share, error) { return nil, nil },
- RevokeShareFunc: func(ctx context.Context, token string, userID int64) error { return nil },
- ValidateShareTokenFunc: func(ctx context.Context, token string) (*model.Share, error) { return nil, nil },
- StreamSharedMediaFunc: func(ctx context.Context, token string) (*FileResult, error) { return nil, nil },
- GetNoteFunc: func(ctx context.Context, mediaID, userID int64) (*model.Note, error) { return nil, nil },
- UpsertNoteFunc: func(ctx context.Context, note *model.Note) error { return nil },
- DeleteNoteFunc: func(ctx context.Context, mediaID, userID int64) error { return nil },
+ UploadMediaFunc: func(ctx context.Context, setID, userID int64, filename string, data io.Reader, size int64) (*model.Media, error) {
+ return nil, nil
+ },
+ CreateShareFunc: func(ctx context.Context, userID, mediaID int64, expiresAt time.Time) (*model.Share, error) {
+ return nil, nil
+ },
+ ListSharesFunc: func(ctx context.Context, mediaID, userID int64) ([]model.Share, error) { return nil, nil },
+ RevokeShareFunc: func(ctx context.Context, token string, userID int64) error { return nil },
+ ValidateShareTokenFunc: func(ctx context.Context, token string) (*model.Share, error) { return nil, nil },
+ StreamSharedMediaFunc: func(ctx context.Context, token string) (*FileResult, error) { return nil, nil },
+ GetNoteFunc: func(ctx context.Context, mediaID, userID int64) (*model.Note, error) { return nil, nil },
+ UpsertNoteFunc: func(ctx context.Context, note *model.Note) error { return nil },
+ DeleteNoteFunc: func(ctx context.Context, mediaID, userID int64) error { return nil },
}
m.ListSets(ctx, 1)
@@ -124,10 +130,12 @@ func TestMockAdminService_Defaults(t *testing.T) {
func TestMockAdminService_WithFuncs(t *testing.T) {
ctx := context.Background()
m := &MockAdminService{
- ListTrashFunc: func(ctx context.Context) ([]model.Media, error) { return nil, nil },
- TriggerRescanFunc: func(ctx context.Context) error { return nil },
- ListUsersFunc: func(ctx context.Context) ([]model.User, error) { return nil, nil },
- CreateUserFunc: func(ctx context.Context, username, password string, isAdmin bool) (*model.User, error) { return nil, nil },
+ ListTrashFunc: func(ctx context.Context) ([]model.Media, error) { return nil, nil },
+ TriggerRescanFunc: func(ctx context.Context) error { return nil },
+ ListUsersFunc: func(ctx context.Context) ([]model.User, error) { return nil, nil },
+ CreateUserFunc: func(ctx context.Context, username, password string, isAdmin bool) (*model.User, error) {
+ return nil, nil
+ },
DeleteUserFunc: func(ctx context.Context, id int64) error { return nil },
ListPermissionsFunc: func(ctx context.Context) (*PermissionsMatrix, error) { return nil, nil },
GrantPermissionFunc: func(ctx context.Context, setID, userID int64, role model.Role) error { return nil },
diff --git a/internal/service/scan.go b/internal/service/scan.go
index ca4aca8..d019616 100644
--- a/internal/service/scan.go
+++ b/internal/service/scan.go
@@ -2,7 +2,7 @@ package service
import (
"context"
- "fmt"
+ "errors"
"log/slog"
"sync"
"time"
@@ -40,7 +40,7 @@ func NewScanService(appCtx context.Context, sc scanner.Scanner, mediaRoot string
func (s *scanService) TriggerRescan(ctx context.Context) error {
if s.scanner == nil {
- return fmt.Errorf("scanner not configured")
+ return errors.New("scanner not configured")
}
s.mu.Lock()
diff --git a/internal/service/tag.go b/internal/service/tag.go
index 80e358c..4112489 100644
--- a/internal/service/tag.go
+++ b/internal/service/tag.go
@@ -2,6 +2,7 @@ package service
import (
"context"
+ "errors"
"fmt"
"codeberg.org/snonux/player/internal/model"
@@ -49,7 +50,7 @@ func (s *tagService) RemoveTag(ctx context.Context, mediaID, userID int64, tagNa
return fmt.Errorf("get tag: %w", err)
}
if tag == nil {
- return fmt.Errorf("tag not found")
+ return errors.New("tag not found")
}
return s.store.RemoveTag(ctx, mediaID, tag.ID)
}