DATA-DOG / go-sqlmock

Sql mock driver for golang to test database interactions
Other
5.95k stars 404 forks source link

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

Closed Woody1193 closed 1 month ago

Woody1193 commented 1 year ago

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.

diegommm commented 1 month ago

Hi @Woody1193! Thank you very much for your contribution :heart: