mardi 11 juillet 2017

How to test Go code which uses databases(mysql)?

I have a gRPC service using MySQL and need to clear records after every test case. I try to wrap every test case with a transaction. It works if there's no transaction in my rpc code but fails if there are. And there'll be errors like:

can't start transaction
...
sql: Transaction has already been committed or rolled back

Then I try to use truncate to clear the records but some of the test cases fails randomly.

What's a proper way to test the code using DB(MySQL)? (I don't like mock like go-sqlmock)

Aucun commentaire:

Enregistrer un commentaire