-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdriver_test.go
57 lines (45 loc) · 1.26 KB
/
driver_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
package sqlplus
import (
"context"
"database/sql/driver"
"testing"
"github.com/stretchr/testify/assert"
)
var _ driver.Driver = (*mockDriver)(nil)
var _ driver.DriverContext = (*mockDriverCtx)(nil)
var _ driver.Driver = (*mockDriverCtx)(nil)
type (
mockDriver struct{}
mockDriverCtx struct{}
)
func (d *mockDriver) Open(_ string) (driver.Conn, error) {
return &mockConn{}, nil
}
// -----------------
func (m *mockDriverCtx) OpenConnector(_ string) (driver.Connector, error) {
return &mockConnector{}, nil
}
func (m *mockDriverCtx) Open(_ string) (driver.Conn, error) {
return &mockConn{}, nil
}
func TestNew(t *testing.T) {
t.Run("mockDriver", func(t *testing.T) {
d := New(&mockDriver{}, &mockHook{})
conn, err := d.Open("any")
assert.NoError(t, err)
assert.NotNil(t, conn)
})
t.Run("mockDriverCtx", func(t *testing.T) {
d := New(&mockDriverCtx{}, NewMultiHook(&mockHook{}))
connect, err := d.Open("any")
assert.NoError(t, err)
assert.NotNil(t, connect)
driverContext := d.(driver.DriverContext)
openConnector, err := driverContext.OpenConnector("any")
assert.NoError(t, err)
connect, err = openConnector.Connect(context.Background())
assert.NoError(t, err)
assert.NotNil(t, connect)
assert.NotNil(t, openConnector.Driver())
})
}