move TestReset mock from terraform to helper

the terraform package doesn't know about TestProvider, so don't put the
hooks in terraform.MockResourceProvider. Wrap the mock in the test where
we need to check the TestProvider functionality.
This commit is contained in:
James Bardin 2017-03-08 17:42:05 -05:00
parent 6fcb55d09e
commit 5238f51dc7
2 changed files with 24 additions and 13 deletions

View File

@ -6,6 +6,7 @@ import (
"os" "os"
"regexp" "regexp"
"strings" "strings"
"sync"
"sync/atomic" "sync/atomic"
"testing" "testing"
@ -26,8 +27,26 @@ func init() {
} }
} }
// wrap the mock provider to implement TestProvider
type resetProvider struct {
*terraform.MockResourceProvider
mu sync.Mutex
TestResetCalled bool
TestResetError error
}
func (p *resetProvider) TestReset() error {
p.mu.Lock()
defer p.mu.Unlock()
p.TestResetCalled = true
return p.TestResetError
}
func TestTest(t *testing.T) { func TestTest(t *testing.T) {
mp := testProvider() mp := &resetProvider{
MockResourceProvider: testProvider(),
}
mp.DiffReturn = nil mp.DiffReturn = nil
mp.ApplyFn = func( mp.ApplyFn = func(
@ -384,8 +403,10 @@ func TestTest_factoryError(t *testing.T) {
} }
func TestTest_resetError(t *testing.T) { func TestTest_resetError(t *testing.T) {
mp := testProvider() mp := &resetProvider{
mp.TestResetError = fmt.Errorf("provider reset error") MockResourceProvider: testProvider(),
TestResetError: fmt.Errorf("provider reset error"),
}
mt := new(mockT) mt := new(mockT)
Test(mt, TestCase{ Test(mt, TestCase{

View File

@ -56,8 +56,6 @@ type MockResourceProvider struct {
ReadDataDiffFn func(*InstanceInfo, *ResourceConfig) (*InstanceDiff, error) ReadDataDiffFn func(*InstanceInfo, *ResourceConfig) (*InstanceDiff, error)
ReadDataDiffReturn *InstanceDiff ReadDataDiffReturn *InstanceDiff
ReadDataDiffReturnError error ReadDataDiffReturnError error
TestResetCalled bool
TestResetError error
StopCalled bool StopCalled bool
StopFn func() error StopFn func() error
StopReturnError error StopReturnError error
@ -146,14 +144,6 @@ func (p *MockResourceProvider) Configure(c *ResourceConfig) error {
return p.ConfigureReturnError return p.ConfigureReturnError
} }
func (p *MockResourceProvider) TestReset() error {
p.Lock()
defer p.Unlock()
p.TestResetCalled = true
return p.TestResetError
}
func (p *MockResourceProvider) Stop() error { func (p *MockResourceProvider) Stop() error {
p.Lock() p.Lock()
defer p.Unlock() defer p.Unlock()