Skip to content

Commit

Permalink
Pass predestroy state to CheckDestroy
Browse files Browse the repository at this point in the history
  • Loading branch information
enk21 authored and paddycarver committed Sep 28, 2020
1 parent 35d7fcb commit fd0bfde
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 @@ -15,7 +15,7 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
)

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

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

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 @@ -63,7 +54,7 @@ func runNewTest(t testing.T, c TestCase, helper *tftest.Helper) {
}

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 fd0bfde

Please sign in to comment.