You've already forked go-sqlmock
mirror of
https://github.com/DATA-DOG/go-sqlmock.git
synced 2025-06-19 00:07:38 +02:00
Mikemacd patch 1 (#2)
* Update sqlmock.go Permit prepares to obey MatchExpectationsInOrder flag, allowing prepared statements to be prepared in a different order than they were added to the expectations. * Update sqlmock_test.go Add test case for unordered prepared statements.
This commit is contained in:
committed by
GitHub
parent
18ab7ac1c7
commit
ca83e31de6
22
sqlmock.go
22
sqlmock.go
@ -309,6 +309,9 @@ func (c *sqlmock) prepare(query string) (*ExpectedPrepare, error) {
|
||||
var expected *ExpectedPrepare
|
||||
var fulfilled int
|
||||
var ok bool
|
||||
|
||||
query = stripQuery(query)
|
||||
|
||||
for _, next := range c.expected {
|
||||
next.Lock()
|
||||
if next.fulfilled() {
|
||||
@ -317,17 +320,24 @@ func (c *sqlmock) prepare(query string) (*ExpectedPrepare, error) {
|
||||
continue
|
||||
}
|
||||
|
||||
if expected, ok = next.(*ExpectedPrepare); ok {
|
||||
break
|
||||
}
|
||||
|
||||
next.Unlock()
|
||||
if c.ordered {
|
||||
if expected, ok = next.(*ExpectedPrepare); ok {
|
||||
break
|
||||
}
|
||||
|
||||
next.Unlock()
|
||||
return nil, fmt.Errorf("call to Prepare statement with query '%s', was not expected, next expectation is: %s", query, next)
|
||||
}
|
||||
|
||||
if pr, ok := next.(*ExpectedPrepare); ok {
|
||||
if pr.sqlRegex.MatchString(query) {
|
||||
expected = pr
|
||||
break
|
||||
}
|
||||
}
|
||||
next.Unlock()
|
||||
}
|
||||
|
||||
query = stripQuery(query)
|
||||
if expected == nil {
|
||||
msg := "call to Prepare '%s' query was not expected"
|
||||
if fulfilled == len(c.expected) {
|
||||
|
Reference in New Issue
Block a user