2015-02-24 04:09:48 +01:00
|
|
|
package terraform
|
|
|
|
|
|
|
|
import (
|
|
|
|
"sync"
|
|
|
|
|
|
|
|
"github.com/hashicorp/terraform/config"
|
|
|
|
)
|
|
|
|
|
|
|
|
// MockEvalContext is a mock version of EvalContext that can be used
|
|
|
|
// for tests.
|
|
|
|
type MockEvalContext struct {
|
2016-12-22 20:33:26 +01:00
|
|
|
StoppedCalled bool
|
|
|
|
StoppedValue <-chan struct{}
|
|
|
|
|
2015-02-24 04:09:48 +01:00
|
|
|
HookCalled bool
|
|
|
|
HookHook Hook
|
|
|
|
HookError error
|
|
|
|
|
|
|
|
InputCalled bool
|
|
|
|
InputInput UIInput
|
|
|
|
|
|
|
|
InitProviderCalled bool
|
|
|
|
InitProviderName string
|
|
|
|
InitProviderProvider ResourceProvider
|
|
|
|
InitProviderError error
|
|
|
|
|
|
|
|
ProviderCalled bool
|
|
|
|
ProviderName string
|
|
|
|
ProviderProvider ResourceProvider
|
|
|
|
|
2015-06-19 21:52:50 +02:00
|
|
|
CloseProviderCalled bool
|
|
|
|
CloseProviderName string
|
|
|
|
CloseProviderProvider ResourceProvider
|
|
|
|
|
2015-02-24 04:09:48 +01:00
|
|
|
ProviderInputCalled bool
|
|
|
|
ProviderInputName string
|
|
|
|
ProviderInputConfig map[string]interface{}
|
|
|
|
|
|
|
|
SetProviderInputCalled bool
|
|
|
|
SetProviderInputName string
|
|
|
|
SetProviderInputConfig map[string]interface{}
|
|
|
|
|
|
|
|
ConfigureProviderCalled bool
|
|
|
|
ConfigureProviderName string
|
|
|
|
ConfigureProviderConfig *ResourceConfig
|
|
|
|
ConfigureProviderError error
|
|
|
|
|
|
|
|
InitProvisionerCalled bool
|
|
|
|
InitProvisionerName string
|
|
|
|
InitProvisionerProvisioner ResourceProvisioner
|
|
|
|
InitProvisionerError error
|
|
|
|
|
|
|
|
ProvisionerCalled bool
|
|
|
|
ProvisionerName string
|
|
|
|
ProvisionerProvisioner ResourceProvisioner
|
|
|
|
|
2015-06-19 21:52:50 +02:00
|
|
|
CloseProvisionerCalled bool
|
|
|
|
CloseProvisionerName string
|
|
|
|
CloseProvisionerProvisioner ResourceProvisioner
|
|
|
|
|
2015-02-24 04:09:48 +01:00
|
|
|
InterpolateCalled bool
|
|
|
|
InterpolateConfig *config.RawConfig
|
|
|
|
InterpolateResource *Resource
|
|
|
|
InterpolateConfigResult *ResourceConfig
|
|
|
|
InterpolateError error
|
|
|
|
|
2017-10-13 16:11:10 +02:00
|
|
|
InterpolateProviderCalled bool
|
|
|
|
InterpolateProviderConfig *config.ProviderConfig
|
|
|
|
InterpolateProviderResource *Resource
|
|
|
|
InterpolateProviderConfigResult *ResourceConfig
|
|
|
|
InterpolateProviderError error
|
|
|
|
|
2015-02-24 04:09:48 +01:00
|
|
|
PathCalled bool
|
|
|
|
PathPath []string
|
|
|
|
|
|
|
|
SetVariablesCalled bool
|
2015-05-02 01:29:19 +02:00
|
|
|
SetVariablesModule string
|
2016-04-11 19:40:06 +02:00
|
|
|
SetVariablesVariables map[string]interface{}
|
2015-02-24 04:09:48 +01:00
|
|
|
|
|
|
|
DiffCalled bool
|
|
|
|
DiffDiff *Diff
|
|
|
|
DiffLock *sync.RWMutex
|
|
|
|
|
|
|
|
StateCalled bool
|
|
|
|
StateState *State
|
|
|
|
StateLock *sync.RWMutex
|
|
|
|
}
|
|
|
|
|
2016-12-22 20:33:26 +01:00
|
|
|
func (c *MockEvalContext) Stopped() <-chan struct{} {
|
|
|
|
c.StoppedCalled = true
|
|
|
|
return c.StoppedValue
|
|
|
|
}
|
|
|
|
|
2015-02-24 04:09:48 +01:00
|
|
|
func (c *MockEvalContext) Hook(fn func(Hook) (HookAction, error)) error {
|
|
|
|
c.HookCalled = true
|
|
|
|
if c.HookHook != nil {
|
|
|
|
if _, err := fn(c.HookHook); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return c.HookError
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *MockEvalContext) Input() UIInput {
|
|
|
|
c.InputCalled = true
|
|
|
|
return c.InputInput
|
|
|
|
}
|
|
|
|
|
2017-11-01 23:34:18 +01:00
|
|
|
func (c *MockEvalContext) InitProvider(t, n string) (ResourceProvider, error) {
|
2015-02-24 04:09:48 +01:00
|
|
|
c.InitProviderCalled = true
|
|
|
|
c.InitProviderName = n
|
|
|
|
return c.InitProviderProvider, c.InitProviderError
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *MockEvalContext) Provider(n string) ResourceProvider {
|
|
|
|
c.ProviderCalled = true
|
|
|
|
c.ProviderName = n
|
|
|
|
return c.ProviderProvider
|
|
|
|
}
|
|
|
|
|
2015-06-19 21:52:50 +02:00
|
|
|
func (c *MockEvalContext) CloseProvider(n string) error {
|
|
|
|
c.CloseProviderCalled = true
|
|
|
|
c.CloseProviderName = n
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2015-02-24 04:09:48 +01:00
|
|
|
func (c *MockEvalContext) ConfigureProvider(n string, cfg *ResourceConfig) error {
|
|
|
|
c.ConfigureProviderCalled = true
|
|
|
|
c.ConfigureProviderName = n
|
|
|
|
c.ConfigureProviderConfig = cfg
|
|
|
|
return c.ConfigureProviderError
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *MockEvalContext) ProviderInput(n string) map[string]interface{} {
|
|
|
|
c.ProviderInputCalled = true
|
|
|
|
c.ProviderInputName = n
|
|
|
|
return c.ProviderInputConfig
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *MockEvalContext) SetProviderInput(n string, cfg map[string]interface{}) {
|
|
|
|
c.SetProviderInputCalled = true
|
|
|
|
c.SetProviderInputName = n
|
|
|
|
c.SetProviderInputConfig = cfg
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *MockEvalContext) InitProvisioner(n string) (ResourceProvisioner, error) {
|
|
|
|
c.InitProvisionerCalled = true
|
|
|
|
c.InitProvisionerName = n
|
|
|
|
return c.InitProvisionerProvisioner, c.InitProvisionerError
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *MockEvalContext) Provisioner(n string) ResourceProvisioner {
|
|
|
|
c.ProvisionerCalled = true
|
|
|
|
c.ProvisionerName = n
|
|
|
|
return c.ProvisionerProvisioner
|
|
|
|
}
|
|
|
|
|
2015-06-19 21:52:50 +02:00
|
|
|
func (c *MockEvalContext) CloseProvisioner(n string) error {
|
|
|
|
c.CloseProvisionerCalled = true
|
|
|
|
c.CloseProvisionerName = n
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2015-02-24 04:09:48 +01:00
|
|
|
func (c *MockEvalContext) Interpolate(
|
|
|
|
config *config.RawConfig, resource *Resource) (*ResourceConfig, error) {
|
|
|
|
c.InterpolateCalled = true
|
|
|
|
c.InterpolateConfig = config
|
|
|
|
c.InterpolateResource = resource
|
|
|
|
return c.InterpolateConfigResult, c.InterpolateError
|
|
|
|
}
|
|
|
|
|
2017-10-13 16:11:10 +02:00
|
|
|
func (c *MockEvalContext) InterpolateProvider(
|
|
|
|
config *config.ProviderConfig, resource *Resource) (*ResourceConfig, error) {
|
|
|
|
c.InterpolateProviderCalled = true
|
|
|
|
c.InterpolateProviderConfig = config
|
|
|
|
c.InterpolateProviderResource = resource
|
|
|
|
return c.InterpolateProviderConfigResult, c.InterpolateError
|
|
|
|
}
|
|
|
|
|
2015-02-24 04:09:48 +01:00
|
|
|
func (c *MockEvalContext) Path() []string {
|
|
|
|
c.PathCalled = true
|
|
|
|
return c.PathPath
|
|
|
|
}
|
|
|
|
|
2016-04-11 19:40:06 +02:00
|
|
|
func (c *MockEvalContext) SetVariables(n string, vs map[string]interface{}) {
|
2015-02-24 04:09:48 +01:00
|
|
|
c.SetVariablesCalled = true
|
2015-05-02 01:29:19 +02:00
|
|
|
c.SetVariablesModule = n
|
2015-02-24 04:09:48 +01:00
|
|
|
c.SetVariablesVariables = vs
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *MockEvalContext) Diff() (*Diff, *sync.RWMutex) {
|
|
|
|
c.DiffCalled = true
|
|
|
|
return c.DiffDiff, c.DiffLock
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *MockEvalContext) State() (*State, *sync.RWMutex) {
|
|
|
|
c.StateCalled = true
|
|
|
|
return c.StateState, c.StateLock
|
|
|
|
}
|