Skip to content

Commit d2f1676

Browse files
bfladPaddy
authored andcommitted
helper/resource: Always call return the error in testStepNewConfig instead of t.Fatalf() so step numbers are included with error messages
Reference: hashicorp/terraform-plugin-sdk#539
1 parent 9655f94 commit d2f1676

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

helper/resource/testing_new_config.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package resource
22

33
import (
4+
"fmt"
5+
46
tfjson "github.com/hashicorp/terraform-json"
57
tftest "github.com/hashicorp/terraform-plugin-test/v2"
68
testing "github.com/mitchellh/go-testing-interface"
@@ -24,7 +26,7 @@ func testStepNewConfig(t testing.T, c TestCase, wd *tftest.WorkingDir, step Test
2426
return err
2527
}
2628
if err := testStepTaint(state, step); err != nil {
27-
t.Fatalf("Error when tainting resources: %s", err)
29+
return fmt.Errorf("Error when tainting resources: %s", err)
2830
}
2931
}
3032

@@ -58,7 +60,7 @@ func testStepNewConfig(t testing.T, c TestCase, wd *tftest.WorkingDir, step Test
5860
if step.Check != nil {
5961
state.IsBinaryDrivenTest = true
6062
if err := step.Check(state); err != nil {
61-
t.Fatal(err)
63+
return err
6264
}
6365
}
6466
}
@@ -91,7 +93,7 @@ func testStepNewConfig(t testing.T, c TestCase, wd *tftest.WorkingDir, step Test
9193
if err != nil {
9294
return err
9395
}
94-
t.Fatalf("After applying this test step, the plan was not empty.\nstdout:\n\n%s", stdout)
96+
return fmt.Errorf("After applying this test step, the plan was not empty.\nstdout:\n\n%s", stdout)
9597
}
9698

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

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

0 commit comments

Comments
 (0)