This commit is contained in:
Deluan 2016-03-03 00:46:23 -05:00
parent ffd6304a23
commit 012958cd08
14 changed files with 63 additions and 63 deletions

View File

@ -6,9 +6,9 @@ import (
"github.com/deluan/gosonic/api/responses" "github.com/deluan/gosonic/api/responses"
"github.com/deluan/gosonic/consts" "github.com/deluan/gosonic/consts"
"github.com/deluan/gosonic/domain" "github.com/deluan/gosonic/domain"
. "github.com/deluan/gosonic/tests"
"github.com/deluan/gosonic/tests/mocks" "github.com/deluan/gosonic/tests/mocks"
"github.com/deluan/gosonic/utils" "github.com/deluan/gosonic/utils"
. "github.com/deluan/gosonic/tests"
. "github.com/smartystreets/goconvey/convey" . "github.com/smartystreets/goconvey/convey"
) )

View File

@ -1,11 +1,11 @@
package api package api
import ( import (
"github.com/astaxie/beego"
"github.com/deluan/gosonic/api/responses" "github.com/deluan/gosonic/api/responses"
"github.com/deluan/gosonic/domain" "github.com/deluan/gosonic/domain"
"github.com/deluan/gosonic/utils" "github.com/deluan/gosonic/utils"
"github.com/karlkfi/inject" "github.com/karlkfi/inject"
"github.com/astaxie/beego"
) )
type GetMusicDirectoryController struct { type GetMusicDirectoryController struct {
@ -74,7 +74,7 @@ func (c *GetMusicDirectoryController) Get() {
c.SendResponse(response) c.SendResponse(response)
} }
func (c *GetMusicDirectoryController) retrieveArtist(id string) (a *domain.Artist, as[]domain.Album, found bool) { func (c *GetMusicDirectoryController) retrieveArtist(id string) (a *domain.Artist, as []domain.Album, found bool) {
found, err := c.artistRepo.Exists(id) found, err := c.artistRepo.Exists(id)
if err != nil { if err != nil {
beego.Error("Error searching for Artist:", err) beego.Error("Error searching for Artist:", err)
@ -96,7 +96,7 @@ func (c *GetMusicDirectoryController) retrieveArtist(id string) (a *domain.Artis
return return
} }
func (c *GetMusicDirectoryController) retrieveAlbum(id string) (al *domain.Album, mfs[]domain.MediaFile, found bool) { func (c *GetMusicDirectoryController) retrieveAlbum(id string) (al *domain.Album, mfs []domain.MediaFile, found bool) {
found, err := c.albumRepo.Exists(id) found, err := c.albumRepo.Exists(id)
if err != nil { if err != nil {
beego.Error("Error searching for Album:", err) beego.Error("Error searching for Album:", err)

View File

@ -3,12 +3,12 @@ package api_test
import ( import (
"testing" "testing"
"github.com/deluan/gosonic/api/responses"
"github.com/deluan/gosonic/domain" "github.com/deluan/gosonic/domain"
. "github.com/deluan/gosonic/tests"
"github.com/deluan/gosonic/tests/mocks" "github.com/deluan/gosonic/tests/mocks"
"github.com/deluan/gosonic/utils" "github.com/deluan/gosonic/utils"
. "github.com/deluan/gosonic/tests"
. "github.com/smartystreets/goconvey/convey" . "github.com/smartystreets/goconvey/convey"
"github.com/deluan/gosonic/api/responses"
) )
func TestGetMusicDirectory(t *testing.T) { func TestGetMusicDirectory(t *testing.T) {

View File

@ -1,11 +1,11 @@
package api_test package api_test
import ( import (
"encoding/json"
"github.com/deluan/gosonic/api/responses" "github.com/deluan/gosonic/api/responses"
. "github.com/deluan/gosonic/tests" . "github.com/deluan/gosonic/tests"
. "github.com/smartystreets/goconvey/convey" . "github.com/smartystreets/goconvey/convey"
"testing" "testing"
"encoding/json"
) )
func TestPing(t *testing.T) { func TestPing(t *testing.T) {

View File

@ -1,10 +1,10 @@
package responses_test package responses_test
import ( import (
"testing"
. "github.com/smartystreets/goconvey/convey"
. "github.com/deluan/gosonic/tests"
. "github.com/deluan/gosonic/api/responses" . "github.com/deluan/gosonic/api/responses"
. "github.com/deluan/gosonic/tests"
. "github.com/smartystreets/goconvey/convey"
"testing"
) )
func TestSubsonicResponses(t *testing.T) { func TestSubsonicResponses(t *testing.T) {
@ -60,7 +60,7 @@ func TestSubsonicResponses(t *testing.T) {
Convey("Indexes", func() { Convey("Indexes", func() {
artists := make([]Artist, 1) artists := make([]Artist, 1)
artists[0] = Artist{Id: "111", Name: "aaa"} artists[0] = Artist{Id: "111", Name: "aaa"}
response.Indexes = &Indexes{LastModified:"1", IgnoredArticles:"A"} response.Indexes = &Indexes{LastModified: "1", IgnoredArticles: "A"}
Convey("With data", func() { Convey("With data", func() {
index := make([]Index, 1) index := make([]Index, 1)
@ -95,7 +95,7 @@ func TestSubsonicResponses(t *testing.T) {
}) })
Convey("With just required data", func() { Convey("With just required data", func() {
child := make([]Child, 1) child := make([]Child, 1)
child[0] = Child{ Id:"1", Title: "title", IsDir: false } child[0] = Child{Id: "1", Title: "title", IsDir: false}
response.Directory.Child = child response.Directory.Child = child
Convey("XML", func() { Convey("XML", func() {
So(response, ShouldMatchXML, `<subsonic-response xmlns="http://subsonic.org/restapi" status="ok" version="1.0.0"><directory id="1" name="N"><child id="1" isDir="false" title="title"></child></directory></subsonic-response>`) So(response, ShouldMatchXML, `<subsonic-response xmlns="http://subsonic.org/restapi" status="ok" version="1.0.0"><directory id="1" name="N"><child id="1" isDir="false" title="title"></child></directory></subsonic-response>`)
@ -107,7 +107,7 @@ func TestSubsonicResponses(t *testing.T) {
Convey("With all data", func() { Convey("With all data", func() {
child := make([]Child, 1) child := make([]Child, 1)
child[0] = Child{ child[0] = Child{
Id:"1", IsDir: true, Title: "title", Album: "album", Artist: "artist", Track: 1, Id: "1", IsDir: true, Title: "title", Album: "album", Artist: "artist", Track: 1,
Year: 1985, Genre: "Rock", CoverArt: "1", Size: "8421341", ContentType: "audio/flac", Year: 1985, Genre: "Rock", CoverArt: "1", Size: "8421341", ContentType: "audio/flac",
Suffix: "flac", TranscodedContentType: "audio/mpeg", TranscodedSuffix: "mp3", Suffix: "flac", TranscodedContentType: "audio/mpeg", TranscodedSuffix: "mp3",
Duration: 146, BitRate: 320, Duration: 146, BitRate: 320,

View File

@ -40,7 +40,7 @@ func (r *baseRepository) CountAll() (int, error) {
} }
func (r *baseRepository) Exists(id string) (bool, error) { func (r *baseRepository) Exists(id string) (bool, error) {
res, err := db().SIsMember([]byte(r.table + "s:all"), []byte(id)) res, err := db().SIsMember([]byte(r.table+"s:all"), []byte(id))
return res != 0, err return res != 0, err
} }
@ -132,7 +132,7 @@ func (r *baseRepository) loadAll(entities interface{}, sortBy string, alpha bool
return r.loadFromSet(setName, entities, sortBy, alpha) return r.loadFromSet(setName, entities, sortBy, alpha)
} }
func (r* baseRepository) loadChildren(parentTable string, parentId string, entities interface{}, sortBy string, alpha bool) error { func (r *baseRepository) loadChildren(parentTable string, parentId string, entities interface{}, sortBy string, alpha bool) error {
setName := fmt.Sprintf("%s:%s:%ss", parentTable, parentId, r.table) setName := fmt.Sprintf("%s:%s:%ss", parentTable, parentId, r.table)
return r.loadFromSet(setName, entities, sortBy, alpha) return r.loadFromSet(setName, entities, sortBy, alpha)
} }

View File

@ -35,5 +35,5 @@ func (a byTrackNumber) Swap(i, j int) {
a[i], a[j] = a[j], a[i] a[i], a[j] = a[j], a[i]
} }
func (a byTrackNumber) Less(i, j int) bool { func (a byTrackNumber) Less(i, j int) bool {
return (a[i].DiscNumber * 1000 + a[i].TrackNumber) < (a[j].DiscNumber * 1000 + a[j].TrackNumber) return (a[i].DiscNumber*1000 + a[i].TrackNumber) < (a[j].DiscNumber*1000 + a[j].TrackNumber)
} }

View File

@ -4,9 +4,9 @@ import (
"github.com/dhowden/itl" "github.com/dhowden/itl"
"net/url" "net/url"
"os" "os"
"strings"
"path/filepath" "path/filepath"
"strconv" "strconv"
"strings"
) )
type ItunesScanner struct{} type ItunesScanner struct{}

View File

@ -1,12 +1,12 @@
package tests package tests
import ( import (
. "github.com/smartystreets/goconvey/convey" "bytes"
"encoding/json" "encoding/json"
"encoding/xml" "encoding/xml"
"fmt" "fmt"
"github.com/deluan/gosonic/api/responses" "github.com/deluan/gosonic/api/responses"
"bytes" . "github.com/smartystreets/goconvey/convey"
) )
func ShouldMatchXML(actual interface{}, expected ...interface{}) string { func ShouldMatchXML(actual interface{}, expected ...interface{}) string {

View File

@ -2,9 +2,9 @@ package mocks
import ( import (
"encoding/json" "encoding/json"
"errors"
"fmt" "fmt"
"github.com/deluan/gosonic/domain" "github.com/deluan/gosonic/domain"
"errors"
) )
func CreateMockAlbumRepo() *MockAlbum { func CreateMockAlbumRepo() *MockAlbum {
@ -37,7 +37,7 @@ func (m *MockAlbum) Exists(id string) (bool, error) {
if m.err { if m.err {
return false, errors.New("Error!") return false, errors.New("Error!")
} }
_, found := m.data[id]; _, found := m.data[id]
return found, nil return found, nil
} }

View File

@ -2,9 +2,9 @@ package mocks
import ( import (
"encoding/json" "encoding/json"
"errors"
"fmt" "fmt"
"github.com/deluan/gosonic/domain" "github.com/deluan/gosonic/domain"
"errors"
) )
func CreateMockArtistRepo() *MockArtist { func CreateMockArtistRepo() *MockArtist {
@ -37,7 +37,7 @@ func (m *MockArtist) Exists(id string) (bool, error) {
if m.err { if m.err {
return false, errors.New("Error!") return false, errors.New("Error!")
} }
_, found := m.data[id]; _, found := m.data[id]
return found, nil return found, nil
} }

View File

@ -2,9 +2,9 @@ package mocks
import ( import (
"encoding/json" "encoding/json"
"errors"
"fmt" "fmt"
"github.com/deluan/gosonic/domain" "github.com/deluan/gosonic/domain"
"errors"
) )
func CreateMockMediaFileRepo() *MockMediaFile { func CreateMockMediaFileRepo() *MockMediaFile {
@ -37,7 +37,7 @@ func (m *MockMediaFile) Exists(id string) (bool, error) {
if m.err { if m.err {
return false, errors.New("Error!") return false, errors.New("Error!")
} }
_, found := m.data[id]; _, found := m.data[id]
return found, nil return found, nil
} }