There are many ways a function, including a unit test, can end its execution in Go code. Some of these ways include return, os.Exit, runtime.Goexit.
They all interact in different ways with the defer instruction, the testing.Cleanup function, and the actual goroutine execution.
Let's see how to get our code to end its life properly, ensuring defer and Cleanup work as expected even in the face of panics, fatals, and exits.
This session was presented at the DevoxxFR 2023 conference.