-
Notifications
You must be signed in to change notification settings - Fork 1
/
rdb_test.go
62 lines (49 loc) · 1.04 KB
/
rdb_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package rdb_test
import (
"flag"
"fmt"
"os"
"testing"
_ "github.com/jinzhu/gorm/dialects/mysql"
"github.com/osuripple/rdb"
"gopkg.in/testfixtures.v2"
)
var fixtures *testfixtures.Context
func TestMain(m *testing.M) {
flag.Parse()
// open mysql database connection
err := rdb.OpenDatabase("mysql", getenvDef("DSN", "root@/test?multiStatements=true"))
if err != nil {
fmt.Println(err)
os.Exit(1)
}
if testing.Verbose() {
rdb.DB = rdb.DB.Debug()
}
// only for testing purposes, this creates the tables we need (possibly different than
// the ones created using bdzr)
rdb.DB.AutoMigrate(
&rdb.User{},
)
fixtures, err = testfixtures.NewFolder(rdb.DB.DB(), &testfixtures.MySQL{}, "fixtures")
if err != nil {
fmt.Println(err)
os.Exit(1)
}
res := m.Run()
rdb.DB.Exec("DROP DATABASE test")
rdb.DB.Exec("CREATE DATABASE test")
os.Exit(res)
}
func getenvDef(s string, def string) string {
x := os.Getenv(s)
if x == "" {
return def
}
return x
}
func prepare() {
if err := fixtures.Load(); err != nil {
panic(err)
}
}