Implemented ProperyRepository. Now the Scanner stores the LastScan timestamp

This commit is contained in:
Deluan
2016-03-01 14:40:26 -05:00
parent 1ceefda6ca
commit 841d8f457f
10 changed files with 178 additions and 38 deletions
+38
View File
@@ -0,0 +1,38 @@
package mocks
import (
"github.com/deluan/gosonic/models"
"fmt"
"encoding/json"
"github.com/deluan/gosonic/repositories"
"errors"
)
func CreateMockArtistIndexRepo() *MockArtistIndex {
return &MockArtistIndex{}
}
type MockArtistIndex struct {
repositories.ArtistIndexImpl
data []models.ArtistIndex
err bool
}
func (m *MockArtistIndex) SetError(err bool) {
m.err = err
}
func (m *MockArtistIndex) SetData(j string, length int) {
m.data = make([]models.ArtistIndex, length)
err := json.Unmarshal([]byte(j), &m.data)
if err != nil {
fmt.Println("ERROR: ", err)
}
}
func (m *MockArtistIndex) GetAll() ([]models.ArtistIndex, error) {
if m.err {
return nil, errors.New("Error!")
}
return m.data, nil
}
+36
View File
@@ -0,0 +1,36 @@
package mocks
import (
"github.com/deluan/gosonic/repositories"
"errors"
)
func CreateMockPropertyRepo() *MockProperty {
return &MockProperty{data: make(map[string]string)}
}
type MockProperty struct {
repositories.PropertyImpl
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!")
} else {
return m.data[id], nil
}
}