Skip to content

Commit

Permalink
simulate exit of mockT.Fatal with panic/recover
Browse files Browse the repository at this point in the history
remove returns after t.Fatal
  • Loading branch information
appilon committed Apr 21, 2020
1 parent 4d4d2fd commit cdd4c2d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
1 change: 0 additions & 1 deletion helper/resource/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,6 @@ func Test(t TestT, c TestCase) {
// We require verbose mode so that the user knows what is going on.
if !testTesting && !testing.Verbose() && !c.IsUnitTest {
t.Fatal("Acceptance tests must be run with the -v flag on tests")
return
}

// get instances of all providers, so we can use the individual
Expand Down
24 changes: 13 additions & 11 deletions helper/resource/testing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -509,22 +509,22 @@ func TestTest_stepError(t *testing.T) {

func TestTest_factoryError(t *testing.T) {
resourceFactoryError := fmt.Errorf("resource factory error")

factory := func() (terraform.ResourceProvider, error) {
return nil, resourceFactoryError
}

mt := new(mockT)
Test(mt, TestCase{
ProviderFactories: map[string]terraform.ResourceProviderFactory{
"test": factory,
},
Steps: []TestStep{
{
ExpectError: regexp.MustCompile("resource factory error"),

func() {
defer func() {
recover()
}()
Test(mt, TestCase{
ProviderFactories: map[string]terraform.ResourceProviderFactory{
"test": factory,
},
},
})
IsUnitTest: true,
})
}()

if !mt.failed() {
t.Fatal("test should've failed")
Expand Down Expand Up @@ -751,6 +751,8 @@ func (t *mockT) Fatal(args ...interface{}) {
t.FatalCalled = true
t.FatalArgs = args
t.f = true

panic("mockT.Fatal")
}

func (t *mockT) Parallel() {
Expand Down

0 comments on commit cdd4c2d

Please sign in to comment.