Remove asserter interface
This commit is contained in:
parent
27ec78afaa
commit
5505f2ee76
44
expecter_result.go
Normal file
44
expecter_result.go
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
package gorm
|
||||||
|
|
||||||
|
import (
|
||||||
|
"database/sql/driver"
|
||||||
|
|
||||||
|
sqlmock "gopkg.in/DATA-DOG/go-sqlmock.v1"
|
||||||
|
)
|
||||||
|
|
||||||
|
type ExpectedQuery interface {
|
||||||
|
Returns(model interface{}) ExpectedQuery
|
||||||
|
}
|
||||||
|
|
||||||
|
type ExpectedExec interface {
|
||||||
|
Returns(result driver.Result) ExpectedExec
|
||||||
|
}
|
||||||
|
|
||||||
|
// SqlmockQuery implements Query for asserter go-sqlmock
|
||||||
|
type SqlmockQuery struct {
|
||||||
|
query *sqlmock.ExpectedQuery
|
||||||
|
}
|
||||||
|
|
||||||
|
func (q *SqlmockQuery) getRowsForOutType(out interface{}) *sqlmock.Rows {
|
||||||
|
rows := sqlmock.NewRows([]string{"column1", "column2", "column3"})
|
||||||
|
rows = rows.AddRow("someval1", "someval2", "someval3")
|
||||||
|
|
||||||
|
return rows
|
||||||
|
}
|
||||||
|
|
||||||
|
func (q *SqlmockQuery) Returns(out interface{}) ExpectedQuery {
|
||||||
|
rows := q.getRowsForOutType(out)
|
||||||
|
q.query = q.query.WillReturnRows(rows)
|
||||||
|
|
||||||
|
return q
|
||||||
|
}
|
||||||
|
|
||||||
|
type SqlmockExec struct {
|
||||||
|
exec *sqlmock.ExpectedExec
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e *SqlmockExec) Returns(result driver.Result) ExpectedExec {
|
||||||
|
e.exec = e.exec.WillReturnResult(result)
|
||||||
|
|
||||||
|
return e
|
||||||
|
}
|
@ -1,35 +0,0 @@
|
|||||||
package gorm
|
|
||||||
|
|
||||||
import sqlmock "gopkg.in/DATA-DOG/go-sqlmock.v1"
|
|
||||||
|
|
||||||
type Query interface {
|
|
||||||
Return(model interface{}) Query
|
|
||||||
}
|
|
||||||
|
|
||||||
type Exec interface {
|
|
||||||
Return(args ...interface{}) Exec
|
|
||||||
}
|
|
||||||
|
|
||||||
type Asserter interface {
|
|
||||||
Query(query string) Query
|
|
||||||
// Exec(stmt string) Exec
|
|
||||||
}
|
|
||||||
|
|
||||||
// SqlmockQuery implements Query for asserter go-sqlmock
|
|
||||||
type SqlmockQuery struct {
|
|
||||||
query *sqlmock.ExpectedQuery
|
|
||||||
}
|
|
||||||
|
|
||||||
func (q *SqlmockQuery) getRowsForOutType(out interface{}) *sqlmock.Rows {
|
|
||||||
rows := sqlmock.NewRows([]string{"column1", "column2", "column3"})
|
|
||||||
rows = rows.AddRow("someval1", "someval2", "someval3")
|
|
||||||
|
|
||||||
return rows
|
|
||||||
}
|
|
||||||
|
|
||||||
func (q *SqlmockQuery) Return(out interface{}) Query {
|
|
||||||
rows := q.getRowsForOutType(out)
|
|
||||||
q.query = q.query.WillReturnRows(rows)
|
|
||||||
|
|
||||||
return q
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user