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

helper/resource: Always return the error in testStepNewConfig instead of t.Fatalf() so step numbers are included with error messages #557

Merged
merged 1 commit into from
Aug 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
12 changes: 7 additions & 5 deletions helper/resource/testing_new_config.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package resource

import (
"fmt"

tfjson "github.com/hashicorp/terraform-json"
tftest "github.com/hashicorp/terraform-plugin-test/v2"
testing "github.com/mitchellh/go-testing-interface"
Expand All @@ -24,7 +26,7 @@ func testStepNewConfig(t testing.T, c TestCase, wd *tftest.WorkingDir, step Test
return err
}
if err := testStepTaint(state, step); err != nil {
t.Fatalf("Error when tainting resources: %s", err)
return fmt.Errorf("Error when tainting resources: %s", err)
}
}

Expand Down Expand Up @@ -58,7 +60,7 @@ func testStepNewConfig(t testing.T, c TestCase, wd *tftest.WorkingDir, step Test
if step.Check != nil {
state.IsBinaryDrivenTest = true
if err := step.Check(state); err != nil {
t.Fatal(err)
return err
}
}
}
Expand Down Expand Up @@ -91,7 +93,7 @@ func testStepNewConfig(t testing.T, c TestCase, wd *tftest.WorkingDir, step Test
if err != nil {
return err
}
t.Fatalf("After applying this test step, the plan was not empty.\nstdout:\n\n%s", stdout)
return fmt.Errorf("After applying this test step, the plan was not empty.\nstdout:\n\n%s", stdout)
}

// do a refresh
Expand Down Expand Up @@ -130,7 +132,7 @@ func testStepNewConfig(t testing.T, c TestCase, wd *tftest.WorkingDir, step Test
if err != nil {
return err
}
t.Fatalf("After applying this test step and performing a `terraform refresh`, the plan was not empty.\nstdout\n\n%s", stdout)
return fmt.Errorf("After applying this test step and performing a `terraform refresh`, the plan was not empty.\nstdout\n\n%s", stdout)
}

// ID-ONLY REFRESH
Expand Down Expand Up @@ -164,7 +166,7 @@ func testStepNewConfig(t testing.T, c TestCase, wd *tftest.WorkingDir, step Test
// caught a different bug.
if idRefreshCheck != nil {
if err := testIDRefresh(c, t, wd, step, idRefreshCheck); err != nil {
t.Fatalf(
return fmt.Errorf(
"[ERROR] Test: ID-only test failed: %s", err)
}
}
Expand Down