navidrome/engine/browser_test.go

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

53 lines
1.2 KiB
Go
Raw Normal View History

2020-01-15 23:49:09 +01:00
package engine
import (
"context"
2020-01-15 23:49:09 +01:00
"errors"
2020-01-24 01:44:08 +01:00
"github.com/deluan/navidrome/model"
"github.com/deluan/navidrome/persistence"
2020-01-15 23:49:09 +01:00
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("Browser", func() {
var repo *mockGenreRepository
var b Browser
BeforeEach(func() {
2020-01-15 23:49:09 +01:00
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}
2020-01-15 23:49:09 +01:00
})
It("returns sorted data", func() {
Expect(b.GetGenres(context.TODO())).To(Equal(model.Genres{
2020-01-15 23:49:09 +01:00
{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(context.TODO())
2020-01-15 23:49:09 +01:00
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
}