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

Make mockT.Fatal halt execution #396

Merged
merged 2 commits into from
Apr 22, 2020
Merged
Show file tree
Hide file tree
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
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
28 changes: 17 additions & 11 deletions helper/resource/testing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -509,22 +509,26 @@ 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() {
if r := recover(); r != nil {
if !strings.HasPrefix(r.(string), "mockT") {
panic(r)
}
}
}()
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 +755,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