test for TestReset and fixed resource factories

This commit is contained in:
James Bardin 2017-03-07 10:18:09 -05:00
parent 0279d11c8a
commit 4b2e96b2e2
1 changed files with 49 additions and 0 deletions

View File

@ -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")