mardi 7 août 2018

go tests: clean up after panic

Suppose that I set up a Docker container with a DB for my tests, and I do that in testing.TestMain because I want this to be done once and globally. I write a defer statement in this testing.Main() that does the clean up (namely, removes the DB container).

Now, suppose that something goes wrong and my tests panic. This issue tells me that I can not write custom recover code to ensure that the container is removed. This is true: testing.M.Run() does its own recover() call, and it looks like there's no way to override its behaviour.

The question is: what should I do to make sure that my clean up code is executed no matter what?

Aucun commentaire:

Enregistrer un commentaire