mirror of
https://github.com/navidrome/navidrome.git
synced 2025-04-03 20:47:35 +03:00
70 lines
1.5 KiB
Go
70 lines
1.5 KiB
Go
package db_ledis
|
|
|
|
import (
|
|
"strconv"
|
|
"testing"
|
|
|
|
"github.com/cloudsonic/sonic-server/domain"
|
|
"github.com/cloudsonic/sonic-server/tests"
|
|
. "github.com/smartystreets/goconvey/convey"
|
|
)
|
|
|
|
func TestIndexRepository(t *testing.T) {
|
|
|
|
tests.Init(t, false)
|
|
|
|
Convey("Subject: NewIndexRepository", t, func() {
|
|
repo := NewArtistIndexRepository()
|
|
|
|
Convey("It should be able to read and write to the database", func() {
|
|
i := &domain.ArtistIndex{ID: "123"}
|
|
|
|
repo.Put(i)
|
|
s, _ := repo.Get("123")
|
|
|
|
So(s, shouldBeEqual, i)
|
|
})
|
|
Convey("It should be able to check for existence 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)
|
|
})
|
|
Convey("Method Put() should return error if ID is not set", func() {
|
|
i := &domain.ArtistIndex{}
|
|
|
|
err := repo.Put(i)
|
|
|
|
So(err, ShouldNotBeNil)
|
|
})
|
|
Convey("Given that I have 4 records", func() {
|
|
for i := 1; i <= 4; i++ {
|
|
e := &domain.ArtistIndex{ID: strconv.Itoa(i)}
|
|
repo.Put(e)
|
|
}
|
|
|
|
Convey("When I call GetAll()", func() {
|
|
indices, err := repo.GetAll()
|
|
Convey("Then It should not return any error", func() {
|
|
So(err, ShouldBeNil)
|
|
})
|
|
Convey("And It should return 4 entities", func() {
|
|
So(indices, ShouldHaveLength, 4)
|
|
})
|
|
Convey("And the values should be retrieved", func() {
|
|
for _, e := range indices {
|
|
So(e.ID, ShouldBeIn, []string{"1", "2", "3", "4"})
|
|
}
|
|
})
|
|
})
|
|
})
|
|
Reset(func() {
|
|
dropDb()
|
|
})
|
|
})
|
|
}
|