navidrome/tests/mock_share_repo.go

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

47 lines
777 B
Go
Raw Permalink Normal View History

2021-06-08 22:30:19 +02:00
package tests
import (
"github.com/deluan/rest"
"github.com/navidrome/navidrome/model"
)
type MockShareRepo struct {
model.ShareRepository
rest.Repository
rest.Persistable
Entity interface{}
ID string
2021-06-08 22:30:19 +02:00
Cols []string
2021-08-22 17:46:52 +02:00
Error error
2021-06-08 22:30:19 +02:00
}
func (m *MockShareRepo) Save(entity interface{}) (string, error) {
2021-08-22 17:46:52 +02:00
if m.Error != nil {
return "", m.Error
}
s := entity.(*model.Share)
if s.ID == "" {
s.ID = "id"
}
m.Entity = s
return s.ID, nil
2021-06-08 22:30:19 +02:00
}
func (m *MockShareRepo) Update(id string, entity interface{}, cols ...string) error {
2021-08-22 17:46:52 +02:00
if m.Error != nil {
return m.Error
}
m.ID = id
2021-06-08 22:30:19 +02:00
m.Entity = entity
m.Cols = cols
2021-08-22 17:46:52 +02:00
return nil
2021-06-08 22:30:19 +02:00
}
func (m *MockShareRepo) Exists(id string) (bool, error) {
if m.Error != nil {
return false, m.Error
}
return id == m.ID, nil
}