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

tests/provider: Introduce shared disappears TestCheckFunc, refactor Backup testing to implement and verify #12864

Merged
merged 2 commits into from
Apr 29, 2020

Conversation

bflad
Copy link
Contributor

@bflad bflad commented Apr 16, 2020

Community Note

  • Please vote on this pull request by adding a 👍 reaction to the original pull request comment to help the community and maintainers prioritize this request
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for pull request followers and do not help prioritize the request

Release note for CHANGELOG:

NONE

A common problem in Terraform Providers is the need to verify that a Terraform Resource will successfully remove itself from the Terraform state when externally deleted. In an effort to test this functionality, the Terraform AWS Provider has implemented testing, commonly named _disappears in each resource's acceptance testing, where each test includes a TestCheckFunc that manually reimplements the deletion functionality of the resource.

This change proposes the introduction of a shared TestCheckFunc that can prevent the necessity of manually reimplementing the resource deletion code in a TestCheckFunc for each resource. If acceptable, a GitHub issue will be created outlining a refactoring and documentation proposal for the provider codebase.

It is worth noting that in the future, the Terraform Plugin SDK's acceptance testing framework could introduce native functionality for this type of common testing, but this shared TestCheckFunc is an effort to reduce a current development pain point.

Output from acceptance testing:

--- PASS: TestAccAwsBackupVault_disappears (13.75s)
--- PASS: TestAccAwsBackupPlan_disappears (18.15s)
--- PASS: TestAccAwsBackupSelection_disappears (24.02s)

…ackup testing to implement and verify

A common problem in Terraform Providers is the need to verify that a Terraform Resource will successfully remove itself from the Terraform state when externally deleted. In an effort to test this functionality, the Terraform AWS Provider has implemented testing, commonly named `_disappears` in each resource's acceptance testing, where each test includes a `TestCheckFunc` that manually reimplements the deletion functionality of the resource.

This change proposes the introduction of a shared `TestCheckFunc` that can prevent the necessity of manually reimplementing the resource deletion code in a `TestCheckFunc` for each resource. If acceptable, a GitHub issue will be created outlining a refactoring and documentation proposal for the provider codebase.

It is worth noting that in the future, the Terraform Plugin SDK's acceptance testing framework could introduce native functionality for this type of common testing, but this shared `TestCheckFunc` is an effort to reduce a current development pain point.

Output from acceptance testing:

```
--- PASS: TestAccAwsBackupVault_disappears (13.75s)
--- PASS: TestAccAwsBackupPlan_disappears (18.15s)
--- PASS: TestAccAwsBackupSelection_disappears (24.02s)
```
@bflad bflad added the tests PRs: expanded test coverage. Issues: expanded coverage, enhancements to test infrastructure. label Apr 16, 2020
@bflad bflad requested a review from a team April 16, 2020 18:32
@ghost ghost added needs-triage Waiting for first response or review from a maintainer. size/M Managed by automation to categorize the size of a PR. service/backup Issues and PRs that pertain to the backup service. labels Apr 16, 2020
@bflad bflad removed the needs-triage Waiting for first response or review from a maintainer. label Apr 16, 2020
}

