-
Notifications
You must be signed in to change notification settings - Fork 1
/
stack_trace_transaction_test.go
72 lines (54 loc) · 2.14 KB
/
stack_trace_transaction_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
package sqldb
import (
"context"
"errors"
"testing"
"github.com/smarty/assertions/should"
"github.com/smarty/gunit"
)
func TestStackTraceTransactionFixture(t *testing.T) {
gunit.Run(new(StackTraceTransactionFixture), t)
}
type StackTraceTransactionFixture struct {
*gunit.Fixture
inner *FakeTransaction
transaction *StackTraceTransaction
}
func (this *StackTraceTransactionFixture) Setup() {
this.inner = new(FakeTransaction)
this.transaction = NewStackTraceTransaction(this.inner)
this.transaction.StackTrace = ContrivedStackTrace("STACK")
}
func (this *StackTraceTransactionFixture) TestCommit() {
this.inner.commitError = errors.New("ERROR")
err := this.transaction.Commit()
this.So(err.Error(), should.Equal, "ERROR\nStack Trace:\nSTACK")
this.So(this.inner.commitCalls, should.Equal, 1)
}
func (this *StackTraceTransactionFixture) TestRollback() {
this.inner.rollbackError = errors.New("ERROR")
err := this.transaction.Rollback()
this.So(err.Error(), should.Equal, "ERROR\nStack Trace:\nSTACK")
this.So(this.inner.rollbackCalls, should.Equal, 1)
}
func (this *StackTraceTransactionFixture) TestExecute() {
this.inner.executeError = errors.New("ERROR")
this.inner.executeResult = 42
rows, err := this.transaction.Execute(context.Background(), "STATEMENT", 1, 2, 3)
this.So(rows, should.Equal, 42)
this.So(err.Error(), should.Equal, "ERROR\nStack Trace:\nSTACK")
this.So(this.inner.executeCalls, should.Equal, 1)
this.So(this.inner.executeStatement, should.Equal, "STATEMENT")
this.So(this.inner.executeParameters, should.Resemble, []interface{}{1, 2, 3})
}
func (this *StackTraceTransactionFixture) TestSelect() {
expectedResult := new(FakeSelectResult)
this.inner.selectResult = expectedResult
this.inner.selectError = errors.New("ERROR")
result, err := this.transaction.Select(context.Background(), "STATEMENT", 1, 2, 3)
this.So(result, should.Equal, expectedResult)
this.So(err.Error(), should.Equal, "ERROR\nStack Trace:\nSTACK")
this.So(this.inner.selectCalls, should.Equal, 1)
this.So(this.inner.selectStatement, should.Equal, "STATEMENT")
this.So(this.inner.selectParameters, should.Resemble, []interface{}{1, 2, 3})
}