vladopajic / go-test-coverage

go-test-coverage is tool and github action which reports issues when test coverage is below set threshold
GNU General Public License v3.0
78 stars 9 forks source link

feat: add option to ignore early returns when error handling #62

Closed vladopajic closed 5 months ago

vladopajic commented 7 months ago

in Go source code, there are many occurrences of a pattern where the code early returns after executing a function that returns a non-nil error, for example:

result, err := foo()
if err != nil {
    return ...
}

these cases can sometimes be non-trivial to fully cover with unit tests because it could be challenging to make the function foo return an error. it is definitely possible to cover this case, but it would require developers to write mocks, which can sometimes take a lot of time and may not be the primary focus of development.

cases like these could be annoying for developers because they can constantly break coverage targets set by developers.

in order to aid developers in these cases, a new configuration option could be added to the go-test-coverage tool, which will omit code with this pattern from coverage statistics.

implementation details: