2014-07-08 13:01:22 -05:00
|
|
|
package terraform
|
|
|
|
|
|
|
|
// MockResourceProvisioner implements ResourceProvisioner but mocks out all the
|
|
|
|
// calls for testing purposes.
|
|
|
|
type MockResourceProvisioner struct {
|
|
|
|
// Anything you want, in case you need to store extra data with the mock.
|
|
|
|
Meta interface{}
|
|
|
|
|
|
|
|
ApplyCalled bool
|
|
|
|
ApplyState *ResourceState
|
|
|
|
ApplyConfig *ResourceConfig
|
2014-07-22 11:56:39 -05:00
|
|
|
ApplyFn func(*ResourceState, *ResourceConfig) error
|
2014-07-08 13:01:22 -05:00
|
|
|
ApplyReturnError error
|
|
|
|
|
|
|
|
ValidateCalled bool
|
|
|
|
ValidateConfig *ResourceConfig
|
2014-07-09 17:02:00 -05:00
|
|
|
ValidateFn func(c *ResourceConfig) ([]string, []error)
|
2014-07-08 13:01:22 -05:00
|
|
|
ValidateReturnWarns []string
|
|
|
|
ValidateReturnErrors []error
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *MockResourceProvisioner) Validate(c *ResourceConfig) ([]string, []error) {
|
|
|
|
p.ValidateCalled = true
|
|
|
|
p.ValidateConfig = c
|
2014-07-09 17:02:00 -05:00
|
|
|
if p.ValidateFn != nil {
|
|
|
|
return p.ValidateFn(c)
|
|
|
|
}
|
2014-07-08 13:01:22 -05:00
|
|
|
return p.ValidateReturnWarns, p.ValidateReturnErrors
|
|
|
|
}
|
|
|
|
|
2014-07-22 11:56:39 -05:00
|
|
|
func (p *MockResourceProvisioner) Apply(state *ResourceState, c *ResourceConfig) error {
|
2014-07-08 13:01:22 -05:00
|
|
|
p.ApplyCalled = true
|
|
|
|
p.ApplyState = state
|
|
|
|
p.ApplyConfig = c
|
|
|
|
if p.ApplyFn != nil {
|
|
|
|
return p.ApplyFn(state, c)
|
|
|
|
}
|
2014-07-22 11:56:39 -05:00
|
|
|
return p.ApplyReturnError
|
2014-07-08 13:01:22 -05:00
|
|
|
}
|