Add method to assert all expectations
This commit is contained in:
parent
475ba3db3e
commit
ae219db84b
13
expecter.go
13
expecter.go
@ -16,15 +16,6 @@ func (r *Recorder) Print(args ...interface{}) {
|
|||||||
if v, ok := msgs[3].(string); ok {
|
if v, ok := msgs[3].(string); ok {
|
||||||
r.stmt = v
|
r.stmt = v
|
||||||
}
|
}
|
||||||
// for i, msg := range msgs {
|
|
||||||
// switch v := msg.(type) {
|
|
||||||
// case string:
|
|
||||||
// case []byte:
|
|
||||||
// r.buf.Read([]byte(v))
|
|
||||||
// default:
|
|
||||||
// return
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -119,6 +110,10 @@ func NewExpecter(fn AdapterFactory, dialect string, args ...interface{}) (*DB, *
|
|||||||
|
|
||||||
/* PUBLIC METHODS */
|
/* PUBLIC METHODS */
|
||||||
|
|
||||||
|
func (h *Expecter) AssertExpectations() error {
|
||||||
|
return h.adapter.AssertExpectations()
|
||||||
|
}
|
||||||
|
|
||||||
// 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, where)
|
||||||
|
@ -26,6 +26,7 @@ func init() {
|
|||||||
type Adapter interface {
|
type Adapter interface {
|
||||||
ExpectQuery(stmt string) ExpectedQuery
|
ExpectQuery(stmt string) ExpectedQuery
|
||||||
ExpectExec(stmt string) ExpectedExec
|
ExpectExec(stmt string) ExpectedExec
|
||||||
|
AssertExpectations() error
|
||||||
}
|
}
|
||||||
|
|
||||||
// SqlmockAdapter implemenets the Adapter interface using go-sqlmock
|
// SqlmockAdapter implemenets the Adapter interface using go-sqlmock
|
||||||
@ -56,3 +57,7 @@ func (a *SqlmockAdapter) ExpectExec(stmt string) ExpectedExec {
|
|||||||
|
|
||||||
return &SqlmockExec{exec: e}
|
return &SqlmockExec{exec: e}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a *SqlmockAdapter) AssertExpectations() error {
|
||||||
|
return a.mocker.ExpectationsWereMet()
|
||||||
|
}
|
||||||
|
@ -38,6 +38,9 @@ func TestQuery(t *testing.T) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
expect.First(&User{}).Returns(&User{})
|
expect.First(&User{})
|
||||||
|
|
||||||
db.First(&User{})
|
db.First(&User{})
|
||||||
|
|
||||||
|
expect.AssertExpectations()
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user