/
connection_test.go
98 lines (80 loc) · 2.02 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package dbi
import (
"os"
"testing"
)
type DummyConnection struct {
host string
userinfo string
db string
options map[string][]string
}
func (self *DummyConnection) Query(sql string, params ...interface{}) (ResultSet, os.Error) {
return new(DummyResultSet), nil
}
func (self *DummyConnection) Execute(sql string, params ...interface{}) os.Error {
return nil
}
func (self *DummyConnection) Prepare(sql string) (Statement, os.Error) {
return nil, nil
}
func (self *DummyConnection) BeginTransaction() os.Error {
return nil
}
func (self *DummyConnection) Rollback() os.Error {
return nil
}
func (self *DummyConnection) Commit() os.Error {
return nil
}
func (self *DummyConnection) Close() os.Error {
return nil
}
//
// Below we test everything via the Connection interface to ensure that
// the method really needs to be provided by DummyConnection.
//
func TestCloseMethodWorks(*testing.T) {
conn := new(DummyConnection)
func(c Connection) {
c.Close()
}(conn)
}
func TestExecuteMethodWorks(t *testing.T) {
conn := new(DummyConnection)
func(c Connection) {
err := c.Execute("CREATE TABLE users (...)")
if err != nil {
t.Fatal("Expected Execute() to pass")
}
}(conn)
}
func TestQueryMethodWorks(t *testing.T) {
conn := new(DummyConnection)
func (c Connection) {
_, err := c.Query("SELECT * FROM users")
if err != nil {
t.Fatal("Expected Query() to pass")
}
}(conn)
}
func TestPrepareMethodWorks(t *testing.T) {
func (c Connection) {
_, _ = c.Prepare("SELECT * FROM users")
}(new(DummyConnection))
}
func TestBeginTransactionMethodWorks(t *testing.T) {
func(c Connection) {
c.BeginTransaction()
}(new(DummyConnection))
}
func TestRollbackMethodWorks(t *testing.T) {
func(c Connection) {
c.Rollback()
}(new(DummyConnection))
}
func TestCommitMethodWorks(t *testing.T) {
func(c Connection) {
c.Commit()
}(new(DummyConnection))
}