When working with connections to services such as database, it can be difficult to write tests. This is because it's difficult in Go to mock or duck-type things at runtime. Although I recommend using a storage interface when working with databases, it's still useful to mock a database transaction interface inside this interface. The Creating storage interfaces for data portability recipe will cover storage interfaces; this recipe will focus on an interface to wrap database connections and transaction objects.
To show the use of such an interface, we'll rewrite the create and query files from the previous recipe to use our interface. The final output will be the same, but the create and query operations will all be performed in a transaction.
Getting ready
Refer to the Getting ready section in the Using the database/sql package with MySQL recipe.
How to do it...
These steps cover writing...