quintodrome/tests/mock_share_repo.go

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

60 lines
1,013 B
Go
Raw Normal View History

2021-06-08 12:30:19 -08:00
package tests
import (
"github.com/deluan/rest"
"github.com/navidrome/navidrome/model"
)
type MockShareRepo struct {
model.ShareRepository
rest.Repository
rest.Persistable
2026-02-08 05:57:30 -09:00
Entity any
ID string
2021-06-08 12:30:19 -08:00
Cols []string
2021-08-22 07:46:52 -08:00
Error error
2021-06-08 12:30:19 -08:00
}
2026-02-08 05:57:30 -09:00
func (m *MockShareRepo) Save(entity any) (string, error) {
2021-08-22 07:46:52 -08: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 12:30:19 -08:00
}
2026-02-08 05:57:30 -09:00
func (m *MockShareRepo) Update(id string, entity any, cols ...string) error {
2021-08-22 07:46:52 -08:00
if m.Error != nil {
return m.Error
}
m.ID = id
2021-06-08 12:30:19 -08:00
m.Entity = entity
m.Cols = cols
2021-08-22 07:46:52 -08:00
return nil
2021-06-08 12:30:19 -08:00
}
func (m *MockShareRepo) Exists(id string) (bool, error) {
if m.Error != nil {
return false, m.Error
}
return id == m.ID, nil
}
func (m *MockShareRepo) Get(id string) (*model.Share, error) {
if m.Error != nil {
return nil, m.Error
}
if id != m.ID {
return nil, model.ErrNotFound
}
if s, ok := m.Entity.(*model.Share); ok {
return s, nil
}
return &model.Share{ID: id}, nil
}