testing.go 491 B

12345678910111213141516171819202122232425262728293031
  1. package testing
  2. import (
  3. "os"
  4. "path"
  5. "runtime"
  6. "github.com/felamaslen/gmus-backend/pkg/database"
  7. )
  8. func ChangeToRootDir() {
  9. _, filename, _, _ := runtime.Caller(0)
  10. dir := path.Join(path.Dir(filename), "../..")
  11. err := os.Chdir(dir)
  12. if err != nil {
  13. panic(err)
  14. }
  15. }
  16. func init() {
  17. ChangeToRootDir()
  18. }
  19. func PrepareDatabaseForTesting() {
  20. database.MigrateDatabase()
  21. db := database.GetConnection()
  22. db.MustExec("truncate table songs")
  23. db.MustExec("truncate table scan_errors")
  24. }