Identify the source of package-level leaks
masterWhen using goleak.VerifyTestMain, leaks are only reported once after all tests have finished, making it difficult to identify the specific failing test. You can use the following bash script to run each test individually and identify which one causes the leak:
- Compile the tests into a binary.
- Iterate through all tests (including Examples) and run them one by one using the binary, printing a
.for success and the test name for failure.
# Create a test binary which will be used to run each test individually
$ go test -c -o tests
# Run each test individually, printing "." for successful tests, or the test name
# for failing tests.
$ for test in $(go test -list . | grep -E "^(Test|Example)"); do ./tests -test.run "^$test$" &>/dev/null && echo -n "." || echo -e "\n$test failed"; done