I'm writing some rather complex unit tests in Go and I have something like:
err = os.Mkdir(tempDir, 0755)
assert.NoError(t, err, "error creating temporary directory")
defer func() {
log.Info("cleaning up temporary directory '%s'..", tempDir)
err = os.RemoveAll(tempDir)
assert.NoError(t, err, "error removing temporary directory")
}()
The problem is that this won't work and temporary dir won't be deleted if I hit Ctrl+C to interrupt the test for whatever the reason (it generates temporary data and it takes a lot of time, it can be beneficial to just SIGINT the process if I realize something is wrong).
Any clean way to do this?