experimental-cli/project/db_test.go

43 lines
680 B
Go
Raw Normal View History

2020-09-10 12:33:41 +00:00
package main
import (
2020-11-08 15:28:29 +00:00
"os/exec"
2020-09-10 12:33:41 +00:00
"testing"
)
func resetDB() {
2020-09-24 23:43:11 +00:00
tx, err := getDB().Begin()
2020-09-10 12:33:41 +00:00
if err != nil {
2020-09-24 23:43:11 +00:00
panicf("Failed to start transaction: %s", err)
2020-09-10 12:33:41 +00:00
}
for i := len(migrations) - 1; i >= 0; i-- {
_, err := tx.Exec(migrations[i].down)
if err != nil {
2020-09-24 23:43:11 +00:00
panicf("Migration failure: %s", err)
2020-09-10 12:33:41 +00:00
}
}
for _, migration := range migrations {
_, err := tx.Exec(migration.up)
if err != nil {
2020-09-24 23:43:11 +00:00
panicf("Migration failure: %s", err)
2020-09-10 12:33:41 +00:00
}
}
if tx.Commit() != nil {
2020-09-24 23:43:11 +00:00
panic(err)
2020-09-10 12:33:41 +00:00
}
2020-11-08 15:28:29 +00:00
exec.Command("rm", "-rf", pigeonBlobDir())
2020-09-10 12:33:41 +00:00
}
func TestSetUpTeardown(t *testing.T) {
resetDB()
2020-09-24 23:43:11 +00:00
err := getDB().Ping()
2020-09-10 12:33:41 +00:00
if err != nil {
t.Fatalf("Test setup failed: %s", err)
}
}