Skip to content

Commit 6bb3dce

Browse files
authored
Merge pull request #396 from hashicorp/return-after-fatal
Make mockT.Fatal halt execution
2 parents a1878d1 + 7aef158 commit 6bb3dce

File tree

2 files changed

+17
-12
lines changed

2 files changed

+17
-12
lines changed

helper/resource/testing.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,6 @@ func Test(t TestT, c TestCase) {
558558
// We require verbose mode so that the user knows what is going on.
559559
if !testTesting && !testing.Verbose() && !c.IsUnitTest {
560560
t.Fatal("Acceptance tests must be run with the -v flag on tests")
561-
return
562561
}
563562

564563
// get instances of all providers, so we can use the individual

helper/resource/testing_test.go

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -509,22 +509,26 @@ func TestTest_stepError(t *testing.T) {
509509

510510
func TestTest_factoryError(t *testing.T) {
511511
resourceFactoryError := fmt.Errorf("resource factory error")
512-
513512
factory := func() (terraform.ResourceProvider, error) {
514513
return nil, resourceFactoryError
515514
}
516-
517515
mt := new(mockT)
518-
Test(mt, TestCase{
519-
ProviderFactories: map[string]terraform.ResourceProviderFactory{
520-
"test": factory,
521-
},
522-
Steps: []TestStep{
523-
{
524-
ExpectError: regexp.MustCompile("resource factory error"),
516+
517+
func() {
518+
defer func() {
519+
if r := recover(); r != nil {
520+
if !strings.HasPrefix(r.(string), "mockT") {
521+
panic(r)
522+
}
523+
}
524+
}()
525+
Test(mt, TestCase{
526+
ProviderFactories: map[string]terraform.ResourceProviderFactory{
527+
"test": factory,
525528
},
526-
},
527-
})
529+
IsUnitTest: true,
530+
})
531+
}()
528532

529533
if !mt.failed() {
530534
t.Fatal("test should've failed")
@@ -751,6 +755,8 @@ func (t *mockT) Fatal(args ...interface{}) {
751755
t.FatalCalled = true
752756
t.FatalArgs = args
753757
t.f = true
758+
759+
panic("mockT.Fatal")
754760
}
755761

756762
func (t *mockT) Parallel() {

0 commit comments

Comments
 (0)