First version of getAlbumList.view working.

- It still misses almost all type options
- Introduced "parent" in Child subresponse, as it was breaking DSub
This commit is contained in:
Deluan
2016-03-04 09:09:16 -05:00
parent 87e012f3bf
commit 9a246b5432
12 changed files with 239 additions and 48 deletions
+11 -1
View File
@@ -2,12 +2,12 @@ package tests
import (
"bytes"
"crypto/md5"
"encoding/json"
"encoding/xml"
"fmt"
"github.com/deluan/gosonic/api/responses"
. "github.com/smartystreets/goconvey/convey"
"crypto/md5"
)
func ShouldMatchXML(actual interface{}, expected ...interface{}) string {
@@ -49,6 +49,16 @@ func ShouldMatchMD5(actual interface{}, expected ...interface{}) string {
return ShouldEqual(a, expected[0].(string))
}
func ShouldBeAValid(actual interface{}, expected ...interface{}) string {
v := responses.Subsonic{}
err := json.Unmarshal(actual.(*bytes.Buffer).Bytes(), &v)
if err != nil {
return fmt.Sprintf("Malformed response: %v", err)
}
return ""
}
func UnindentJSON(j []byte) string {
var m = make(map[string]interface{})
json.Unmarshal(j, &m)
+15 -5
View File
@@ -13,8 +13,10 @@ func CreateMockAlbumRepo() *MockAlbum {
type MockAlbum struct {
domain.AlbumRepository
data map[string]*domain.Album
err bool
data map[string]*domain.Album
all domain.Albums
err bool
Options domain.QueryOptions
}
func (m *MockAlbum) SetError(err bool) {
@@ -23,12 +25,12 @@ func (m *MockAlbum) SetError(err bool) {
func (m *MockAlbum) SetData(j string, size int) {
m.data = make(map[string]*domain.Album)
var l = make([]domain.Album, size)
err := json.Unmarshal([]byte(j), &l)
m.all = make(domain.Albums, size)
err := json.Unmarshal([]byte(j), &m.all)
if err != nil {
fmt.Println("ERROR: ", err)
}
for _, a := range l {
for _, a := range m.all {
m.data[a.Id] = &a
}
}
@@ -48,6 +50,14 @@ func (m *MockAlbum) Get(id string) (*domain.Album, error) {
return m.data[id], nil
}
func (m *MockAlbum) GetAll(qo domain.QueryOptions) (domain.Albums, error) {
m.Options = qo
if m.err {
return nil, errors.New("Error!")
}
return m.all, nil
}
func (m *MockAlbum) FindByArtist(artistId string) (domain.Albums, error) {
if m.err {
return nil, errors.New("Error!")