github.com/Hashicorp/terraform@v0.11.12-beta1/terraform/eval_context_mock.go (about) 1 package terraform 2 3 import ( 4 "sync" 5 6 "github.com/hashicorp/terraform/config" 7 ) 8 9 // MockEvalContext is a mock version of EvalContext that can be used 10 // for tests. 11 type MockEvalContext struct { 12 StoppedCalled bool 13 StoppedValue <-chan struct{} 14 15 HookCalled bool 16 HookHook Hook 17 HookError error 18 19 InputCalled bool 20 InputInput UIInput 21 22 InitProviderCalled bool 23 InitProviderName string 24 InitProviderProvider ResourceProvider 25 InitProviderError error 26 27 ProviderCalled bool 28 ProviderName string 29 ProviderProvider ResourceProvider 30 31 CloseProviderCalled bool 32 CloseProviderName string 33 CloseProviderProvider ResourceProvider 34 35 ProviderInputCalled bool 36 ProviderInputName string 37 ProviderInputConfig map[string]interface{} 38 39 SetProviderInputCalled bool 40 SetProviderInputName string 41 SetProviderInputConfig map[string]interface{} 42 43 ConfigureProviderCalled bool 44 ConfigureProviderName string 45 ConfigureProviderConfig *ResourceConfig 46 ConfigureProviderError error 47 48 InitProvisionerCalled bool 49 InitProvisionerName string 50 InitProvisionerProvisioner ResourceProvisioner 51 InitProvisionerError error 52 53 ProvisionerCalled bool 54 ProvisionerName string 55 ProvisionerProvisioner ResourceProvisioner 56 57 CloseProvisionerCalled bool 58 CloseProvisionerName string 59 CloseProvisionerProvisioner ResourceProvisioner 60 61 InterpolateCalled bool 62 InterpolateConfig *config.RawConfig 63 InterpolateResource *Resource 64 InterpolateConfigResult *ResourceConfig 65 InterpolateError error 66 67 InterpolateProviderCalled bool 68 InterpolateProviderConfig *config.ProviderConfig 69 InterpolateProviderResource *Resource 70 InterpolateProviderConfigResult *ResourceConfig 71 InterpolateProviderError error 72 73 PathCalled bool 74 PathPath []string 75 76 SetVariablesCalled bool 77 SetVariablesModule string 78 SetVariablesVariables map[string]interface{} 79 80 DiffCalled bool 81 DiffDiff *Diff 82 DiffLock *sync.RWMutex 83 84 StateCalled bool 85 StateState *State 86 StateLock *sync.RWMutex 87 } 88 89 func (c *MockEvalContext) Stopped() <-chan struct{} { 90 c.StoppedCalled = true 91 return c.StoppedValue 92 } 93 94 func (c *MockEvalContext) Hook(fn func(Hook) (HookAction, error)) error { 95 c.HookCalled = true 96 if c.HookHook != nil { 97 if _, err := fn(c.HookHook); err != nil { 98 return err 99 } 100 } 101 102 return c.HookError 103 } 104 105 func (c *MockEvalContext) Input() UIInput { 106 c.InputCalled = true 107 return c.InputInput 108 } 109 110 func (c *MockEvalContext) InitProvider(t, n string) (ResourceProvider, error) { 111 c.InitProviderCalled = true 112 c.InitProviderName = n 113 return c.InitProviderProvider, c.InitProviderError 114 } 115 116 func (c *MockEvalContext) Provider(n string) ResourceProvider { 117 c.ProviderCalled = true 118 c.ProviderName = n 119 return c.ProviderProvider 120 } 121 122 func (c *MockEvalContext) CloseProvider(n string) error { 123 c.CloseProviderCalled = true 124 c.CloseProviderName = n 125 return nil 126 } 127 128 func (c *MockEvalContext) ConfigureProvider(n string, cfg *ResourceConfig) error { 129 c.ConfigureProviderCalled = true 130 c.ConfigureProviderName = n 131 c.ConfigureProviderConfig = cfg 132 return c.ConfigureProviderError 133 } 134 135 func (c *MockEvalContext) ProviderInput(n string) map[string]interface{} { 136 c.ProviderInputCalled = true 137 c.ProviderInputName = n 138 return c.ProviderInputConfig 139 } 140 141 func (c *MockEvalContext) SetProviderInput(n string, cfg map[string]interface{}) { 142 c.SetProviderInputCalled = true 143 c.SetProviderInputName = n 144 c.SetProviderInputConfig = cfg 145 } 146 147 func (c *MockEvalContext) InitProvisioner(n string) (ResourceProvisioner, error) { 148 c.InitProvisionerCalled = true 149 c.InitProvisionerName = n 150 return c.InitProvisionerProvisioner, c.InitProvisionerError 151 } 152 153 func (c *MockEvalContext) Provisioner(n string) ResourceProvisioner { 154 c.ProvisionerCalled = true 155 c.ProvisionerName = n 156 return c.ProvisionerProvisioner 157 } 158 159 func (c *MockEvalContext) CloseProvisioner(n string) error { 160 c.CloseProvisionerCalled = true 161 c.CloseProvisionerName = n 162 return nil 163 } 164 165 func (c *MockEvalContext) Interpolate( 166 config *config.RawConfig, resource *Resource) (*ResourceConfig, error) { 167 c.InterpolateCalled = true 168 c.InterpolateConfig = config 169 c.InterpolateResource = resource 170 return c.InterpolateConfigResult, c.InterpolateError 171 } 172 173 func (c *MockEvalContext) InterpolateProvider( 174 config *config.ProviderConfig, resource *Resource) (*ResourceConfig, error) { 175 c.InterpolateProviderCalled = true 176 c.InterpolateProviderConfig = config 177 c.InterpolateProviderResource = resource 178 return c.InterpolateProviderConfigResult, c.InterpolateError 179 } 180 181 func (c *MockEvalContext) Path() []string { 182 c.PathCalled = true 183 return c.PathPath 184 } 185 186 func (c *MockEvalContext) SetVariables(n string, vs map[string]interface{}) { 187 c.SetVariablesCalled = true 188 c.SetVariablesModule = n 189 c.SetVariablesVariables = vs 190 } 191 192 func (c *MockEvalContext) Diff() (*Diff, *sync.RWMutex) { 193 c.DiffCalled = true 194 return c.DiffDiff, c.DiffLock 195 } 196 197 func (c *MockEvalContext) State() (*State, *sync.RWMutex) { 198 c.StateCalled = true 199 return c.StateState, c.StateLock 200 }