-
-
Notifications
You must be signed in to change notification settings - Fork 406
Closed
Labels
Description
When using sqlmock I find myself often in situations where I want to create a sqlmock.Rows with multiple rows in a just single line of code. In larger tests my test data is often organized like this:
var (
testColumns []string
testValues [][]driver.Values
)In the actual test the data is usually used like this:
testRows := sqlmock.NewRows(testColumns)
for _, values := range testValues {
testRows.AddRow(values...)
}
mock.ExpectQuery(query).
WillReturnRows(testRows)Although this works perfectly fine, it is still a bit of an overhead that decreases readability in larger tests where multiple queries are mocked. I therefore suggest to add a method AddRows(rows ...[]driver.Value) to the sqlmock.Rows type. The method could be use like this:
mock.ExpectQuery(query).
WillReturnRows(sqlmock.NewRows(testColumns).AddRows(testValues...))If this feature was accepted, I'd be more than happy to make a PR that adds this little helper method.
krnkl