mirror of
https://github.com/navidrome/navidrome.git
synced 2025-04-04 21:17:37 +03:00
Also refactored mocks into their original packages, to avoid cyclic references. Is there a better way to have mocks in GoLang tests?
44 lines
717 B
Go
44 lines
717 B
Go
package engine
|
|
|
|
import (
|
|
"errors"
|
|
)
|
|
|
|
func CreateMockPropertyRepo() *MockProperty {
|
|
return &MockProperty{data: make(map[string]string)}
|
|
}
|
|
|
|
type MockProperty struct {
|
|
PropertyRepository
|
|
data map[string]string
|
|
err bool
|
|
}
|
|
|
|
func (m *MockProperty) SetError(err bool) {
|
|
m.err = err
|
|
}
|
|
|
|
func (m *MockProperty) Put(id string, value string) error {
|
|
if m.err {
|
|
return errors.New("Error!")
|
|
}
|
|
m.data[id] = value
|
|
return nil
|
|
}
|
|
|
|
func (m *MockProperty) Get(id string) (string, error) {
|
|
if m.err {
|
|
return "", errors.New("Error!")
|
|
}
|
|
return m.data[id], nil
|
|
}
|
|
|
|
func (m *MockProperty) DefaultGet(id string, defaultValue string) (string, error) {
|
|
v, err := m.Get(id)
|
|
|
|
if v == "" {
|
|
v = defaultValue
|
|
}
|
|
|
|
return v, err
|
|
}
|