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

Pass pre-destroy state to CheckDestroy as expected by the documentation #591

Merged
merged 1 commit into from
Sep 28, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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