Started the implementation of getMusicDirectory. Probably will need to introduce a new 'service' layer...

This commit is contained in:
Deluan
2016-03-02 20:00:55 -05:00
parent 68786d4b39
commit 9577d9ae87
15 changed files with 166 additions and 16 deletions
@@ -5,6 +5,8 @@ import (
"encoding/json"
"encoding/xml"
"fmt"
"github.com/deluan/gosonic/api/responses"
"bytes"
)
func ShouldMatchXML(actual interface{}, expected ...interface{}) string {
@@ -25,6 +27,17 @@ func ShouldMatchJSON(actual interface{}, expected ...interface{}) string {
return ShouldEqual(s, expected[0].(string))
}
func ShouldReceiveError(actual interface{}, expected ...interface{}) string {
v := responses.Subsonic{}
err := xml.Unmarshal(actual.(*bytes.Buffer).Bytes(), &v)
if err != nil {
return fmt.Sprintf("Malformed XML: %v", err)
}
return ShouldEqual(v.Error.Code, expected[0].(int))
}
func UnindentJSON(j []byte) string {
var m = make(map[string]interface{})
json.Unmarshal(j, &m)
+38
View File
@@ -0,0 +1,38 @@
package mocks
import (
"encoding/json"
"fmt"
"github.com/deluan/gosonic/domain"
"errors"
)
func CreateMockArtistRepo() *MockArtist {
return &MockArtist{}
}
type MockArtist struct {
domain.ArtistRepository
data map[string]domain.Artist
err bool
}
func (m *MockArtist) SetError(err bool) {
m.err = err
}
func (m *MockArtist) SetData(j string) {
m.data = make(map[string]domain.Artist)
err := json.Unmarshal([]byte(j), &m.data)
if err != nil {
fmt.Println("ERROR: ", err)
}
}
func (m *MockArtist) Exists(id string) (bool, error) {
if m.err {
return false, errors.New("Error!")
}
_, found := m.data[id];
return found, nil
}