mirror of
https://github.com/navidrome/navidrome.git
synced 2026-10-14 13:27:09 +02:00
Introduced engine.Scrobbler
Also refactored mocks into their original packages, to avoid cyclic references. Is there a better way to have mocks in GoLang tests?
This commit is contained in:
parent
4aa02e68e5
commit
b660a70688
16 changed files with 156 additions and 45 deletions
|
|
@ -5,8 +5,8 @@ import (
|
|||
|
||||
"github.com/deluan/gosonic/api/responses"
|
||||
"github.com/deluan/gosonic/domain"
|
||||
"github.com/deluan/gosonic/persistence"
|
||||
. "github.com/deluan/gosonic/tests"
|
||||
"github.com/deluan/gosonic/tests/mocks"
|
||||
"github.com/deluan/gosonic/utils"
|
||||
. "github.com/smartystreets/goconvey/convey"
|
||||
)
|
||||
|
|
@ -14,7 +14,7 @@ import (
|
|||
func TestGetAlbumList(t *testing.T) {
|
||||
Init(t, false)
|
||||
|
||||
mockAlbumRepo := mocks.CreateMockAlbumRepo()
|
||||
mockAlbumRepo := persistence.CreateMockAlbumRepo()
|
||||
utils.DefineSingleton(new(domain.AlbumRepository), func() domain.AlbumRepository {
|
||||
return mockAlbumRepo
|
||||
})
|
||||
|
|
|
|||
|
|
@ -46,6 +46,9 @@ func (c *BaseAPIController) ParamInt(param string, def int) int {
|
|||
|
||||
func (c *BaseAPIController) ParamBool(param string, def bool) bool {
|
||||
value := def
|
||||
if c.Input().Get(param) == "" {
|
||||
return def
|
||||
}
|
||||
c.Ctx.Input.Bind(&value, param)
|
||||
return value
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,8 +7,8 @@ import (
|
|||
"github.com/deluan/gosonic/consts"
|
||||
"github.com/deluan/gosonic/domain"
|
||||
"github.com/deluan/gosonic/engine"
|
||||
"github.com/deluan/gosonic/persistence"
|
||||
. "github.com/deluan/gosonic/tests"
|
||||
"github.com/deluan/gosonic/tests/mocks"
|
||||
"github.com/deluan/gosonic/utils"
|
||||
. "github.com/smartystreets/goconvey/convey"
|
||||
)
|
||||
|
|
@ -35,11 +35,11 @@ const (
|
|||
func TestGetIndexes(t *testing.T) {
|
||||
Init(t, false)
|
||||
|
||||
mockRepo := mocks.CreateMockArtistIndexRepo()
|
||||
mockRepo := persistence.CreateMockArtistIndexRepo()
|
||||
utils.DefineSingleton(new(domain.ArtistIndexRepository), func() domain.ArtistIndexRepository {
|
||||
return mockRepo
|
||||
})
|
||||
propRepo := mocks.CreateMockPropertyRepo()
|
||||
propRepo := engine.CreateMockPropertyRepo()
|
||||
utils.DefineSingleton(new(engine.PropertyRepository), func() engine.PropertyRepository {
|
||||
return propRepo
|
||||
})
|
||||
|
|
@ -116,15 +116,15 @@ func TestGetIndexes(t *testing.T) {
|
|||
func TestGetMusicDirectory(t *testing.T) {
|
||||
Init(t, false)
|
||||
|
||||
mockArtistRepo := mocks.CreateMockArtistRepo()
|
||||
mockArtistRepo := persistence.CreateMockArtistRepo()
|
||||
utils.DefineSingleton(new(domain.ArtistRepository), func() domain.ArtistRepository {
|
||||
return mockArtistRepo
|
||||
})
|
||||
mockAlbumRepo := mocks.CreateMockAlbumRepo()
|
||||
mockAlbumRepo := persistence.CreateMockAlbumRepo()
|
||||
utils.DefineSingleton(new(domain.AlbumRepository), func() domain.AlbumRepository {
|
||||
return mockAlbumRepo
|
||||
})
|
||||
mockMediaFileRepo := mocks.CreateMockMediaFileRepo()
|
||||
mockMediaFileRepo := persistence.CreateMockMediaFileRepo()
|
||||
utils.DefineSingleton(new(domain.MediaFileRepository), func() domain.MediaFileRepository {
|
||||
return mockMediaFileRepo
|
||||
})
|
||||
|
|
|
|||
|
|
@ -10,8 +10,8 @@ import (
|
|||
"github.com/astaxie/beego"
|
||||
"github.com/deluan/gosonic/api/responses"
|
||||
"github.com/deluan/gosonic/domain"
|
||||
"github.com/deluan/gosonic/persistence"
|
||||
. "github.com/deluan/gosonic/tests"
|
||||
"github.com/deluan/gosonic/tests/mocks"
|
||||
"github.com/deluan/gosonic/utils"
|
||||
. "github.com/smartystreets/goconvey/convey"
|
||||
)
|
||||
|
|
@ -28,7 +28,7 @@ func getCoverArt(params ...string) (*http.Request, *httptest.ResponseRecorder) {
|
|||
func TestGetCoverArt(t *testing.T) {
|
||||
Init(t, false)
|
||||
|
||||
mockMediaFileRepo := mocks.CreateMockMediaFileRepo()
|
||||
mockMediaFileRepo := persistence.CreateMockMediaFileRepo()
|
||||
utils.DefineSingleton(new(domain.MediaFileRepository), func() domain.MediaFileRepository {
|
||||
return mockMediaFileRepo
|
||||
})
|
||||
|
|
|
|||
|
|
@ -6,38 +6,31 @@ import (
|
|||
|
||||
"github.com/astaxie/beego"
|
||||
"github.com/deluan/gosonic/api/responses"
|
||||
"github.com/deluan/gosonic/domain"
|
||||
"github.com/deluan/gosonic/itunesbridge"
|
||||
"github.com/deluan/gosonic/engine"
|
||||
"github.com/deluan/gosonic/utils"
|
||||
)
|
||||
|
||||
type MediaAnnotationController struct {
|
||||
BaseAPIController
|
||||
itunes itunesbridge.ItunesControl
|
||||
mfRepo domain.MediaFileRepository
|
||||
scrobbler engine.Scrobbler
|
||||
}
|
||||
|
||||
func (c *MediaAnnotationController) Prepare() {
|
||||
utils.ResolveDependencies(&c.itunes, &c.mfRepo)
|
||||
utils.ResolveDependencies(&c.scrobbler)
|
||||
}
|
||||
|
||||
func (c *MediaAnnotationController) Scrobble() {
|
||||
id := c.RequiredParamString("id", "Required id parameter is missing")
|
||||
time := c.ParamTime("time", time.Now())
|
||||
submission := c.ParamBool("submission", true)
|
||||
|
||||
submission := c.ParamBool("submission", false)
|
||||
println(submission)
|
||||
if submission {
|
||||
mf, err := c.mfRepo.Get(id)
|
||||
if err != nil || mf == nil {
|
||||
beego.Error("Id", id, "not found!")
|
||||
c.SendError(responses.ERROR_DATA_NOT_FOUND, "Id not found")
|
||||
}
|
||||
|
||||
beego.Info(fmt.Sprintf(`Scrobbling (%s) "%s" at %v`, id, mf.Title, time))
|
||||
if err := c.itunes.Scrobble(id, time); err != nil {
|
||||
mf, err := c.scrobbler.Register(id, time, true)
|
||||
if err != nil {
|
||||
beego.Error("Error scrobbling:", err)
|
||||
c.SendError(responses.ERROR_GENERIC, "Internal error")
|
||||
}
|
||||
beego.Info(fmt.Sprintf(`Scrobbled (%s) "%s" at %v`, id, mf.Title, time))
|
||||
}
|
||||
|
||||
response := c.NewEmpty()
|
||||
|
|
|
|||
|
|
@ -3,16 +3,17 @@ package api_test
|
|||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/deluan/gosonic/api/responses"
|
||||
"github.com/deluan/gosonic/domain"
|
||||
. "github.com/deluan/gosonic/tests"
|
||||
"github.com/deluan/gosonic/tests/mocks"
|
||||
"github.com/deluan/gosonic/utils"
|
||||
. "github.com/smartystreets/goconvey/convey"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
|
||||
"github.com/astaxie/beego"
|
||||
"fmt"
|
||||
"github.com/deluan/gosonic/api/responses"
|
||||
"github.com/deluan/gosonic/domain"
|
||||
"github.com/deluan/gosonic/persistence"
|
||||
. "github.com/deluan/gosonic/tests"
|
||||
"github.com/deluan/gosonic/utils"
|
||||
. "github.com/smartystreets/goconvey/convey"
|
||||
)
|
||||
|
||||
func stream(params ...string) (*http.Request, *httptest.ResponseRecorder) {
|
||||
|
|
@ -27,7 +28,7 @@ func stream(params ...string) (*http.Request, *httptest.ResponseRecorder) {
|
|||
func TestStream(t *testing.T) {
|
||||
Init(t, false)
|
||||
|
||||
mockMediaFileRepo := mocks.CreateMockMediaFileRepo()
|
||||
mockMediaFileRepo := persistence.CreateMockMediaFileRepo()
|
||||
utils.DefineSingleton(new(domain.MediaFileRepository), func() domain.MediaFileRepository {
|
||||
return mockMediaFileRepo
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue