Add documentation to prevent go lint from complaining
This commit is contained in:
		
							parent
							
								
									e9a29091fa
								
							
						
					
					
						commit
						486fb73ee5
					
				@ -11,6 +11,7 @@ type Recorder struct {
 | 
			
		||||
	stmt string
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Stmt represents a sql statement. It can be an Exec or Query
 | 
			
		||||
type Stmt struct {
 | 
			
		||||
	stmtType string
 | 
			
		||||
	sql      string
 | 
			
		||||
@ -64,10 +65,12 @@ type DefaultNoopDB struct{}
 | 
			
		||||
// NoopResult is a noop struct that satisfies sql.Result
 | 
			
		||||
type NoopResult struct{}
 | 
			
		||||
 | 
			
		||||
// LastInsertId is a noop method for satisfying drive.Result
 | 
			
		||||
func (r NoopResult) LastInsertId() (int64, error) {
 | 
			
		||||
	return 1, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// RowsAffected is a noop method for satisfying drive.Result
 | 
			
		||||
func (r NoopResult) RowsAffected() (int64, error) {
 | 
			
		||||
	return 1, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -36,6 +36,8 @@ type SqlmockAdapter struct {
 | 
			
		||||
	mocker sqlmock.Sqlmock
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// NewSqlmockAdapter returns a mock gorm.DB and an Adapter backed by
 | 
			
		||||
// go-sqlmock
 | 
			
		||||
func NewSqlmockAdapter(dialect string, args ...interface{}) (*DB, Adapter, error) {
 | 
			
		||||
	gormDb, err := Open("sqlmock", "mock_gorm_dsn")
 | 
			
		||||
 | 
			
		||||
@ -46,18 +48,25 @@ func NewSqlmockAdapter(dialect string, args ...interface{}) (*DB, Adapter, error
 | 
			
		||||
	return gormDb, &SqlmockAdapter{db: db, mocker: mock}, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// ExpectQuery wraps the underlying mock method for setting a query
 | 
			
		||||
// expectation
 | 
			
		||||
func (a *SqlmockAdapter) ExpectQuery(stmt string) ExpectedQuery {
 | 
			
		||||
	q := a.mocker.ExpectQuery(stmt)
 | 
			
		||||
 | 
			
		||||
	return &SqlmockQuery{query: q}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// ExpectExec wraps the underlying mock method for setting a exec
 | 
			
		||||
// expectation
 | 
			
		||||
func (a *SqlmockAdapter) ExpectExec(stmt string) ExpectedExec {
 | 
			
		||||
	e := a.mocker.ExpectExec(stmt)
 | 
			
		||||
 | 
			
		||||
	return &SqlmockExec{exec: e}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// AssertExpectations asserts that _all_ expectations for a test have been met
 | 
			
		||||
// and returns an error specifying which have not if there are unmet
 | 
			
		||||
// expectations
 | 
			
		||||
func (a *SqlmockAdapter) AssertExpectations() error {
 | 
			
		||||
	return a.mocker.ExpectationsWereMet()
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -8,15 +8,21 @@ import (
 | 
			
		||||
	sqlmock "gopkg.in/DATA-DOG/go-sqlmock.v1"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
// ExpectedQuery represents an expected query that will be executed and can
 | 
			
		||||
// return some rows. It presents a fluent API for chaining calls to other
 | 
			
		||||
// expectations
 | 
			
		||||
type ExpectedQuery interface {
 | 
			
		||||
	Returns(model interface{}) ExpectedQuery
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// ExpectedExec represents an expected exec that will be executed and can
 | 
			
		||||
// return a result. It presents a fluent API for chaining calls to other
 | 
			
		||||
// expectations
 | 
			
		||||
type ExpectedExec interface {
 | 
			
		||||
	Returns(result driver.Result) ExpectedExec
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// SqlmockQuery implements Query for asserter go-sqlmock
 | 
			
		||||
// SqlmockQuery implements Query for go-sqlmock
 | 
			
		||||
type SqlmockQuery struct {
 | 
			
		||||
	query *sqlmock.ExpectedQuery
 | 
			
		||||
}
 | 
			
		||||
@ -89,6 +95,9 @@ func (q *SqlmockQuery) getRowsForOutType(out interface{}) *sqlmock.Rows {
 | 
			
		||||
	return rows
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Returns accepts an out type which should either be a struct or slice. Under
 | 
			
		||||
// the hood, it converts a gorm model struct to sql.Rows that can be passed to
 | 
			
		||||
// the underlying mock db
 | 
			
		||||
func (q *SqlmockQuery) Returns(out interface{}) ExpectedQuery {
 | 
			
		||||
	rows := q.getRowsForOutType(out)
 | 
			
		||||
	q.query = q.query.WillReturnRows(rows)
 | 
			
		||||
@ -96,10 +105,14 @@ func (q *SqlmockQuery) Returns(out interface{}) ExpectedQuery {
 | 
			
		||||
	return q
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// SqlmockExec implements Exec for go-sqlmock
 | 
			
		||||
type SqlmockExec struct {
 | 
			
		||||
	exec *sqlmock.ExpectedExec
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Returns accepts a driver.Result. It is passed directly to the underlying
 | 
			
		||||
// mock db. Useful for checking DAO behaviour in the event that the incorrect
 | 
			
		||||
// number of rows are affected by an Exec
 | 
			
		||||
func (e *SqlmockExec) Returns(result driver.Result) ExpectedExec {
 | 
			
		||||
	e.exec = e.exec.WillReturnResult(result)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user