scanner_test.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. package services_test
  2. import (
  3. . "github.com/onsi/ginkgo"
  4. . "github.com/onsi/gomega"
  5. "github.com/felamaslen/go-music-player/pkg/database"
  6. "github.com/felamaslen/go-music-player/pkg/read"
  7. "github.com/felamaslen/go-music-player/pkg/services"
  8. setup "github.com/felamaslen/go-music-player/pkg/testing"
  9. )
  10. var _ = Describe("music scanner (integration test)", func() {
  11. BeforeEach(func() {
  12. setup.PrepareDatabaseForTesting()
  13. })
  14. It("should recursively scan files from a directory and add them to the database", func() {
  15. services.ScanAndInsert(read.TestDirectory)
  16. db := database.GetConnection()
  17. rows, err := db.Queryx(`
  18. select title, artist, album, duration, base_path, relative_path
  19. from songs
  20. `)
  21. Expect(err).To(BeNil())
  22. var song read.Song
  23. rows.Next()
  24. rows.StructScan(&song)
  25. Expect(song).To(Equal(read.Song{
  26. Title: read.TestSong.Title,
  27. Artist: read.TestSong.Artist,
  28. Album: read.TestSong.Album,
  29. Duration: read.TestSong.Duration,
  30. BasePath: read.TestSong.BasePath,
  31. RelativePath: read.TestSong.RelativePath,
  32. }))
  33. rows.Close()
  34. })
  35. })