We break down how Go tests “leak” state and why cleanup is mandatory: what
t.Cleanup does,
when exactly it runs (including subtests), why the call order is LIFO,
how it differs from defer, and how to apply the pattern
“changed state → immediately registered rollback” for global settings, temporary directories, and resources.
At the end: common mistakes and how to avoid them.