if resourceState.Primary.ID == "" {
return fmt.Errorf("resource ID missing:: %s", resourceName)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra : here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch 😄

Copy link
Contributor

@gdavison gdavison left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🚀

--- PASS: TestProvider_impl (0.02s)
--- PASS: TestProvider (0.85s)
--- PASS: TestAccAWSProvider_Region_AwsChina (10.24s)
--- PASS: TestAccAWSProvider_Region_AwsCommercial (11.48s)
--- PASS: TestAccAWSProvider_Region_AwsGovCloudUs (11.29s)
--- PASS: TestAccAWSProvider_IgnoreTags_Keys_One (12.59s)
--- PASS: TestAccAWSProvider_IgnoreTags_EmptyConfigurationBlock (12.77s)
--- PASS: TestAccAWSProvider_IgnoreTags_KeyPrefixes_None (13.07s)
--- PASS: TestAccAWSProvider_IgnoreTags_KeyPrefixes_One (13.34s)
--- PASS: TestAccAWSProvider_IgnoreTags_Keys_None (13.46s)
--- PASS: TestAccAWSProvider_IgnoreTags_Keys_Multiple (14.05s)
--- PASS: TestAccAWSProvider_IgnoreTags_KeyPrefixes_Multiple (13.93s)
--- PASS: TestAccAWSProvider_Endpoints_Deprecated (15.50s)
--- PASS: TestAccAWSProvider_Endpoints (15.77s)
--- PASS: TestAccAwsBackupPlan_basic (17.67s)
--- PASS: TestAccAwsBackupPlan_Rule_CopyAction_Multiple (17.98s)
--- PASS: TestAccAwsBackupPlan_disappears (11.93s)
--- PASS: TestAccAwsBackupVault_disappears (9.28s)
--- PASS: TestAccAwsBackupPlan_Rule_CopyAction_CrossRegion (23.49s)
--- PASS: TestAccAwsBackupVault_basic (12.03s)
--- PASS: TestAccAwsBackupSelection_basic (15.07s)
--- PASS: TestAccAwsBackupSelection_withTags (14.30s)
--- PASS: TestAccAwsBackupSelection_disappears (15.83s)
--- PASS: TestAccAwsBackupPlan_withRules (28.99s)
--- PASS: TestAccAwsBackupPlan_withTags (29.42s)
--- PASS: TestAccAwsBackupPlan_withRecoveryPointTags (30.27s)
--- PASS: TestAccAwsBackupPlan_Rule_CopyAction_SameRegion (30.89s)
--- PASS: TestAccAwsBackupSelection_updateTag (19.15s)
--- PASS: TestAccAwsBackupPlan_withLifecycle (35.36s)
--- PASS: TestAccAwsBackupSelection_withResources (22.94s)
--- PASS: TestAccAwsBackupVault_withTags (21.83s)
--- PASS: TestAccAwsBackupVault_withKmsKey (30.63s)

@bflad bflad added this to the v2.60.0 milestone Apr 29, 2020
@bflad bflad merged commit dcb4597 into master Apr 29, 2020
@bflad bflad deleted the t-testAccCheckResourceDisappears branch April 29, 2020 21:05
@ghost
Copy link

ghost commented May 1, 2020

This has been released in version 2.60.0 of the Terraform AWS provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.

For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template for triage. Thanks!

adamdecaf pushed a commit to adamdecaf/terraform-provider-aws that referenced this pull request May 28, 2020
…ackup testing to implement and verify (hashicorp#12864)

* tests/provider: Introduce shared disappears TestCheckFunc, refactor Backup testing to implement and verify

A common problem in Terraform Providers is the need to verify that a Terraform Resource will successfully remove itself from the Terraform state when externally deleted. In an effort to test this functionality, the Terraform AWS Provider has implemented testing, commonly named `_disappears` in each resource's acceptance testing, where each test includes a `TestCheckFunc` that manually reimplements the deletion functionality of the resource.

This change proposes the introduction of a shared `TestCheckFunc` that can prevent the necessity of manually reimplementing the resource deletion code in a `TestCheckFunc` for each resource. If acceptable, a GitHub issue will be created outlining a refactoring and documentation proposal for the provider codebase.

It is worth noting that in the future, the Terraform Plugin SDK's acceptance testing framework could introduce native functionality for this type of common testing, but this shared `TestCheckFunc` is an effort to reduce a current development pain point.

Output from acceptance testing:

```
--- PASS: TestAccAwsBackupVault_disappears (13.75s)
--- PASS: TestAccAwsBackupPlan_disappears (18.15s)
--- PASS: TestAccAwsBackupSelection_disappears (24.02s)
```

* tests/provider: Remove extra colon in testAccCheckResourceDisappears error message

Reference: hashicorp#12864 (review)
@ghost
Copy link

ghost commented May 30, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thanks!

@ghost ghost locked and limited conversation to collaborators May 30, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
service/backup Issues and PRs that pertain to the backup service. size/M Managed by automation to categorize the size of a PR. tests PRs: expanded test coverage. Issues: expanded coverage, enhancements to test infrastructure.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants