Skip to content

Commit

Permalink
tests/provider: Support (helper/schema.Resource).DeleteContext in tes…
Browse files Browse the repository at this point in the history
…tAccCheckResourceDisappears

Reference: #15446
  • Loading branch information
bflad committed Oct 2, 2020
1 parent 4ea6c15 commit 8c33ed6
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions aws/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/aws/aws-sdk-go/aws/endpoints"
"github.com/aws/aws-sdk-go/service/ec2"
"github.com/aws/aws-sdk-go/service/organizations"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/structure"
Expand Down Expand Up @@ -750,6 +751,18 @@ func testAccCheckResourceDisappears(provider *schema.Provider, resource *schema.
return fmt.Errorf("resource ID missing: %s", resourceName)
}

if resource.DeleteContext != nil {
diags := resource.DeleteContext(context.Background(), resource.Data(resourceState.Primary), provider.Meta())

for i := range diags {
if diags[i].Severity == diag.Error {
return fmt.Errorf("error deleting resource: %s", diags[i].Summary)
}
}

return nil
}

return resource.Delete(resource.Data(resourceState.Primary), provider.Meta())
}
}
Expand Down

0 comments on commit 8c33ed6

Please sign in to comment.