Skip to content

lint: Add linter for testhelper.Run

Will Chandler requested to merge wc/testhelper-lint into master

Our tests will check for leaked goroutines, but only if testhelper.Run is called in the package being tested. A recent production outage was caused by leaked goroutines which our tests did not catch as the package did not use the required helper.

Create a custom linter to validate that each package that contains tests also contains a TestMain function that calls testhelper.Run.

One limitation is that the _test package is scanned in a separate pass from the primary package, preventing us from validating that either the primary package or its _test package has defined TestMain. By default each analysis pass has no knowledge of what other packages have or will be scanned.

To avoid accidentally requiring TestMain to be defined twice, we skip linting any package with a name ending with _test. However, this potentially leads to coverage gaps if all tests are in the _test package. We would pass the primary package as it has no tests, and then skip checking the test package based on its name, missing that it did not execute TestMain.

A future iteration of this linter should use Facts to pass information on package state between passes, but this first implementation gets us 90% of the value.

Closes #5522 (closed)

Edited by Will Chandler

Merge request reports