sensu / sensu-plugin-sdk

A framework for creating Sensu plugins
MIT License
7 stars 8 forks source link

exitFunction creates a problem for plugin testing #39

Open jspaleta opened 4 years ago

jspaleta commented 4 years ago

I'm not sure the best way to address this, but here's the problem.

because Execute() eventually calls exitFunction which defaults to os.Exit the main() function pattern as used in the template plugin github projects are very difficult to test using go test What happens is main() will exit the test entirely unless you set exitFunction, but exitFunction isn't exposed as a tunable.

I'm able to work-around this using reflect and unsafe golang packages but that seems like a lot of work to support some basic testing that we need all derived plugins to be doing. Example workaround: https://github.com/sensu/sensu-kafka-handler/blob/master/main_test.go

Straw proposal, extend the interface that exposes Execute, with a setter function for exitFunction.