Description
I like being able to run the tests of a project with simply go test ./...
, without requiring any local setup before that (other than a Go toolchain of the appropriate version being available). If one uses envtest
to mock a Kubernetes cluster, one is expected to run some version of setup-envtest
, to ensure the appropriate binaries are available; typically either like this
source <(setup-envtest use <version> -p env)
go test ./...
or e.g.
KUBEBUILDER_ASSETS=$(setup-envtest use <version> -p path) go test./...
Other than setup-envtest
being written with purely this use case in mind, there's no technical reason we couldn't allow triggering this from within the test harness, rather than outside of it.
Here's a proof-of-concept implementation that runs the relevant parts of setup-envtest
triggered from within the test instead, allowing
go test ./...
even for tests that use envtest.
The main reason it's not very straightforward to write this code, is that the error handling in setup-envtest
is based on panic-and-recover, rather than passing error values. But it also feels a bit odd to go into the internals of the tool, rather than the tool being built to support the use case in the first place.
If I send a PR to make this a supported feature and use case for setup-envtest, what are the chances of that being accepted? :)