Skip to content

Commit

Permalink
simulate execution halt with panic in mockT
Browse files Browse the repository at this point in the history
remove return statements after t.Fatal
  • Loading branch information
appilon committed Apr 21, 2020
1 parent efaf61f commit 605b666
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 16 deletions.
5 changes: 0 additions & 5 deletions 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 All @@ -568,7 +567,6 @@ func Test(t TestT, c TestCase) {
p, err := pf()
if err != nil {
t.Fatal(err)
return
}
providers[name] = p
}
Expand All @@ -579,7 +577,6 @@ func Test(t TestT, c TestCase) {
err = p.Configure(terraform.NewResourceConfigRaw(nil))
if err != nil {
t.Fatal(err)
return
}
}

Expand All @@ -603,7 +600,6 @@ func Test(t TestT, c TestCase) {
providerResolver, err := testProviderResolver(c)
if err != nil {
t.Fatal(err)
return
}

opts := terraform.ContextOpts{ProviderResolver: providerResolver}
Expand All @@ -627,7 +623,6 @@ func Test(t TestT, c TestCase) {
skip, err := step.SkipFunc()
if err != nil {
t.Fatal(err)
return
}
if skip {
log.Printf("[WARN] Skipping step %d", i)
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 605b666

Please sign in to comment.