1
0
mirror of https://github.com/zhashkevych/go-sqlxmock.git synced 2025-06-12 21:47:29 +02:00

allow to expect prepared statement to be closed, closes #89

This commit is contained in:
gedi
2017-09-01 10:24:02 +03:00
parent c91a7f4b68
commit 9d03611ad1
5 changed files with 57 additions and 8 deletions

View File

@ -154,6 +154,13 @@ func (c *sqlmock) ExpectationsWereMet() error {
if !e.fulfilled() {
return fmt.Errorf("there is a remaining expectation which was not matched: %s", e)
}
// for expected prepared statement check whether it was closed if expected
if prep, ok := e.(*ExpectedPrepare); ok {
if prep.mustBeClosed && !prep.wasClosed {
return fmt.Errorf("expected prepared statement to be closed, but it was not: %s", prep)
}
}
}
return nil
}
@ -302,7 +309,7 @@ func (c *sqlmock) Prepare(query string) (driver.Stmt, error) {
}
time.Sleep(ex.delay)
return &statement{c, query, ex.closeErr}, nil
return &statement{c, ex, query}, nil
}
func (c *sqlmock) prepare(query string) (*ExpectedPrepare, error) {