diff --git a/helper/resource/testing.go b/helper/resource/testing.go index 18d57edced8..14d694ab2e4 100644 --- a/helper/resource/testing.go +++ b/helper/resource/testing.go @@ -537,7 +537,6 @@ func Test(t TestT, c TestCase) { // We require verbose mode so that the user knows what is going on. if !testing.Verbose() && !c.IsUnitTest { t.Fatal("Acceptance tests must be run with the -v flag on tests") - return } // Run the PreCheck if we have it @@ -561,7 +560,6 @@ func Test(t TestT, c TestCase) { if acctest.TestHelper == nil { t.Fatal("Please configure the acctest binary driver") - return } RunNewTest(t.(*testing.T), c, providers) diff --git a/helper/resource/testing_test.go b/helper/resource/testing_test.go index eacc6ae52d2..bd264cc5fac 100644 --- a/helper/resource/testing_test.go +++ b/helper/resource/testing_test.go @@ -6,7 +6,6 @@ import ( "fmt" "os" "reflect" - "regexp" "sort" "strings" "testing" @@ -30,7 +29,18 @@ func init() { func TestParallelTest(t *testing.T) { mt := new(mockT) - ParallelTest(mt, TestCase{}) + + // the test will error because the binary driver is unconfigured + func() { + defer func() { + if r := recover(); r != nil { + if !strings.HasPrefix(r.(string), "mockT") { + panic(r) + } + } + }() + ParallelTest(mt, TestCase{IsUnitTest: true}) + }() if !mt.ParallelCalled { t.Fatal("Parallel() not called") @@ -43,21 +53,27 @@ func TestTest_factoryError(t *testing.T) { factory := func() (*schema.Provider, error) { return nil, resourceFactoryError } - mt := new(mockT) - Test(mt, TestCase{ - ProviderFactories: map[string]func() (*schema.Provider, error){ - "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]func() (*schema.Provider, error){ + "test": factory, }, - }, - }) + IsUnitTest: true, + }) + }() - if !mt.failed() { - t.Fatal("test should've failed") + fatalStr := fmt.Sprint(mt.FatalArgs) + if !strings.Contains(fatalStr, resourceFactoryError.Error()) { + t.Fatalf("test should've failed with %s, failed with %s", resourceFactoryError, fatalStr) } } @@ -161,6 +177,8 @@ func (t *mockT) Fatal(args ...interface{}) { t.FatalCalled = true t.FatalArgs = args t.f = true + + panic("mockT.Fatal") } func (t *mockT) Parallel() {