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"
"regexp"
"strings"
"sync"
"sync/atomic"
"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) {
mp := testProvider()
mp := &resetProvider{
MockResourceProvider: testProvider(),
}
mp.DiffReturn = nil
mp.ApplyFn = func(
@ -384,8 +403,10 @@ func TestTest_factoryError(t *testing.T) {
}
func TestTest_resetError(t *testing.T) {
mp := testProvider()
mp.TestResetError = fmt.Errorf("provider reset error")
mp := &resetProvider{
MockResourceProvider: testProvider(),
TestResetError: fmt.Errorf("provider reset error"),
}
mt := new(mockT)
Test(mt, TestCase{

View File

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