| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- package repository_test
- import (
- . "github.com/onsi/ginkgo"
- . "github.com/onsi/gomega"
- "github.com/felamaslen/go-music-player/pkg/database"
- "github.com/felamaslen/go-music-player/pkg/read"
- "github.com/felamaslen/go-music-player/pkg/repository"
- setup "github.com/felamaslen/go-music-player/pkg/testing"
- )
- var _ = Describe("songs repository", func() {
- db := database.GetConnection()
- BeforeEach(func() {
- setup.PrepareDatabaseForTesting()
- })
- Context("when reading", func() {
- var id int64
- BeforeEach(func() {
- db.QueryRowx(
- `
- insert into songs (track_number, title, artist, album, duration, modified_date, base_path, relative_path)
- values ($1, $2, $3, $4, $5, $6, $7, $8)
- returning id
- `,
- 7,
- "Hey Jude",
- "The Beatles",
- "",
- 431,
- 8876,
- "/path/to",
- "file.ogg",
- ).Scan(&id)
- })
- It("should retrieve a song from the database", func() {
- Expect(id).NotTo(BeZero())
- result, err := repository.SelectSong(db, int(id))
- Expect(err).To(BeNil())
- Expect(result).To(Equal(&read.Song{
- TrackNumber: 7,
- Title: "Hey Jude",
- Artist: "The Beatles",
- Album: "",
- Duration: 431,
- BasePath: "/path/to",
- RelativePath: "file.ogg",
- ModifiedDate: 8876,
- }))
- })
- Context("when the song does not exist", func() {
- It("should return an error", func() {
- result, err := repository.SelectSong(db, 88113)
- Expect(err).To(MatchError("No such ID"))
- Expect(result).To(BeNil())
- })
- })
- })
- })
|