Escape query string and assert err == nil
This commit is contained in:
parent
ae219db84b
commit
6a1b81b18b
@ -4,6 +4,7 @@ import (
|
||||
"database/sql"
|
||||
"errors"
|
||||
"fmt"
|
||||
"regexp"
|
||||
)
|
||||
|
||||
type Recorder struct {
|
||||
@ -116,8 +117,8 @@ func (h *Expecter) AssertExpectations() error {
|
||||
|
||||
// First triggers a Query
|
||||
func (h *Expecter) First(out interface{}, where ...interface{}) ExpectedQuery {
|
||||
h.gorm.First(out, where)
|
||||
return h.adapter.ExpectQuery(h.recorder.stmt)
|
||||
h.gorm.First(out)
|
||||
return h.adapter.ExpectQuery(regexp.QuoteMeta(h.recorder.stmt))
|
||||
}
|
||||
|
||||
// Find triggers a Query
|
||||
|
@ -39,8 +39,9 @@ func TestQuery(t *testing.T) {
|
||||
}
|
||||
|
||||
expect.First(&User{})
|
||||
|
||||
db.First(&User{})
|
||||
|
||||
expect.AssertExpectations()
|
||||
if err := expect.AssertExpectations(); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user