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