scanner_test.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. var songs []read.Song
  18. err := db.Select(&songs, `
  19. select title, artist, album, duration, base_path, relative_path
  20. from songs
  21. `)
  22. Expect(err).To(BeNil())
  23. Expect(songs).To(HaveLen(2))
  24. Expect(read.Song{
  25. Title: read.TestSong.Title,
  26. Artist: read.TestSong.Artist,
  27. Album: read.TestSong.Album,
  28. Duration: read.TestSong.Duration,
  29. BasePath: read.TestSong.BasePath,
  30. RelativePath: read.TestSong.RelativePath,
  31. }).To(BeElementOf(songs))
  32. Expect(read.Song{
  33. Title: read.TestSongNested.Title,
  34. Artist: read.TestSongNested.Artist,
  35. Album: read.TestSongNested.Album,
  36. Duration: read.TestSongNested.Duration,
  37. BasePath: read.TestSongNested.BasePath,
  38. RelativePath: read.TestSongNested.RelativePath,
  39. }).To(BeElementOf(songs))
  40. })
  41. })