hashicorp / terraform-plugin-testing

Module for testing Terraform providers
Mozilla Public License 2.0
45 stars 11 forks source link

Cancelable resource.Test() / UnitTest() #66

Open IronSavior opened 4 years ago

IronSavior commented 4 years ago

SDK version

2.0.2

Use-cases

I want to use verifying mocks in my provider unit tests while using the Terraform resource.UnitTest() test driver. The problem I'm facing occurs when my test mock receives an unexpected call and it responds by calling testing.T.FailNow(). Because the call to FailNow() occurs on a different goroutine than the one started by the test, it deadlocks the test suite.

Attempted Solutions

The best I can do has been wrapping the testing.T in a struct to override FailNow() so it prints the name of the failing test and panics. I need a way to signal the test to shut down.

Proposal

Provide a means to signal a running resource.Test() to shut down. For example, if I could pass in a cancelable context.Context, then I could override FailNow() so it triggers a cancellation that propagates into the test driver before invoking the real FailNow().

References

https://github.com/golang/go/issues/15758 https://github.com/spacemeshos/go-spacemesh/issues/2151 https://github.com/golang/mock/issues/346

bflad commented 1 year ago

Hi folks 👋

With the introduction of the terraform-plugin-testing module (migration guide), we are transferring feature requests relating to the helper/resource "testing framework" in the terraform-plugin-sdk repository over to the new terraform-plugin-testing repository.

Thanks again for this feature request.