Skip to content

Commit

Permalink
Pass predestroy state to CheckDestroy
Browse files Browse the repository at this point in the history
Backport #591 to v1-maint.
  • Loading branch information
enk21 authored and paddycarver committed Mar 22, 2021
1 parent 32f0219 commit 9045305
Showing 1 changed file with 3 additions and 12 deletions.
15 changes: 3 additions & 12 deletions helper/resource/testing_new.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
tftest "github.com/hashicorp/terraform-plugin-test/v2"
)

func runPostTestDestroy(t *testing.T, c TestCase, wd *tftest.WorkingDir, factories map[string]terraform.ResourceProviderFactory) error {
func runPostTestDestroy(t *testing.T, c TestCase, wd *tftest.WorkingDir, factories map[string]terraform.ResourceProviderFactory, statePreDestroy *terraform.State) error {
t.Helper()

err := runProviderCommand(t, func() error {
Expand All @@ -26,16 +26,7 @@ func runPostTestDestroy(t *testing.T, c TestCase, wd *tftest.WorkingDir, factori
}

if c.CheckDestroy != nil {
var statePostDestroy *terraform.State
err := runProviderCommand(t, func() error {
statePostDestroy = getState(t, wd)
return nil
}, wd, factories)
if err != nil {
return err
}

if err := c.CheckDestroy(statePostDestroy); err != nil {
if err := c.CheckDestroy(statePreDestroy); err != nil {
return err
}
}
Expand All @@ -62,7 +53,7 @@ func RunNewTest(t *testing.T, c TestCase, providers map[string]terraform.Resourc
}

if !stateIsEmpty(statePreDestroy) {
err := runPostTestDestroy(t, c, wd, c.ProviderFactories)
err := runPostTestDestroy(t, c, wd, c.ProviderFactories, statePreDestroy)
if err != nil {
t.Fatalf("Error running post-test destroy, there may be dangling resources: %s", err.Error())
}
Expand Down

0 comments on commit 9045305

Please sign in to comment.