mirror of
https://github.com/DATA-DOG/go-sqlmock.git
synced 2025-03-25 21:18:08 +02:00
closes #50
This commit is contained in:
parent
05f39e9110
commit
d4cd2ca2ad
@ -6,6 +6,7 @@ go:
|
||||
- 1.4
|
||||
- 1.5
|
||||
- 1.6
|
||||
- 1.7
|
||||
- tip
|
||||
|
||||
script: go test -race
|
||||
|
@ -188,6 +188,9 @@ It only asserts that argument is of `time.Time` type.
|
||||
|
||||
## Changes
|
||||
|
||||
- **2016-11-02** - `db.Prepare()` was not validating expected prepare SQL
|
||||
query. It should still be validated even if Exec or Query is not
|
||||
executed on that prepared statement.
|
||||
- **2016-02-23** - added **sqlmock.AnyArg()** function to provide any kind
|
||||
of argument matcher.
|
||||
- **2016-02-23** - convert expected arguments to driver.Value as natural
|
||||
|
@ -291,9 +291,12 @@ func (c *sqlmock) Prepare(query string) (driver.Stmt, error) {
|
||||
}
|
||||
return nil, fmt.Errorf(msg, query)
|
||||
}
|
||||
defer expected.Unlock()
|
||||
if !expected.sqlRegex.MatchString(query) {
|
||||
return nil, fmt.Errorf("query '%s', does not match regex [%s]", query, expected.sqlRegex.String())
|
||||
}
|
||||
|
||||
expected.triggered = true
|
||||
expected.Unlock()
|
||||
return &statement{c, query, expected.closeErr}, expected.err
|
||||
}
|
||||
|
||||
|
@ -753,3 +753,23 @@ func TestEmptyRowSet(t *testing.T) {
|
||||
t.Fatalf("all expectations should be met: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
// Based on issue #50
|
||||
func TestPrepareExpectationNotFulfilled(t *testing.T) {
|
||||
t.Parallel()
|
||||
db, mock, err := New()
|
||||
if err != nil {
|
||||
t.Errorf("an error '%s' was not expected when opening a stub database connection", err)
|
||||
}
|
||||
defer db.Close()
|
||||
|
||||
mock.ExpectPrepare("^BADSELECT$")
|
||||
|
||||
if _, err := db.Prepare("SELECT"); err == nil {
|
||||
t.Fatal("prepare should not match expected query string")
|
||||
}
|
||||
|
||||
if err := mock.ExpectationsWereMet(); err == nil {
|
||||
t.Errorf("was expecting an error, since prepared statement query does not match, but there was none")
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user