2016-03-02 15:07:24 +01:00
|
|
|
package persistence
|
2016-03-01 04:17:54 +01:00
|
|
|
|
|
|
|
import (
|
2016-03-09 02:33:09 +01:00
|
|
|
"strconv"
|
|
|
|
"testing"
|
|
|
|
|
2016-03-02 15:07:24 +01:00
|
|
|
"github.com/deluan/gosonic/domain"
|
2016-03-02 19:18:39 +01:00
|
|
|
"github.com/deluan/gosonic/tests"
|
|
|
|
. "github.com/smartystreets/goconvey/convey"
|
2016-03-01 04:17:54 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestIndexRepository(t *testing.T) {
|
|
|
|
|
|
|
|
tests.Init(t, false)
|
|
|
|
|
|
|
|
Convey("Subject: NewIndexRepository", t, func() {
|
|
|
|
repo := NewArtistIndexRepository()
|
2016-03-01 04:22:50 +01:00
|
|
|
|
2016-03-01 04:17:54 +01:00
|
|
|
Convey("It should be able to read and write to the database", func() {
|
2016-03-02 15:07:24 +01:00
|
|
|
i := &domain.ArtistIndex{Id: "123"}
|
2016-03-01 04:17:54 +01:00
|
|
|
|
|
|
|
repo.Put(i)
|
2016-03-02 19:18:39 +01:00
|
|
|
s, _ := repo.Get("123")
|
2016-03-01 04:17:54 +01:00
|
|
|
|
|
|
|
So(s, shouldBeEqual, i)
|
|
|
|
})
|
2016-03-03 02:00:55 +01:00
|
|
|
Convey("It should be able to check for existance of an Id", func() {
|
|
|
|
i := &domain.ArtistIndex{Id: "123"}
|
|
|
|
|
|
|
|
repo.Put(i)
|
|
|
|
|
|
|
|
s, _ := repo.Exists("123")
|
|
|
|
So(s, ShouldBeTrue)
|
|
|
|
|
|
|
|
s, _ = repo.Exists("NOT_FOUND")
|
|
|
|
So(s, ShouldBeFalse)
|
|
|
|
})
|
2016-03-01 15:17:28 +01:00
|
|
|
Convey("Method Put() should return error if Id is not set", func() {
|
2016-03-02 15:07:24 +01:00
|
|
|
i := &domain.ArtistIndex{}
|
2016-03-01 04:22:50 +01:00
|
|
|
|
|
|
|
err := repo.Put(i)
|
|
|
|
|
|
|
|
So(err, ShouldNotBeNil)
|
|
|
|
})
|
2016-03-01 04:17:54 +01:00
|
|
|
Convey("Given that I have 4 records", func() {
|
|
|
|
for i := 1; i <= 4; i++ {
|
2016-03-02 15:07:24 +01:00
|
|
|
e := &domain.ArtistIndex{Id: strconv.Itoa(i)}
|
2016-03-01 04:17:54 +01:00
|
|
|
repo.Put(e)
|
|
|
|
}
|
|
|
|
|
2016-03-01 04:22:50 +01:00
|
|
|
Convey("When I call GetAll()", func() {
|
2016-03-02 19:18:39 +01:00
|
|
|
indices, err := repo.GetAll()
|
2016-03-01 04:17:54 +01:00
|
|
|
Convey("Then It should not return any error", func() {
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
})
|
2016-03-01 04:39:36 +01:00
|
|
|
Convey("And It should return 4 entities", func() {
|
|
|
|
So(indices, ShouldHaveLength, 4)
|
2016-03-01 04:17:54 +01:00
|
|
|
})
|
2016-03-01 04:39:36 +01:00
|
|
|
Convey("And the values should be retrieved", func() {
|
2016-03-09 02:33:09 +01:00
|
|
|
for _, e := range *indices {
|
2016-03-01 04:17:54 +01:00
|
|
|
So(e.Id, ShouldBeIn, []string{"1", "2", "3", "4"})
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
Reset(func() {
|
|
|
|
dropDb()
|
|
|
|
})
|
|
|
|
})
|
2016-03-02 19:18:39 +01:00
|
|
|
}
|