mirror of
https://github.com/opentofu/opentofu.git
synced 2025-01-14 10:42:55 -06:00
45 lines
1.2 KiB
Go
45 lines
1.2 KiB
Go
package terraform
|
|
|
|
// MockResourceProvider implements ResourceProvider but mocks out all the
|
|
// calls for testing purposes.
|
|
type MockResourceProvider struct {
|
|
// Anything you want, in case you need to store extra data with the mock.
|
|
Meta interface{}
|
|
|
|
ConfigureCalled bool
|
|
ConfigureConfig *ResourceConfig
|
|
ConfigureReturnError error
|
|
DiffCalled bool
|
|
DiffState *ResourceState
|
|
DiffDesired *ResourceConfig
|
|
DiffFn func(*ResourceState, *ResourceConfig) (*ResourceDiff, error)
|
|
DiffReturn *ResourceDiff
|
|
DiffReturnError error
|
|
ResourcesCalled bool
|
|
ResourcesReturn []ResourceType
|
|
}
|
|
|
|
func (p *MockResourceProvider) Configure(c *ResourceConfig) error {
|
|
p.ConfigureCalled = true
|
|
p.ConfigureConfig = c
|
|
return p.ConfigureReturnError
|
|
}
|
|
|
|
func (p *MockResourceProvider) Diff(
|
|
state *ResourceState,
|
|
desired *ResourceConfig) (*ResourceDiff, error) {
|
|
p.DiffCalled = true
|
|
p.DiffState = state
|
|
p.DiffDesired = desired
|
|
if p.DiffFn != nil {
|
|
return p.DiffFn(state, desired)
|
|
}
|
|
|
|
return p.DiffReturn, p.DiffReturnError
|
|
}
|
|
|
|
func (p *MockResourceProvider) Resources() []ResourceType {
|
|
p.ResourcesCalled = true
|
|
return p.ResourcesReturn
|
|
}
|