stackeval: testEvaluator arranges for its result to be cleaned up

Some operations against an "evaluator" (type Main) register cleanup
actions that need to be run once the evaluation has completed. To avoid
leaking resources while we're running tests we'll arrange for any test
that uses the "testEvaluator" helper to automatically run the cleanup
actions on the returned evaluator once the test is complete.

At the time of this commit the only possible cleanup action is terminating
any provider pluginc client processes that might be running, and none of
our tests are actually doing that so this doesn't really change anything,
but it's here to avoid problems if we add additional cleanup actions in
future, or if any tests start actually using child plugin processes.
pull/34738/head
Martin Atkins 3 years ago
parent d7461ce202
commit 94ca9bc613

@ -109,11 +109,15 @@ func testEvaluator(t *testing.T, opts testEvaluatorOpts) *Main {
}
}
return NewForInspecting(opts.Config, opts.State, InspectOpts{
main := NewForInspecting(opts.Config, opts.State, InspectOpts{
InputVariableValues: inputVals,
ProviderFactories: opts.ProviderFactories,
TestOnlyGlobals: opts.TestOnlyGlobals,
})
t.Cleanup(func() {
main.DoCleanup(context.Background())
})
return main
}
type testEvaluatorOpts struct {

Loading…
Cancel
Save