-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsplit_statement_connection_pool_test.go
91 lines (66 loc) · 2.71 KB
/
split_statement_connection_pool_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
package sqldb
import (
"context"
"errors"
"reflect"
"testing"
"github.com/smarty/assertions/should"
"github.com/smarty/gunit"
)
func TestSplitStatementConnectionPoolFixture(t *testing.T) {
gunit.Run(new(SplitStatementConnectionPoolFixture), t)
}
type SplitStatementConnectionPoolFixture struct {
*gunit.Fixture
inner *FakeConnectionPool
pool *SplitStatementConnectionPool
}
func (this *SplitStatementConnectionPoolFixture) Setup() {
this.inner = &FakeConnectionPool{}
this.pool = NewSplitStatementConnectionPool(this.inner, "?")
}
///////////////////////////////////////////////////////////////
func (this *SplitStatementConnectionPoolFixture) TestPing() {
this.inner.pingError = errors.New("")
err := this.pool.Ping(context.Background())
this.So(err, should.Equal, this.inner.pingError)
this.So(this.inner.pingCalls, should.Equal, 1)
}
func (this *SplitStatementConnectionPoolFixture) TestBeginTransactionFails() {
this.inner.transactionError = errors.New("")
transaction, err := this.pool.BeginTransaction(context.Background())
this.So(transaction, should.BeNil)
this.So(err, should.Equal, this.inner.transactionError)
this.So(this.inner.transactionCalls, should.Equal, 1)
}
func (this *SplitStatementConnectionPoolFixture) TestBeginTransactionSucceeds() {
this.inner.transaction = &FakeTransaction{}
transaction, err := this.pool.BeginTransaction(context.Background())
this.So(reflect.TypeOf(transaction), should.Equal, reflect.TypeOf(&SplitStatementTransaction{}))
this.So(err, should.BeNil)
this.So(this.inner.transactionCalls, should.Equal, 1)
}
func (this *SplitStatementConnectionPoolFixture) TestClose() {
this.inner.closeError = errors.New("")
err := this.pool.Close()
this.So(err, should.Equal, this.inner.closeError)
this.So(this.inner.closeCalls, should.Equal, 1)
}
func (this *SplitStatementConnectionPoolFixture) TestExecute() {
this.inner.executeResult = 5
affected, err := this.pool.Execute(context.Background(), "statement1 ?; statement2 ? ?;", 1, 2, 3)
this.So(affected, should.Equal, 10)
this.So(err, should.BeNil)
this.So(this.inner.executeCalls, should.Equal, 2)
this.So(this.inner.executeParameters, should.Resemble, []interface{}{2, 3}) // last two parameters
}
func (this *SplitStatementConnectionPoolFixture) TestSelect() {
this.inner.selectError = errors.New("")
this.inner.selectResult = &FakeSelectResult{}
result, err := this.pool.Select(context.Background(), "query", 1, 2, 3)
this.So(result, should.Equal, this.inner.selectResult)
this.So(err, should.Equal, this.inner.selectError)
this.So(this.inner.selectCalls, should.Equal, 1)
this.So(this.inner.selectStatement, should.Equal, "query")
this.So(this.inner.selectParameters, should.Resemble, []interface{}{1, 2, 3})
}