hashicorp / hashicorp/terraform-plugin-testing

Cancelable resource.Test() / UnitTest()

Open
#66 1 comment 1 reaction 0 assignees View on GitHub
enhancement
Dominant language
Go
Stars
68
Forks
22
Avg merge
2d 12h
Merged PRs (30d)
1

Description

### 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

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.