-
Notifications
You must be signed in to change notification settings - Fork 1
/
binding_transaction_adapter_test.go
69 lines (50 loc) · 1.93 KB
/
binding_transaction_adapter_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
package sqldb
import (
"context"
"errors"
"testing"
"github.com/smarty/assertions/should"
"github.com/smarty/gunit"
)
func TestBindingTransactionAdapterFixture(t *testing.T) {
gunit.Run(new(BindingTransactionAdapterFixture), t)
}
type BindingTransactionAdapterFixture struct {
*gunit.Fixture
inner *FakeTransaction
transaction *BindingTransactionAdapter
}
func (this *BindingTransactionAdapterFixture) Setup() {
this.inner = &FakeTransaction{}
this.transaction = NewBindingTransactionAdapter(this.inner, false)
}
///////////////////////////////////////////////////////////////
func (this *BindingTransactionAdapterFixture) TestCommit() {
this.inner.commitError = errors.New("")
err := this.transaction.Commit()
this.So(err, should.Equal, this.inner.commitError)
this.So(this.inner.commitCalls, should.Equal, 1)
}
func (this *BindingTransactionAdapterFixture) TestRollback() {
this.inner.rollbackError = errors.New("")
err := this.transaction.Rollback()
this.So(err, should.Equal, this.inner.rollbackError)
this.So(this.inner.rollbackCalls, should.Equal, 1)
}
func (this *BindingTransactionAdapterFixture) TestExecute() {
this.inner.executeResult = 42
this.inner.executeError = errors.New("")
affected, err := this.transaction.Execute(context.Background(), "statement")
this.So(affected, should.Equal, this.inner.executeResult)
this.So(err, should.Equal, this.inner.executeError)
this.So(this.inner.executeStatement, should.Equal, "statement")
this.So(this.inner.executeCalls, should.Equal, 1)
}
func (this *BindingTransactionAdapterFixture) TestBindSelect() {
this.inner.selectError = errors.New("")
err := this.transaction.BindSelect(context.Background(), nil, "query", 1, 2, 3)
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})
}