testing.go 448 B

123456789101112131415161718192021222324252627282930
  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. }