1
0
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:
gedi
2015-08-26 14:28:01 +03:00
parent 5a740a6373
commit 566ca54083
4 changed files with 276 additions and 103 deletions

View File

@ -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)
}