go-sqlmock
go-sqlmock copied to clipboard
Ability to clone sqlmock
trafficstars
Hello, I think it would be great to be able to reuse mock instead of creating a new instance for every test case. Something like:
func TestSomething(t *testing.T) {
db, mock, err := sqlmock.New()
if err != nil {
t.Fatal(err)
}
cases := []struct {
description string
input string
expected string
}{
{
description: "abc",
input: "a",
expected: "b",
},
}
for _, c := range cases {
t.Run(c.description, func(t *testing.T) {
mock = mock.Clone()
//...
})
}
}
Will be happy to contribute if you think this is a good idea.
Why not just put the sqlmock.New() in the subtest?