1
0
mirror of https://github.com/DATA-DOG/go-sqlmock.git synced 2024-11-24 08:32:36 +02:00
go-sqlmock/transaction.go
2014-02-08 17:53:15 +02:00

38 lines
824 B
Go

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
}