go-sqlmock
go-sqlmock copied to clipboard
Added SqlMock type to allow for options to be sent to function that creates the sqlmock
trafficstars
This PR addresses an issue where the user wants to embed the SqlMock creation code into a function, like so:
func createServiceMock(database string, schema string, opts ...sqlmock.SqlMockOption) (*MyDB, sqlmock.Sqlmock) {
db, mock, err := sqlmock.New(opts...)
Expect(err).ShouldNot(HaveOccurred())
svc := FromConnection(database, schema, db)
return svc, mock
}
With the current implementation of go-sqlmock, this cannot done because the option references a type internal to the go-sqlmock package. By adding an alias for this type, the user can now send such options without exposing the internal sqlmock type.