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

Replace PreConfig Disappears Testing #13820

Closed
3 of 8 tasks
bflad opened this issue Jun 18, 2020 · 2 comments · Fixed by #16305
Closed
3 of 8 tasks

Replace PreConfig Disappears Testing #13820

bflad opened this issue Jun 18, 2020 · 2 comments · Fixed by #16305
Assignees
Labels
technical-debt Addresses areas of the codebase that need refactoring or redesign. tests PRs: expanded test coverage. Issues: expanded coverage, enhancements to test infrastructure.
Milestone

Comments

@bflad
Copy link
Contributor

bflad commented Jun 18, 2020

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue 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 issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

Description

Certain resource acceptance testing is using an older style for testing out-of-band resource deletions via PreConfig, e.g.

func TestAccAWSGlueCatalogDatabase_recreates(t *testing.T) {
	resourceName := "aws_glue_catalog_database.test"
	rName := acctest.RandomWithPrefix("tf-acc-test")

	resource.ParallelTest(t, resource.TestCase{
		PreCheck:     func() { testAccPreCheck(t) },
		Providers:    testAccProviders,
		CheckDestroy: testAccCheckGlueDatabaseDestroy,
		Steps: []resource.TestStep{
			{
				Config: testAccGlueCatalogDatabase_basic(rName),
				Check: resource.ComposeTestCheckFunc(
					testAccCheckGlueCatalogDatabaseExists(resourceName),
				),
			},
			{
				// Simulate deleting the database outside Terraform
				PreConfig: func() {
					conn := testAccProvider.Meta().(*AWSClient).glueconn
					input := &glue.DeleteDatabaseInput{
						Name: aws.String(rName),
					}
					_, err := conn.DeleteDatabase(input)
					if err != nil {
						t.Fatalf("error deleting Glue Catalog Database: %s", err)
					}
				},
				Config:             testAccGlueCatalogDatabase_basic(rName),
				ExpectNonEmptyPlan: true,
				PlanOnly:           true,
			},
		},
	})
}

This can be replaced with the easier and more consistent testAccCheckResourceDisappears() function. Example in the Contributing Guide:

func TestAccAwsExampleThing_disappears(t *testing.T) {
  rName := acctest.RandomWithPrefix("tf-acc-test")
  resourceName := "aws_example_thing.test"

  resource.ParallelTest(t, resource.TestCase{
    PreCheck:     func() { testAccPreCheck(t) },
    Providers:    testAccProviders,
    CheckDestroy: testAccCheckAwsExampleThingDestroy,
    Steps: []resource.TestStep{
      {
        Config: testAccAwsExampleThingConfigName(rName),
        Check: resource.ComposeTestCheckFunc(
          testAccCheckAwsExampleThingExists(resourceName, &job),
          testAccCheckResourceDisappears(testAccProvider, resourceAwsExampleThing(), resourceName),
        ),
        ExpectNonEmptyPlan: true,
      },
    },
  })
}

Affected Resource(s)

  • aws_app_cookie_stickiness_policy
  • aws_ebs_snapshot
  • aws_ecs_task_definition
  • aws_glue_catalog_database
  • aws_glue_catalog_table
  • aws_glue_crawler
  • aws_lb_cookie_stickiness_policy
  • aws_ssm_association

NOTE: Ignore these (we may need a different setup for this in-deletion state testing):

  • TestAccAWSDBInstance_IsAlreadyBeingDeleted
  • TestAccAWSRDSClusterInstance_isAlreadyBeingDeleted

References

@bflad bflad added tests PRs: expanded test coverage. Issues: expanded coverage, enhancements to test infrastructure. service/glue Issues and PRs that pertain to the glue service. technical-debt Addresses areas of the codebase that need refactoring or redesign. labels Jun 18, 2020
@DrFaust92 DrFaust92 removed the service/glue Issues and PRs that pertain to the glue service. label Oct 30, 2020
bflad added a commit that referenced this issue Nov 19, 2020
…tAccCheckResourceDisappears

Reference: #13820

Output from acceptance testing:

```
--- PASS: TestAccAWSAppCookieStickinessPolicy_disappears_ELB (16.05s)
--- PASS: TestAccAWSAppCookieStickinessPolicy_disappears (18.31s)

--- PASS: TestAccAWSEcsTaskDefinition_disappears (15.18s)

--- PASS: TestAccAWSGlueCatalogTable_disappears (10.65s)

--- PASS: TestAccAWSLBCookieStickinessPolicy_disappears_ELB (18.22s)
--- PASS: TestAccAWSLBCookieStickinessPolicy_disappears (21.69s)

--- PASS: TestAccAWSSSMAssociation_disappears (85.35s)
```
bflad added a commit that referenced this issue Dec 3, 2020
…tAccCheckResourceDisappears (#16305)

* tests/provider: Migrate remaining PreConfig disappears testing to testAccCheckResourceDisappears

Reference: #13820

Output from acceptance testing:

```
--- PASS: TestAccAWSAppCookieStickinessPolicy_disappears_ELB (16.05s)
--- PASS: TestAccAWSAppCookieStickinessPolicy_disappears (18.31s)

--- PASS: TestAccAWSEcsTaskDefinition_disappears (15.18s)

--- PASS: TestAccAWSGlueCatalogTable_disappears (10.65s)

--- PASS: TestAccAWSLBCookieStickinessPolicy_disappears_ELB (18.22s)
--- PASS: TestAccAWSLBCookieStickinessPolicy_disappears (21.69s)

--- PASS: TestAccAWSSSMAssociation_disappears (85.35s)
```

* tests/resource/aws_lb_cookie_stickiness_policy: Remove now unused configuration

Previously:

```
aws/resource_aws_lb_cookie_stickiness_policy_test.go:191:6: `testAccLBCookieStickinessPolicyConfigDestroy` is unused (deadcode)
func testAccLBCookieStickinessPolicyConfigDestroy(rName string) string {
     ^
```
@bflad bflad added this to the v3.20.0 milestone Dec 3, 2020
@bflad bflad self-assigned this Dec 3, 2020
@ghost
Copy link

ghost commented Dec 3, 2020

This has been released in version 3.20.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!

@ghost
Copy link

ghost commented Jan 2, 2021

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 as resolved and limited conversation to collaborators Jan 2, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
technical-debt Addresses areas of the codebase that need refactoring or redesign. tests PRs: expanded test coverage. Issues: expanded coverage, enhancements to test infrastructure.
Projects
None yet
2 participants