mirror of
https://github.com/navidrome/navidrome.git
synced 2024-09-11 20:12:54 +02:00
60 lines
1.1 KiB
Go
60 lines
1.1 KiB
Go
package tests
|
|
|
|
import "github.com/navidrome/navidrome/model"
|
|
|
|
type MockedUserPropsRepo struct {
|
|
model.UserPropsRepository
|
|
data map[string]string
|
|
err error
|
|
}
|
|
|
|
func (p *MockedUserPropsRepo) init() {
|
|
if p.data == nil {
|
|
p.data = make(map[string]string)
|
|
}
|
|
}
|
|
|
|
func (p *MockedUserPropsRepo) Put(userId, key string, value string) error {
|
|
if p.err != nil {
|
|
return p.err
|
|
}
|
|
p.init()
|
|
p.data[userId+key] = value
|
|
return nil
|
|
}
|
|
|
|
func (p *MockedUserPropsRepo) Get(userId, key string) (string, error) {
|
|
if p.err != nil {
|
|
return "", p.err
|
|
}
|
|
p.init()
|
|
if v, ok := p.data[userId+key]; ok {
|
|
return v, nil
|
|
}
|
|
return "", model.ErrNotFound
|
|
}
|
|
|
|
func (p *MockedUserPropsRepo) Delete(userId, key string) error {
|
|
if p.err != nil {
|
|
return p.err
|
|
}
|
|
p.init()
|
|
if _, ok := p.data[userId+key]; ok {
|
|
delete(p.data, userId+key)
|
|
return nil
|
|
}
|
|
return model.ErrNotFound
|
|
}
|
|
|
|
func (p *MockedUserPropsRepo) DefaultGet(userId, key string, defaultValue string) (string, error) {
|
|
if p.err != nil {
|
|
return "", p.err
|
|
}
|
|
p.init()
|
|
v, err := p.Get(userId, key)
|
|
if err != nil {
|
|
return defaultValue, nil
|
|
}
|
|
return v, nil
|
|
}
|