-
Notifications
You must be signed in to change notification settings - Fork 39
/
connection_test.go
63 lines (47 loc) · 1.14 KB
/
connection_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
63
package gosql
import (
"os"
"testing"
_ "github.com/go-sql-driver/mysql"
)
func TestMain(m *testing.M) {
configs := make(map[string]*Config)
dsn1 := os.Getenv("MYSQL_TEST_DSN1")
if dsn1 == "" {
dsn1 = "root:123456@tcp(127.0.0.1:3306)/test?charset=utf8&parseTime=True&loc=Asia%2FShanghai"
}
dsn2 := os.Getenv("MYSQL_TEST_DSN2")
if dsn2 == "" {
dsn2 = "root:123456@tcp(127.0.0.1:3306)/test2?charset=utf8&parseTime=True&loc=Asia%2FShanghai"
}
configs["default"] = &Config{
Enable: true,
Driver: "mysql",
Dsn: dsn1,
ShowSql: true,
}
configs["db2"] = &Config{
Enable: true,
Driver: "mysql",
Dsn: dsn2,
ShowSql: true,
}
_ = Connect(configs)
m.Run()
}
func TestWithOptions(t *testing.T) {
dsn := os.Getenv("MYSQL_TEST_DSN2")
if dsn == "" {
dsn = "root:123456@tcp(127.0.0.1:3306)/test2?charset=utf8&parseTime=True&loc=Asia%2FShanghai"
}
_, err := Open("mysql", dsn, WithMaxOpenConns(10), WithMaxIdleConns(100), WithMaxLifetimes(100))
if err != nil {
t.Error(err)
}
}
func TestConnect(t *testing.T) {
db := Sqlx()
if db.DriverName() != "mysql" {
t.Fatalf("sqlx database connection error")
}
}