2016-03-16 22:48:44 +01:00
|
|
|
package persistence
|
2016-03-01 20:40:26 +01:00
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"errors"
|
2016-03-02 19:18:39 +01:00
|
|
|
"fmt"
|
2016-03-09 02:33:09 +01:00
|
|
|
|
2016-03-02 19:18:39 +01:00
|
|
|
"github.com/deluan/gosonic/domain"
|
2016-03-01 20:40:26 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
func CreateMockArtistIndexRepo() *MockArtistIndex {
|
|
|
|
return &MockArtistIndex{}
|
|
|
|
}
|
|
|
|
|
|
|
|
type MockArtistIndex struct {
|
2016-03-02 15:07:24 +01:00
|
|
|
domain.ArtistIndexRepository
|
2016-03-04 03:01:55 +01:00
|
|
|
data domain.ArtistIndexes
|
2016-03-01 20:40:26 +01:00
|
|
|
err bool
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *MockArtistIndex) SetError(err bool) {
|
|
|
|
m.err = err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *MockArtistIndex) SetData(j string, length int) {
|
2016-03-04 03:01:55 +01:00
|
|
|
m.data = make(domain.ArtistIndexes, length)
|
2016-03-01 20:40:26 +01:00
|
|
|
err := json.Unmarshal([]byte(j), &m.data)
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println("ERROR: ", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-09 02:33:09 +01:00
|
|
|
func (m *MockArtistIndex) GetAll() (*domain.ArtistIndexes, error) {
|
2016-03-01 20:40:26 +01:00
|
|
|
if m.err {
|
|
|
|
return nil, errors.New("Error!")
|
|
|
|
}
|
2016-03-09 02:33:09 +01:00
|
|
|
return &m.data, nil
|
2016-03-01 20:40:26 +01:00
|
|
|
}
|