mirror of
https://github.com/navidrome/navidrome.git
synced 2025-04-04 13:07:36 +03:00
- Create model.DataStore, with provision for transactions - Change all layers dependencies on repositories to use DataStore - Implemented persistence.SQLStore - Removed iTunes Bridge/Importer support
51 lines
1.2 KiB
Go
51 lines
1.2 KiB
Go
package engine
|
|
|
|
import (
|
|
"errors"
|
|
|
|
"github.com/cloudsonic/sonic-server/model"
|
|
"github.com/cloudsonic/sonic-server/persistence"
|
|
. "github.com/onsi/ginkgo"
|
|
. "github.com/onsi/gomega"
|
|
)
|
|
|
|
var _ = Describe("Browser", func() {
|
|
var repo *mockGenreRepository
|
|
var b Browser
|
|
|
|
BeforeSuite(func() {
|
|
repo = &mockGenreRepository{data: model.Genres{
|
|
{Name: "Rock", SongCount: 1000, AlbumCount: 100},
|
|
{Name: "", SongCount: 13, AlbumCount: 13},
|
|
{Name: "Electronic", SongCount: 4000, AlbumCount: 40},
|
|
}}
|
|
var ds = &persistence.MockDataStore{MockedGenre: repo}
|
|
b = &browser{ds: ds}
|
|
})
|
|
|
|
It("returns sorted data", func() {
|
|
Expect(b.GetGenres()).To(Equal(model.Genres{
|
|
{Name: "<Empty>", SongCount: 13, AlbumCount: 13},
|
|
{Name: "Electronic", SongCount: 4000, AlbumCount: 40},
|
|
{Name: "Rock", SongCount: 1000, AlbumCount: 100},
|
|
}))
|
|
})
|
|
|
|
It("bubbles up errors", func() {
|
|
repo.err = errors.New("generic error")
|
|
_, err := b.GetGenres()
|
|
Expect(err).ToNot(BeNil())
|
|
})
|
|
})
|
|
|
|
type mockGenreRepository struct {
|
|
data model.Genres
|
|
err error
|
|
}
|
|
|
|
func (r *mockGenreRepository) GetAll() (model.Genres, error) {
|
|
if r.err != nil {
|
|
return nil, r.err
|
|
}
|
|
return r.data, nil
|
|
}
|