go-sqlmock icon indicating copy to clipboard operation
go-sqlmock copied to clipboard

Added SqlMock type to allow for options to be sent to function that creates the sqlmock

Open Woody1193 opened this issue 2 years ago • 0 comments
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.

Woody1193 avatar Dec 22 '22 07:12 Woody1193