You've already forked go-sqlmock
mirror of
https://github.com/DATA-DOG/go-sqlmock.git
synced 2025-06-23 00:17:47 +02:00
allow unordered expectation matching, support for goroutines
* 1778939 take care of locks for goroutine based matching
This commit is contained in:
@ -4,6 +4,7 @@ import (
|
||||
"database/sql/driver"
|
||||
"reflect"
|
||||
"regexp"
|
||||
"sync"
|
||||
)
|
||||
|
||||
// Argument interface allows to match
|
||||
@ -16,11 +17,14 @@ type Argument interface {
|
||||
// an expectation interface
|
||||
type expectation interface {
|
||||
fulfilled() bool
|
||||
Lock()
|
||||
Unlock()
|
||||
}
|
||||
|
||||
// common expectation struct
|
||||
// satisfies the expectation interface
|
||||
type commonExpectation struct {
|
||||
sync.Mutex
|
||||
triggered bool
|
||||
err error
|
||||
}
|
||||
@ -184,6 +188,19 @@ type queryBasedExpectation struct {
|
||||
args []driver.Value
|
||||
}
|
||||
|
||||
func (e *queryBasedExpectation) attemptMatch(sql string, args []driver.Value) (ret bool) {
|
||||
if !e.queryMatches(sql) {
|
||||
return
|
||||
}
|
||||
|
||||
defer recover() // ignore panic since we attempt a match
|
||||
|
||||
if e.argsMatches(args) {
|
||||
return true
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (e *queryBasedExpectation) queryMatches(sql string) bool {
|
||||
return e.sqlRegex.MatchString(sql)
|
||||
}
|
||||
|
Reference in New Issue
Block a user