-
Notifications
You must be signed in to change notification settings - Fork 2
/
dummy_test.go
52 lines (40 loc) · 972 Bytes
/
dummy_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
package nject_test
import (
"database/sql"
"database/sql/driver"
"fmt"
)
// some DummyDriver parts taken from
// https://github.com/vyskocilm/gazpacho/tree/master/dbmagic
func init() {
sql.Register("dummy", &DummyDriver{})
}
var _ driver.Driver = &DummyDriver{}
var _ driver.Conn = &DummyConn{}
var _ driver.Tx = &DummyTx{}
type DummyDriver struct{}
func (d *DummyDriver) Open(name string) (driver.Conn, error) {
fmt.Println("db open")
return &DummyConn{}, nil
}
type DummyConn struct{}
func (c *DummyConn) Prepare(query string) (driver.Stmt, error) {
return nil, fmt.Errorf("not implemented")
}
func (c *DummyConn) Close() error {
fmt.Println("db close")
return nil
}
func (c *DummyConn) Begin() (driver.Tx, error) {
fmt.Println("tx begin")
return &DummyTx{}, nil
}
type DummyTx struct{}
func (t *DummyTx) Commit() error {
fmt.Println("tx committed")
return nil
}
func (t *DummyTx) Rollback() error {
fmt.Println("tx rolled back")
return nil
}