-
Notifications
You must be signed in to change notification settings - Fork 0
/
db_config_test.go
83 lines (69 loc) · 1.48 KB
/
db_config_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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package qube_test
import (
"bytes"
"context"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/winebarrel/qube"
)
func TestAcc_DBConfig(t *testing.T) {
if !testAcc {
t.Skip()
}
require := require.New(t)
ds := []struct {
DSN string
Driver qube.DBDriver
AutoCommit bool
}{
{
DSN: testDSN_MySQL,
Driver: qube.DBDriverMySQL,
AutoCommit: true,
},
{
DSN: testDSN_MySQL,
Driver: qube.DBDriverMySQL,
AutoCommit: false,
},
{
DSN: testDSN_PostgreSQL,
Driver: qube.DBDriverPostgreSQL,
AutoCommit: false,
},
}
for _, d := range ds {
config := &qube.DBConfig{
DSN: d.DSN,
Driver: d.Driver,
Noop: false,
}
db, err := config.OpenDBWithPing(d.AutoCommit)
require.NoError(err)
defer db.Close()
_, err = db.Exec("select 1")
require.NoError(err)
_, err = db.ExecContext(context.Background(), "select 2")
require.NoError(err)
}
}
func Test_DBConfig_Noop(t *testing.T) {
require := require.New(t)
assert := assert.New(t)
var buf bytes.Buffer
config := &qube.DBConfig{
DSN: testDSN_MySQL,
Driver: qube.DBDriverMySQL,
Noop: true,
NullDBOut: &buf,
}
db, err := config.OpenDBWithPing(true)
require.NoError(err)
defer db.Close()
_, err = db.Exec("select 1")
require.NoError(err)
_, err = db.ExecContext(context.Background(), "select 2")
require.NoError(err)
assert.Equal("select 1\nselect 2\n", buf.String())
}