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