Make mocks strongly typed

This commit is contained in:
Deluan
2020-10-27 10:48:37 -04:00
parent 6152fadd92
commit 313a088f86
6 changed files with 25 additions and 32 deletions
+2 -8
View File
@@ -1,9 +1,7 @@
package persistence
import (
"encoding/json"
"errors"
"fmt"
"github.com/deluan/navidrome/model"
)
@@ -24,13 +22,9 @@ func (m *MockAlbum) SetError(err bool) {
m.err = err
}
func (m *MockAlbum) SetData(j string) {
func (m *MockAlbum) SetData(albums model.Albums) {
m.data = make(map[string]model.Album)
m.all = model.Albums{}
err := json.Unmarshal([]byte(j), &m.all)
if err != nil {
fmt.Println("ERROR: ", err)
}
m.all = albums
for _, a := range m.all {
m.data[a.ID] = a
}
+2 -9
View File
@@ -1,9 +1,7 @@
package persistence
import (
"encoding/json"
"errors"
"fmt"
"github.com/deluan/navidrome/model"
)
@@ -22,14 +20,9 @@ func (m *MockArtist) SetError(err bool) {
m.err = err
}
func (m *MockArtist) SetData(j string) {
func (m *MockArtist) SetData(artists model.Artists) {
m.data = make(map[string]model.Artist)
var l = model.Artists{}
err := json.Unmarshal([]byte(j), &l)
if err != nil {
fmt.Println("ERROR: ", err)
}
for _, a := range l {
for _, a := range artists {
m.data[a.ID] = a
}
}
+3 -10
View File
@@ -1,9 +1,7 @@
package persistence
import (
"encoding/json"
"errors"
"fmt"
"github.com/deluan/navidrome/model"
)
@@ -22,15 +20,10 @@ func (m *MockMediaFile) SetError(err bool) {
m.err = err
}
func (m *MockMediaFile) SetData(j string) {
func (m *MockMediaFile) SetData(mfs model.MediaFiles) {
m.data = make(map[string]model.MediaFile)
var l = model.MediaFiles{}
err := json.Unmarshal([]byte(j), &l)
if err != nil {
fmt.Println("ERROR: ", err)
}
for _, a := range l {
m.data[a.ID] = a
for _, mf := range mfs {
m.data[mf.ID] = mf
}
}