From 4b2e96b2e2663eae5a89f7bcdadb6a011dc7d201 Mon Sep 17 00:00:00 2001 From: James Bardin Date: Tue, 7 Mar 2017 10:18:09 -0500 Subject: [PATCH] test for TestReset and fixed resource factories --- helper/resource/testing_test.go | 49 +++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/helper/resource/testing_test.go b/helper/resource/testing_test.go index d2e05c0c5..56e9cd02e 100644 --- a/helper/resource/testing_test.go +++ b/helper/resource/testing_test.go @@ -4,6 +4,7 @@ import ( "errors" "fmt" "os" + "regexp" "strings" "sync/atomic" "testing" @@ -95,6 +96,9 @@ func TestTest(t *testing.T) { if !checkDestroy { t.Fatal("didn't call check for destroy") } + if !mp.TestResetCalled { + t.Fatal("didn't call TestReset") + } } func TestTest_idRefresh(t *testing.T) { @@ -355,6 +359,51 @@ 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{ + TestStep{ + ExpectError: regexp.MustCompile("resource factory error"), + }, + }, + }) + + if !mt.failed() { + t.Fatal("test should've failed") + } +} + +func TestTest_resetError(t *testing.T) { + mp := testProvider() + mp.TestResetError = fmt.Errorf("provider reset error") + + mt := new(mockT) + Test(mt, TestCase{ + Providers: map[string]terraform.ResourceProvider{ + "test": mp, + }, + Steps: []TestStep{ + TestStep{ + ExpectError: regexp.MustCompile("provider reset error"), + }, + }, + }) + + if !mt.failed() { + t.Fatal("test should've failed") + } +} + func TestComposeAggregateTestCheckFunc(t *testing.T) { check1 := func(s *terraform.State) error { return errors.New("Error 1")