Skip to content

Commit

Permalink
helper/resource: Always call return the error in testStepNewConfig in…
Browse files Browse the repository at this point in the history
…stead of t.Fatalf() so step numbers are included with error messages

Reference: #539
  • Loading branch information
bflad authored and paddycarver committed Aug 28, 2020
1 parent 9655f94 commit d2f1676
Showing 1 changed file with 7 additions and 5 deletions.
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

0 comments on commit d2f1676

Please sign in to comment.