-
Notifications
You must be signed in to change notification settings - Fork 29
/
driverManager_test.go
53 lines (39 loc) · 1.1 KB
/
driverManager_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
package godbal_test
import (
"testing"
"github.com/xujiajun/godbal"
"gopkg.in/DATA-DOG/go-sqlmock.v1"
)
const (
defaultDriver = "mysql"
)
func TestNewMysql(t *testing.T) {
database := godbal.NewMysql("")
db, _, err := sqlmock.New()
if err != nil {
t.Fatalf("an error '%s' was not expected when opening a mysql database connection", err)
}
defer db.Close()
database.SetDB(db)
}
func TestNewDriveManager(t *testing.T) {
newDriveManager := godbal.NewDriveManager()
drivers := newDriveManager.GetAvailableDrivers()
if driver, ok := drivers[defaultDriver]; ok {
if driver != defaultDriver {
t.Errorf("returned unexpected driver: got %v want %v", driver, defaultDriver)
}
} else {
t.Errorf("an error when TestNewDriveManager driver %s not found ", defaultDriver)
}
}
func TestDriveManager_GetMysqlConnection(t *testing.T) {
newDriveManager := godbal.NewDriveManager()
mysqlDB := newDriveManager.GetMysqlDB("")
db, _, err := sqlmock.New()
if err != nil {
t.Fatalf("an error '%s' was not expected when opening a mysql database connection", err)
}
defer db.Close()
mysqlDB.SetDB(db)
}