Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

helper/resource: Support TestStep provider handling #972

Merged
merged 4 commits into from May 31, 2022

Conversation

bflad
Copy link
Member

@bflad bflad commented May 26, 2022

Closes #253
Closes #628
Closes #779

Provider developers can now select whether to configure providers for acceptance testing at the TestCase or TestStep level. Only one level may be used in this current implementation, however it may be possible to allow merged TestCase and TestStep configuration with additional validation logic to ensure a single provider is not specified multiple times across the merge result of all fields.

This change also introduces some upfront TestCase and TestStep configuration validation when calling any of the Test functions, failing the test early if a problem is detected. There are other validations that are possible, however these are considered out of scope.

Reference: #253
Reference: #628
Reference: #779

Provider developers can now select whether to configure providers for acceptance testing at the `TestCase` or `TestStep` level. Only one level may be used in this current implementation, however it may be possible to allow merged `TestCase` and `TestStep` configuration with additional validation logic to ensure a single provider is not specified multiple times across the merge result of all fields.

This change also introduces some upfront `TestCase` and `TestStep` configuration validation when calling any of the `Test` functions, failing the test early if a problem is detected. There are other validations that are possible, however these are considered out of scope.
@bflad bflad added enhancement New feature or request subsystem/tests Issues and feature requests related to the testing framework. labels May 26, 2022
@bflad bflad added this to the v2.17.0 milestone May 26, 2022
@bflad bflad requested a review from a team as a code owner May 26, 2022
bflad added 2 commits May 26, 2022
Previously:

```
func testStepNewImportState(ctx context.Context, t testing.T, c TestCase, helper *plugintest.Helper, wd *plugintest.WorkingDir, step TestStep, cfg string, providers *providerFactories) error {
                                                              ^
helper/resource/plugin.go:163:47: SA5011: possible nil pointer dereference (staticcheck)
	for providerName, factory := range factories.legacy {
	                                             ^
helper/resource/plugin.go:118:5: SA5011(related information): this check suggests that the pointer can be nil (staticcheck)
	if factories == nil {
	   ^
```
@bflad bflad force-pushed the bflad-teststep-providers branch from 89f3e1e to a8e255a Compare May 26, 2022
Copy link
Contributor

@bendbennett bendbennett left a comment

Amazing!

…et and before TestStep providers are changed

Previously:

```
--- FAIL: TestTest_TestStep_ExternalProviders_To_ProviderFactories_StateUpgraders (2.50s)
    /Users/bflad/src/github.com/hashicorp/terraform-plugin-sdk/helper/resource/teststep_providers_test.go:275: Step 2/2 error: exit status 1
        Failed to marshal state to json: schema version 0 for null_resource.test in state does not match version 1 from the provider
    /Users/bflad/src/github.com/hashicorp/terraform-plugin-sdk/helper/resource/testing_new.go:73: Error retrieving state, there may be dangling resources: exit status 1
        Failed to marshal state to json: schema version 0 for null_resource.test in state does not match version 1 from the provider
```
@bflad bflad merged commit 09a236a into main May 31, 2022
5 checks passed
@bflad bflad deleted the bflad-teststep-providers branch May 31, 2022
@github-actions
Copy link

github-actions bot commented Jul 1, 2022

I'm going to lock this pull request because it has been closed for 30 days . This helps our maintainers find and focus on the active contributions.
If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 1, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request subsystem/tests Issues and feature requests related to the testing framework.
Projects
None yet
2 participants