terraform: races in MockResourceProvider
This commit is contained in:
parent
9c9f478811
commit
ac0e29e98e
|
@ -1,8 +1,8 @@
|
||||||
package aws
|
package aws
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
|
||||||
"log"
|
"log"
|
||||||
|
"os"
|
||||||
"reflect"
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,14 @@
|
||||||
package terraform
|
package terraform
|
||||||
|
|
||||||
|
import (
|
||||||
|
"sync"
|
||||||
|
)
|
||||||
|
|
||||||
// MockResourceProvider implements ResourceProvider but mocks out all the
|
// MockResourceProvider implements ResourceProvider but mocks out all the
|
||||||
// calls for testing purposes.
|
// calls for testing purposes.
|
||||||
type MockResourceProvider struct {
|
type MockResourceProvider struct {
|
||||||
|
sync.Mutex
|
||||||
|
|
||||||
// Anything you want, in case you need to store extra data with the mock.
|
// Anything you want, in case you need to store extra data with the mock.
|
||||||
Meta interface{}
|
Meta interface{}
|
||||||
|
|
||||||
|
@ -40,12 +46,18 @@ type MockResourceProvider struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *MockResourceProvider) Validate(c *ResourceConfig) ([]string, []error) {
|
func (p *MockResourceProvider) Validate(c *ResourceConfig) ([]string, []error) {
|
||||||
|
p.Lock()
|
||||||
|
defer p.Unlock()
|
||||||
|
|
||||||
p.ValidateCalled = true
|
p.ValidateCalled = true
|
||||||
p.ValidateConfig = c
|
p.ValidateConfig = c
|
||||||
return p.ValidateReturnWarns, p.ValidateReturnErrors
|
return p.ValidateReturnWarns, p.ValidateReturnErrors
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *MockResourceProvider) ValidateResource(t string, c *ResourceConfig) ([]string, []error) {
|
func (p *MockResourceProvider) ValidateResource(t string, c *ResourceConfig) ([]string, []error) {
|
||||||
|
p.Lock()
|
||||||
|
defer p.Unlock()
|
||||||
|
|
||||||
p.ValidateResourceCalled = true
|
p.ValidateResourceCalled = true
|
||||||
p.ValidateResourceType = t
|
p.ValidateResourceType = t
|
||||||
p.ValidateResourceConfig = c
|
p.ValidateResourceConfig = c
|
||||||
|
@ -53,6 +65,9 @@ func (p *MockResourceProvider) ValidateResource(t string, c *ResourceConfig) ([]
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *MockResourceProvider) Configure(c *ResourceConfig) error {
|
func (p *MockResourceProvider) Configure(c *ResourceConfig) error {
|
||||||
|
p.Lock()
|
||||||
|
defer p.Unlock()
|
||||||
|
|
||||||
p.ConfigureCalled = true
|
p.ConfigureCalled = true
|
||||||
p.ConfigureConfig = c
|
p.ConfigureConfig = c
|
||||||
return p.ConfigureReturnError
|
return p.ConfigureReturnError
|
||||||
|
@ -61,6 +76,9 @@ func (p *MockResourceProvider) Configure(c *ResourceConfig) error {
|
||||||
func (p *MockResourceProvider) Apply(
|
func (p *MockResourceProvider) Apply(
|
||||||
state *ResourceState,
|
state *ResourceState,
|
||||||
diff *ResourceDiff) (*ResourceState, error) {
|
diff *ResourceDiff) (*ResourceState, error) {
|
||||||
|
p.Lock()
|
||||||
|
defer p.Unlock()
|
||||||
|
|
||||||
p.ApplyCalled = true
|
p.ApplyCalled = true
|
||||||
p.ApplyState = state
|
p.ApplyState = state
|
||||||
p.ApplyDiff = diff
|
p.ApplyDiff = diff
|
||||||
|
@ -74,6 +92,9 @@ func (p *MockResourceProvider) Apply(
|
||||||
func (p *MockResourceProvider) Diff(
|
func (p *MockResourceProvider) Diff(
|
||||||
state *ResourceState,
|
state *ResourceState,
|
||||||
desired *ResourceConfig) (*ResourceDiff, error) {
|
desired *ResourceConfig) (*ResourceDiff, error) {
|
||||||
|
p.Lock()
|
||||||
|
defer p.Unlock()
|
||||||
|
|
||||||
p.DiffCalled = true
|
p.DiffCalled = true
|
||||||
p.DiffState = state
|
p.DiffState = state
|
||||||
p.DiffDesired = desired
|
p.DiffDesired = desired
|
||||||
|
@ -86,6 +107,9 @@ func (p *MockResourceProvider) Diff(
|
||||||
|
|
||||||
func (p *MockResourceProvider) Refresh(
|
func (p *MockResourceProvider) Refresh(
|
||||||
s *ResourceState) (*ResourceState, error) {
|
s *ResourceState) (*ResourceState, error) {
|
||||||
|
p.Lock()
|
||||||
|
defer p.Unlock()
|
||||||
|
|
||||||
p.RefreshCalled = true
|
p.RefreshCalled = true
|
||||||
p.RefreshState = s
|
p.RefreshState = s
|
||||||
|
|
||||||
|
@ -97,6 +121,9 @@ func (p *MockResourceProvider) Refresh(
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *MockResourceProvider) Resources() []ResourceType {
|
func (p *MockResourceProvider) Resources() []ResourceType {
|
||||||
|
p.Lock()
|
||||||
|
defer p.Unlock()
|
||||||
|
|
||||||
p.ResourcesCalled = true
|
p.ResourcesCalled = true
|
||||||
return p.ResourcesReturn
|
return p.ResourcesReturn
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue