scan_test.go 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. package repository_test
  2. import (
  3. "time"
  4. . "github.com/onsi/ginkgo"
  5. . "github.com/onsi/gomega"
  6. "github.com/felamaslen/gmus-backend/pkg/database"
  7. "github.com/felamaslen/gmus-backend/pkg/repository"
  8. setup "github.com/felamaslen/gmus-backend/pkg/testing"
  9. "github.com/felamaslen/gmus-backend/pkg/types"
  10. )
  11. var _ = Describe("scan repository", func() {
  12. db := database.GetConnection()
  13. BeforeEach(func() {
  14. setup.PrepareDatabaseForTesting()
  15. })
  16. Describe("InsertScanError", func() {
  17. BeforeEach(func() {
  18. repository.InsertScanError(db, &types.ScanError{
  19. CreatedAt: time.Date(2021, 4, 20, 11, 17, 25, 0, time.UTC),
  20. BasePath: "/my/base/path",
  21. RelativePath: "path/to/file.ogg",
  22. Error: "File does not exist or something",
  23. })
  24. })
  25. It("should insert the error into the database", func() {
  26. var result []*types.ScanError
  27. db.Select(&result, `
  28. select created_at, base_path, relative_path, error
  29. from scan_errors
  30. `)
  31. Expect(result).To(HaveLen(1))
  32. Expect(result[0]).To(Equal(&types.ScanError{
  33. CreatedAt: time.Date(2021, 4, 20, 11, 17, 25, 0, time.UTC).In(time.Local),
  34. BasePath: "/my/base/path",
  35. RelativePath: "path/to/file.ogg",
  36. Error: "File does not exist or something",
  37. }))
  38. })
  39. })
  40. // Note; SelectNewOrUpdatedFiles logic is tested via pkg/read/files_test.go
  41. })