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:
Deluan
2016-03-16 17:48:44 -04:00
parent 4aa02e68e5
commit b660a70688
16 changed files with 158 additions and 47 deletions
+38
View File
@@ -0,0 +1,38 @@
package persistence
import (
"encoding/json"
"errors"
"fmt"
"github.com/deluan/gosonic/domain"
)
func CreateMockArtistIndexRepo() *MockArtistIndex {
return &MockArtistIndex{}
}
type MockArtistIndex struct {
domain.ArtistIndexRepository
data domain.ArtistIndexes
err bool
}
func (m *MockArtistIndex) SetError(err bool) {
m.err = err
}
func (m *MockArtistIndex) SetData(j string, length int) {
m.data = make(domain.ArtistIndexes, length)
err := json.Unmarshal([]byte(j), &m.data)
if err != nil {
fmt.Println("ERROR: ", err)
}
}
func (m *MockArtistIndex) GetAll() (*domain.ArtistIndexes, error) {
if m.err {
return nil, errors.New("Error!")
}
return &m.data, nil
}