Escape query string and assert err == nil

This commit is contained in:
Ian Tan 2017-11-18 19:24:45 +08:00
parent ae219db84b
commit 6a1b81b18b
2 changed files with 6 additions and 4 deletions

View File

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

View File

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