2014-05-28 17:07:47 -05:00
|
|
|
package terraform
|
|
|
|
|
|
|
|
// MockResourceProvider implements ResourceProvider but mocks out all the
|
|
|
|
// calls for testing purposes.
|
|
|
|
type MockResourceProvider struct {
|
2014-06-03 17:08:00 -05:00
|
|
|
// Anything you want, in case you need to store extra data with the mock.
|
|
|
|
Meta interface{}
|
|
|
|
|
2014-05-28 17:07:47 -05:00
|
|
|
ConfigureCalled bool
|
|
|
|
ConfigureConfig map[string]interface{}
|
|
|
|
ConfigureReturnWarnings []string
|
|
|
|
ConfigureReturnError error
|
2014-06-05 04:32:10 -05:00
|
|
|
DiffCalled bool
|
|
|
|
DiffState ResourceState
|
|
|
|
DiffDesired map[string]interface{}
|
2014-06-05 08:57:06 -05:00
|
|
|
DiffFn func(ResourceState, map[string]interface{}) (ResourceDiff, error)
|
2014-06-05 04:32:10 -05:00
|
|
|
DiffReturn ResourceDiff
|
|
|
|
DiffReturnError error
|
2014-06-03 16:26:31 -05:00
|
|
|
ResourcesCalled bool
|
|
|
|
ResourcesReturn []ResourceType
|
2014-05-28 17:07:47 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func (p *MockResourceProvider) Configure(c map[string]interface{}) ([]string, error) {
|
|
|
|
p.ConfigureCalled = true
|
|
|
|
p.ConfigureConfig = c
|
|
|
|
return p.ConfigureReturnWarnings, p.ConfigureReturnError
|
|
|
|
}
|
2014-06-03 16:26:31 -05:00
|
|
|
|
2014-06-03 18:42:21 -05:00
|
|
|
func (p *MockResourceProvider) Diff(
|
|
|
|
state ResourceState,
|
|
|
|
desired map[string]interface{}) (ResourceDiff, error) {
|
2014-06-05 04:32:10 -05:00
|
|
|
p.DiffCalled = true
|
|
|
|
p.DiffState = state
|
|
|
|
p.DiffDesired = desired
|
2014-06-05 08:57:06 -05:00
|
|
|
if p.DiffFn != nil {
|
|
|
|
return p.DiffFn(state, desired)
|
|
|
|
}
|
|
|
|
|
2014-06-05 04:32:10 -05:00
|
|
|
return p.DiffReturn, p.DiffReturnError
|
2014-06-03 18:42:21 -05:00
|
|
|
}
|
|
|
|
|
2014-06-03 16:26:31 -05:00
|
|
|
func (p *MockResourceProvider) Resources() []ResourceType {
|
|
|
|
p.ResourcesCalled = true
|
|
|
|
return p.ResourcesReturn
|
|
|
|
}
|