mirror of
https://github.com/navidrome/navidrome.git
synced 2025-04-03 20:47:35 +03:00
Move mock datastore to tests package
This commit is contained in:
parent
313a088f86
commit
d0bf37a8a9
19 changed files with 41 additions and 79 deletions
|
@ -49,7 +49,7 @@ func CreateSubsonicAPIRouter() *subsonic.Router {
|
|||
transcodingCache := core.NewTranscodingCache()
|
||||
mediaStreamer := core.NewMediaStreamer(dataStore, transcoderTranscoder, transcodingCache)
|
||||
archiver := core.NewArchiver(dataStore)
|
||||
players := engine.NewPlayers(dataStore)
|
||||
players := core.NewPlayers(dataStore)
|
||||
client := core.LastFMNewClient()
|
||||
spotifyClient := core.SpotifyNewClient()
|
||||
externalInfo := core.NewExternalInfo(dataStore, client, spotifyClient)
|
||||
|
|
|
@ -10,7 +10,7 @@ import (
|
|||
"github.com/deluan/navidrome/conf"
|
||||
"github.com/deluan/navidrome/log"
|
||||
"github.com/deluan/navidrome/model"
|
||||
"github.com/deluan/navidrome/persistence"
|
||||
"github.com/deluan/navidrome/tests"
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/gomega"
|
||||
)
|
||||
|
@ -21,13 +21,13 @@ var _ = Describe("Artwork", func() {
|
|||
ctx := log.NewContext(context.TODO())
|
||||
|
||||
BeforeEach(func() {
|
||||
ds = &persistence.MockDataStore{MockedTranscoding: &mockTranscodingRepository{}}
|
||||
ds.Album(ctx).(*persistence.MockAlbum).SetData(model.Albums{
|
||||
ds = &tests.MockDataStore{MockedTranscoding: &tests.MockTranscodingRepository{}}
|
||||
ds.Album(ctx).(*tests.MockAlbum).SetData(model.Albums{
|
||||
{ID: "222", CoverArtId: "123", CoverArtPath: "tests/fixtures/test.mp3"},
|
||||
{ID: "333", CoverArtId: ""},
|
||||
{ID: "444", CoverArtId: "444", CoverArtPath: "tests/fixtures/cover.jpg"},
|
||||
})
|
||||
ds.MediaFile(ctx).(*persistence.MockMediaFile).SetData(model.MediaFiles{
|
||||
ds.MediaFile(ctx).(*tests.MockMediaFile).SetData(model.MediaFiles{
|
||||
{ID: "123", AlbumID: "222", Path: "tests/fixtures/test.mp3", HasCoverArt: true},
|
||||
{ID: "456", AlbumID: "222", Path: "tests/fixtures/test.ogg", HasCoverArt: false},
|
||||
})
|
||||
|
@ -132,14 +132,14 @@ var _ = Describe("Artwork", func() {
|
|||
|
||||
Context("Errors", func() {
|
||||
It("returns err if gets error from album table", func() {
|
||||
ds.Album(ctx).(*persistence.MockAlbum).SetError(true)
|
||||
ds.Album(ctx).(*tests.MockAlbum).SetError(true)
|
||||
buf := new(bytes.Buffer)
|
||||
|
||||
Expect(artwork.Get(ctx, "al-222", 0, buf)).To(MatchError("Error!"))
|
||||
})
|
||||
|
||||
It("returns err if gets error from media_file table", func() {
|
||||
ds.MediaFile(ctx).(*persistence.MockMediaFile).SetError(true)
|
||||
ds.MediaFile(ctx).(*tests.MockMediaFile).SetError(true)
|
||||
buf := new(bytes.Buffer)
|
||||
|
||||
Expect(artwork.Get(ctx, "123", 0, buf)).To(MatchError("Error!"))
|
||||
|
|
|
@ -11,7 +11,7 @@ import (
|
|||
"github.com/deluan/navidrome/log"
|
||||
"github.com/deluan/navidrome/model"
|
||||
"github.com/deluan/navidrome/model/request"
|
||||
"github.com/deluan/navidrome/persistence"
|
||||
"github.com/deluan/navidrome/tests"
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/gomega"
|
||||
)
|
||||
|
@ -25,8 +25,8 @@ var _ = Describe("MediaStreamer", func() {
|
|||
BeforeEach(func() {
|
||||
conf.Server.DataFolder, _ = ioutil.TempDir("", "file_caches")
|
||||
conf.Server.TranscodingCacheSize = "100MB"
|
||||
ds = &persistence.MockDataStore{MockedTranscoding: &mockTranscodingRepository{}}
|
||||
ds.MediaFile(ctx).(*persistence.MockMediaFile).SetData(model.MediaFiles{
|
||||
ds = &tests.MockDataStore{MockedTranscoding: &tests.MockTranscodingRepository{}}
|
||||
ds.MediaFile(ctx).(*tests.MockMediaFile).SetData(model.MediaFiles{
|
||||
{ID: "123", Path: "tests/fixtures/test.mp3", Suffix: "mp3", BitRate: 128, Duration: 257.0},
|
||||
})
|
||||
testCache := NewTranscodingCache()
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package engine
|
||||
package core
|
||||
|
||||
import (
|
||||
"context"
|
|
@ -1,4 +1,4 @@
|
|||
package engine
|
||||
package core
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
@ -7,7 +7,7 @@ import (
|
|||
"github.com/deluan/navidrome/log"
|
||||
"github.com/deluan/navidrome/model"
|
||||
"github.com/deluan/navidrome/model/request"
|
||||
"github.com/deluan/navidrome/persistence"
|
||||
"github.com/deluan/navidrome/tests"
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/gomega"
|
||||
)
|
||||
|
@ -22,7 +22,7 @@ var _ = Describe("Players", func() {
|
|||
|
||||
BeforeEach(func() {
|
||||
repo = &mockPlayerRepository{}
|
||||
ds := &persistence.MockDataStore{MockedPlayer: repo, MockedTranscoding: &mockTranscodingRepository{}}
|
||||
ds := &tests.MockDataStore{MockedPlayer: repo, MockedTranscoding: &tests.MockTranscodingRepository{}}
|
||||
players = NewPlayers(ds)
|
||||
beforeRegister = time.Now()
|
||||
})
|
|
@ -4,7 +4,7 @@ import (
|
|||
"context"
|
||||
|
||||
"github.com/deluan/navidrome/model"
|
||||
"github.com/deluan/navidrome/persistence"
|
||||
"github.com/deluan/navidrome/tests"
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/gomega"
|
||||
)
|
||||
|
@ -15,7 +15,7 @@ var _ = Describe("playlistSync", func() {
|
|||
var ps *playlistSync
|
||||
ctx := context.TODO()
|
||||
BeforeEach(func() {
|
||||
ds = &persistence.MockDataStore{
|
||||
ds = &tests.MockDataStore{
|
||||
MockedMediaFile: &mockedMediaFile{},
|
||||
}
|
||||
ps = newPlaylistSync(ds)
|
||||
|
|
|
@ -11,7 +11,7 @@ import (
|
|||
"github.com/deluan/navidrome/conf"
|
||||
"github.com/deluan/navidrome/consts"
|
||||
"github.com/deluan/navidrome/model"
|
||||
"github.com/deluan/navidrome/persistence"
|
||||
"github.com/deluan/navidrome/tests"
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/gomega"
|
||||
)
|
||||
|
@ -22,7 +22,7 @@ var _ = Describe("serveIndex", func() {
|
|||
fs := http.Dir("tests/fixtures")
|
||||
|
||||
BeforeEach(func() {
|
||||
ds = &persistence.MockDataStore{MockedUser: mockUser}
|
||||
ds = &tests.MockDataStore{MockedUser: mockUser}
|
||||
conf.Server.UILoginBackgroundURL = ""
|
||||
})
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ import (
|
|||
|
||||
"github.com/deluan/navidrome/log"
|
||||
"github.com/deluan/navidrome/model"
|
||||
"github.com/deluan/navidrome/persistence"
|
||||
"github.com/deluan/navidrome/tests"
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/gomega"
|
||||
)
|
||||
|
@ -14,13 +14,13 @@ import (
|
|||
var _ = Describe("AlbumListController", func() {
|
||||
var controller *AlbumListController
|
||||
var ds model.DataStore
|
||||
var mockRepo *persistence.MockAlbum
|
||||
var mockRepo *tests.MockAlbum
|
||||
var w *httptest.ResponseRecorder
|
||||
ctx := log.NewContext(context.TODO())
|
||||
|
||||
BeforeEach(func() {
|
||||
ds = &persistence.MockDataStore{}
|
||||
mockRepo = ds.Album(ctx).(*persistence.MockAlbum)
|
||||
ds = &tests.MockDataStore{}
|
||||
mockRepo = ds.Album(ctx).(*tests.MockAlbum)
|
||||
controller = NewAlbumListController(ds, nil)
|
||||
w = httptest.NewRecorder()
|
||||
})
|
||||
|
|
|
@ -27,7 +27,7 @@ type Router struct {
|
|||
Playlists engine.Playlists
|
||||
Streamer core.MediaStreamer
|
||||
Archiver core.Archiver
|
||||
Players engine.Players
|
||||
Players core.Players
|
||||
ExternalInfo core.ExternalInfo
|
||||
DataStore model.DataStore
|
||||
|
||||
|
@ -36,7 +36,7 @@ type Router struct {
|
|||
|
||||
func New(artwork core.Artwork,
|
||||
playlists engine.Playlists, streamer core.MediaStreamer,
|
||||
archiver core.Archiver, players engine.Players, externalInfo core.ExternalInfo, ds model.DataStore) *Router {
|
||||
archiver core.Archiver, players core.Players, externalInfo core.ExternalInfo, ds model.DataStore) *Router {
|
||||
r := &Router{Artwork: artwork, Playlists: playlists,
|
||||
Streamer: streamer, Archiver: archiver, Players: players, ExternalInfo: externalInfo, DataStore: ds}
|
||||
r.mux = r.routes()
|
||||
|
|
|
@ -1,17 +0,0 @@
|
|||
package engine
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/deluan/navidrome/log"
|
||||
"github.com/deluan/navidrome/tests"
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/gomega"
|
||||
)
|
||||
|
||||
func TestEngine(t *testing.T) {
|
||||
tests.Init(t, false)
|
||||
log.SetLevel(log.LevelCritical)
|
||||
RegisterFailHandler(Fail)
|
||||
RunSpecs(t, "Engine Suite")
|
||||
}
|
|
@ -1,22 +0,0 @@
|
|||
package engine
|
||||
|
||||
import "github.com/deluan/navidrome/model"
|
||||
|
||||
type mockTranscodingRepository struct {
|
||||
model.TranscodingRepository
|
||||
}
|
||||
|
||||
func (m *mockTranscodingRepository) Get(id string) (*model.Transcoding, error) {
|
||||
return &model.Transcoding{ID: id, TargetFormat: "mp3", DefaultBitRate: 160}, nil
|
||||
}
|
||||
|
||||
func (m *mockTranscodingRepository) FindByFormat(format string) (*model.Transcoding, error) {
|
||||
switch format {
|
||||
case "mp3":
|
||||
return &model.Transcoding{ID: "mp31", TargetFormat: "mp3", DefaultBitRate: 160}, nil
|
||||
case "oga":
|
||||
return &model.Transcoding{ID: "oga1", TargetFormat: "oga", DefaultBitRate: 128}, nil
|
||||
default:
|
||||
return nil, model.ErrNotFound
|
||||
}
|
||||
}
|
|
@ -1,10 +1,11 @@
|
|||
package engine
|
||||
|
||||
import (
|
||||
"github.com/deluan/navidrome/core"
|
||||
"github.com/google/wire"
|
||||
)
|
||||
|
||||
var Set = wire.NewSet(
|
||||
NewPlaylists,
|
||||
NewPlayers,
|
||||
core.NewPlayers,
|
||||
)
|
||||
|
|
|
@ -10,11 +10,11 @@ import (
|
|||
"net/url"
|
||||
"strings"
|
||||
|
||||
"github.com/deluan/navidrome/core"
|
||||
"github.com/deluan/navidrome/core/auth"
|
||||
"github.com/deluan/navidrome/log"
|
||||
"github.com/deluan/navidrome/model"
|
||||
"github.com/deluan/navidrome/model/request"
|
||||
"github.com/deluan/navidrome/server/subsonic/engine"
|
||||
"github.com/deluan/navidrome/server/subsonic/responses"
|
||||
"github.com/deluan/navidrome/utils"
|
||||
)
|
||||
|
@ -139,7 +139,7 @@ func validateUser(ctx context.Context, ds model.DataStore, username, pass, token
|
|||
return user, nil
|
||||
}
|
||||
|
||||
func getPlayer(players engine.Players) func(next http.Handler) http.Handler {
|
||||
func getPlayer(players core.Players) func(next http.Handler) http.Handler {
|
||||
return func(next http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
ctx := r.Context()
|
||||
|
|
|
@ -7,12 +7,12 @@ import (
|
|||
"net/http/httptest"
|
||||
"strings"
|
||||
|
||||
"github.com/deluan/navidrome/core"
|
||||
"github.com/deluan/navidrome/core/auth"
|
||||
"github.com/deluan/navidrome/log"
|
||||
"github.com/deluan/navidrome/model"
|
||||
"github.com/deluan/navidrome/model/request"
|
||||
"github.com/deluan/navidrome/persistence"
|
||||
"github.com/deluan/navidrome/server/subsonic/engine"
|
||||
"github.com/deluan/navidrome/tests"
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/gomega"
|
||||
)
|
||||
|
@ -117,7 +117,7 @@ var _ = Describe("Middlewares", func() {
|
|||
Describe("Authenticate", func() {
|
||||
var ds model.DataStore
|
||||
BeforeEach(func() {
|
||||
ds = &persistence.MockDataStore{}
|
||||
ds = &tests.MockDataStore{}
|
||||
})
|
||||
|
||||
It("passes authentication with correct credentials", func() {
|
||||
|
@ -222,7 +222,7 @@ var _ = Describe("Middlewares", func() {
|
|||
Describe("validateUser", func() {
|
||||
var ds model.DataStore
|
||||
BeforeEach(func() {
|
||||
ds = &persistence.MockDataStore{}
|
||||
ds = &tests.MockDataStore{}
|
||||
})
|
||||
|
||||
Context("Plaintext password", func() {
|
||||
|
@ -302,7 +302,7 @@ func (mh *mockHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
type mockPlayers struct {
|
||||
engine.Players
|
||||
core.Players
|
||||
transcoding *model.Transcoding
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package persistence
|
||||
package tests
|
||||
|
||||
import (
|
||||
"errors"
|
|
@ -1,4 +1,4 @@
|
|||
package persistence
|
||||
package tests
|
||||
|
||||
import (
|
||||
"errors"
|
|
@ -1,4 +1,4 @@
|
|||
package persistence
|
||||
package tests
|
||||
|
||||
import (
|
||||
"errors"
|
|
@ -1,4 +1,4 @@
|
|||
package persistence
|
||||
package tests
|
||||
|
||||
import (
|
||||
"context"
|
|
@ -1,16 +1,16 @@
|
|||
package core
|
||||
package tests
|
||||
|
||||
import "github.com/deluan/navidrome/model"
|
||||
|
||||
type mockTranscodingRepository struct {
|
||||
type MockTranscodingRepository struct {
|
||||
model.TranscodingRepository
|
||||
}
|
||||
|
||||
func (m *mockTranscodingRepository) Get(id string) (*model.Transcoding, error) {
|
||||
func (m *MockTranscodingRepository) Get(id string) (*model.Transcoding, error) {
|
||||
return &model.Transcoding{ID: id, TargetFormat: "mp3", DefaultBitRate: 160}, nil
|
||||
}
|
||||
|
||||
func (m *mockTranscodingRepository) FindByFormat(format string) (*model.Transcoding, error) {
|
||||
func (m *MockTranscodingRepository) FindByFormat(format string) (*model.Transcoding, error) {
|
||||
switch format {
|
||||
case "mp3":
|
||||
return &model.Transcoding{ID: "mp31", TargetFormat: "mp3", DefaultBitRate: 160}, nil
|
Loading…
Add table
Add a link
Reference in a new issue