forked from DATA-DOG/go-sqlmock
-
Notifications
You must be signed in to change notification settings - Fork 0
/
transaction.go
37 lines (31 loc) · 824 Bytes
/
transaction.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
package sqlmock
import (
"fmt"
)
type transaction struct {
conn *conn
}
func (tx *transaction) Commit() error {
e := tx.conn.next()
if e == nil {
return fmt.Errorf("all expectations were already fulfilled, call to commit transaction was not expected")
}
etc, ok := e.(*expectedCommit)
if !ok {
return fmt.Errorf("call to commit transaction, was not expected, next expectation was %v", e)
}
etc.triggered = true
return etc.err
}
func (tx *transaction) Rollback() error {
e := tx.conn.next()
if e == nil {
return fmt.Errorf("all expectations were already fulfilled, call to rollback transaction was not expected")
}
etr, ok := e.(*expectedRollback)
if !ok {
return fmt.Errorf("call to rollback transaction, was not expected, next expectation was %v", e)
}
etr.triggered = true
return etr.err
}