mirror of
https://github.com/navidrome/navidrome.git
synced 2024-09-10 11:32:48 +02:00
![Deluan](/assets/img/avatar_default.png)
Also refactored mocks into their original packages, to avoid cyclic references. Is there a better way to have mocks in GoLang tests?
39 lines
690 B
Go
39 lines
690 B
Go
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
|
|
}
|