2014-06-26 18:52:15 -05:00
|
|
|
package terraform
|
|
|
|
|
2016-07-29 12:17:48 -05:00
|
|
|
import "sync"
|
|
|
|
|
2014-06-26 18:52:15 -05:00
|
|
|
// MockHook is an implementation of Hook that can be used for tests.
|
|
|
|
// It records all of its function calls.
|
|
|
|
type MockHook struct {
|
2016-07-29 12:17:48 -05:00
|
|
|
sync.Mutex
|
|
|
|
|
2014-06-27 00:09:16 -05:00
|
|
|
PreApplyCalled bool
|
2014-09-25 12:40:44 -05:00
|
|
|
PreApplyInfo *InstanceInfo
|
2014-09-17 18:33:24 -05:00
|
|
|
PreApplyDiff *InstanceDiff
|
2014-09-17 17:00:19 -05:00
|
|
|
PreApplyState *InstanceState
|
2014-06-27 00:09:16 -05:00
|
|
|
PreApplyReturn HookAction
|
|
|
|
PreApplyError error
|
|
|
|
|
2014-07-17 17:38:50 -05:00
|
|
|
PostApplyCalled bool
|
2014-09-25 12:40:44 -05:00
|
|
|
PostApplyInfo *InstanceInfo
|
2014-09-17 17:00:19 -05:00
|
|
|
PostApplyState *InstanceState
|
2014-07-17 17:38:50 -05:00
|
|
|
PostApplyError error
|
|
|
|
PostApplyReturn HookAction
|
|
|
|
PostApplyReturnError error
|
2016-10-30 17:24:20 -05:00
|
|
|
PostApplyFn func(*InstanceInfo, *InstanceState, error) (HookAction, error)
|
2014-06-27 00:09:16 -05:00
|
|
|
|
2014-06-26 19:17:10 -05:00
|
|
|
PreDiffCalled bool
|
2014-09-25 12:40:44 -05:00
|
|
|
PreDiffInfo *InstanceInfo
|
2014-09-17 17:00:19 -05:00
|
|
|
PreDiffState *InstanceState
|
2014-06-26 19:17:10 -05:00
|
|
|
PreDiffReturn HookAction
|
|
|
|
PreDiffError error
|
|
|
|
|
|
|
|
PostDiffCalled bool
|
2014-09-25 12:40:44 -05:00
|
|
|
PostDiffInfo *InstanceInfo
|
2014-09-17 18:33:24 -05:00
|
|
|
PostDiffDiff *InstanceDiff
|
2014-06-26 19:17:10 -05:00
|
|
|
PostDiffReturn HookAction
|
|
|
|
PostDiffError error
|
|
|
|
|
2014-07-27 11:00:34 -05:00
|
|
|
PreProvisionResourceCalled bool
|
2014-09-25 12:40:44 -05:00
|
|
|
PreProvisionResourceInfo *InstanceInfo
|
2014-09-17 17:00:19 -05:00
|
|
|
PreProvisionInstanceState *InstanceState
|
2014-07-27 11:00:34 -05:00
|
|
|
PreProvisionResourceReturn HookAction
|
|
|
|
PreProvisionResourceError error
|
|
|
|
|
|
|
|
PostProvisionResourceCalled bool
|
2014-09-25 12:40:44 -05:00
|
|
|
PostProvisionResourceInfo *InstanceInfo
|
2014-09-17 17:00:19 -05:00
|
|
|
PostProvisionInstanceState *InstanceState
|
2014-07-27 11:00:34 -05:00
|
|
|
PostProvisionResourceReturn HookAction
|
|
|
|
PostProvisionResourceError error
|
|
|
|
|
|
|
|
PreProvisionCalled bool
|
2014-09-25 12:40:44 -05:00
|
|
|
PreProvisionInfo *InstanceInfo
|
2014-07-27 11:00:34 -05:00
|
|
|
PreProvisionProvisionerId string
|
|
|
|
PreProvisionReturn HookAction
|
|
|
|
PreProvisionError error
|
|
|
|
|
|
|
|
PostProvisionCalled bool
|
2014-09-25 12:40:44 -05:00
|
|
|
PostProvisionInfo *InstanceInfo
|
2014-07-27 11:00:34 -05:00
|
|
|
PostProvisionProvisionerId string
|
2017-01-20 22:21:12 -06:00
|
|
|
PostProvisionErrorArg error
|
2014-07-27 11:00:34 -05:00
|
|
|
PostProvisionReturn HookAction
|
|
|
|
PostProvisionError error
|
|
|
|
|
2014-10-04 18:24:07 -05:00
|
|
|
ProvisionOutputCalled bool
|
|
|
|
ProvisionOutputInfo *InstanceInfo
|
|
|
|
ProvisionOutputProvisionerId string
|
|
|
|
ProvisionOutputMessage string
|
|
|
|
|
2014-06-26 18:52:15 -05:00
|
|
|
PostRefreshCalled bool
|
2014-09-25 12:40:44 -05:00
|
|
|
PostRefreshInfo *InstanceInfo
|
2014-09-17 17:00:19 -05:00
|
|
|
PostRefreshState *InstanceState
|
2014-06-26 18:52:15 -05:00
|
|
|
PostRefreshReturn HookAction
|
|
|
|
PostRefreshError error
|
|
|
|
|
|
|
|
PreRefreshCalled bool
|
2014-09-25 12:40:44 -05:00
|
|
|
PreRefreshInfo *InstanceInfo
|
2014-09-17 17:00:19 -05:00
|
|
|
PreRefreshState *InstanceState
|
2014-06-26 18:52:15 -05:00
|
|
|
PreRefreshReturn HookAction
|
|
|
|
PreRefreshError error
|
2015-02-23 21:09:48 -06:00
|
|
|
|
2016-05-04 13:53:56 -05:00
|
|
|
PreImportStateCalled bool
|
|
|
|
PreImportStateInfo *InstanceInfo
|
2016-05-04 15:02:51 -05:00
|
|
|
PreImportStateId string
|
2016-05-04 13:53:56 -05:00
|
|
|
PreImportStateReturn HookAction
|
|
|
|
PreImportStateError error
|
|
|
|
|
|
|
|
PostImportStateCalled bool
|
|
|
|
PostImportStateInfo *InstanceInfo
|
|
|
|
PostImportStateState []*InstanceState
|
|
|
|
PostImportStateReturn HookAction
|
|
|
|
PostImportStateError error
|
|
|
|
|
2015-02-23 21:09:48 -06:00
|
|
|
PostStateUpdateCalled bool
|
|
|
|
PostStateUpdateState *State
|
|
|
|
PostStateUpdateReturn HookAction
|
|
|
|
PostStateUpdateError error
|
2014-06-26 18:52:15 -05:00
|
|
|
}
|
|
|
|
|
2014-09-25 12:40:44 -05:00
|
|
|
func (h *MockHook) PreApply(n *InstanceInfo, s *InstanceState, d *InstanceDiff) (HookAction, error) {
|
2016-07-29 12:17:48 -05:00
|
|
|
h.Lock()
|
|
|
|
defer h.Unlock()
|
|
|
|
|
2014-06-27 00:09:16 -05:00
|
|
|
h.PreApplyCalled = true
|
2014-09-25 12:40:44 -05:00
|
|
|
h.PreApplyInfo = n
|
2014-06-27 00:09:16 -05:00
|
|
|
h.PreApplyDiff = d
|
|
|
|
h.PreApplyState = s
|
|
|
|
return h.PreApplyReturn, h.PreApplyError
|
|
|
|
}
|
|
|
|
|
2014-09-25 12:40:44 -05:00
|
|
|
func (h *MockHook) PostApply(n *InstanceInfo, s *InstanceState, e error) (HookAction, error) {
|
2016-07-29 12:17:48 -05:00
|
|
|
h.Lock()
|
|
|
|
defer h.Unlock()
|
|
|
|
|
2014-06-27 00:09:16 -05:00
|
|
|
h.PostApplyCalled = true
|
2014-09-25 12:40:44 -05:00
|
|
|
h.PostApplyInfo = n
|
2014-06-27 00:09:16 -05:00
|
|
|
h.PostApplyState = s
|
2014-07-17 17:38:50 -05:00
|
|
|
h.PostApplyError = e
|
2016-10-30 17:24:20 -05:00
|
|
|
|
|
|
|
if h.PostApplyFn != nil {
|
|
|
|
return h.PostApplyFn(n, s, e)
|
|
|
|
}
|
|
|
|
|
2014-07-17 17:38:50 -05:00
|
|
|
return h.PostApplyReturn, h.PostApplyReturnError
|
2014-06-27 00:09:16 -05:00
|
|
|
}
|
|
|
|
|
2014-09-25 12:40:44 -05:00
|
|
|
func (h *MockHook) PreDiff(n *InstanceInfo, s *InstanceState) (HookAction, error) {
|
2016-07-29 12:17:48 -05:00
|
|
|
h.Lock()
|
|
|
|
defer h.Unlock()
|
|
|
|
|
2014-06-26 19:17:10 -05:00
|
|
|
h.PreDiffCalled = true
|
2014-09-25 12:40:44 -05:00
|
|
|
h.PreDiffInfo = n
|
2014-06-26 19:17:10 -05:00
|
|
|
h.PreDiffState = s
|
|
|
|
return h.PreDiffReturn, h.PreDiffError
|
|
|
|
}
|
|
|
|
|
2014-09-25 12:40:44 -05:00
|
|
|
func (h *MockHook) PostDiff(n *InstanceInfo, d *InstanceDiff) (HookAction, error) {
|
2016-07-29 12:17:48 -05:00
|
|
|
h.Lock()
|
|
|
|
defer h.Unlock()
|
|
|
|
|
2014-06-26 19:17:10 -05:00
|
|
|
h.PostDiffCalled = true
|
2014-09-25 12:40:44 -05:00
|
|
|
h.PostDiffInfo = n
|
2014-06-26 19:17:10 -05:00
|
|
|
h.PostDiffDiff = d
|
|
|
|
return h.PostDiffReturn, h.PostDiffError
|
|
|
|
}
|
|
|
|
|
2014-09-25 12:40:44 -05:00
|
|
|
func (h *MockHook) PreProvisionResource(n *InstanceInfo, s *InstanceState) (HookAction, error) {
|
2016-07-29 12:17:48 -05:00
|
|
|
h.Lock()
|
|
|
|
defer h.Unlock()
|
|
|
|
|
2014-07-27 11:00:34 -05:00
|
|
|
h.PreProvisionResourceCalled = true
|
2014-09-25 12:40:44 -05:00
|
|
|
h.PreProvisionResourceInfo = n
|
2014-09-17 17:00:19 -05:00
|
|
|
h.PreProvisionInstanceState = s
|
2014-07-27 11:00:34 -05:00
|
|
|
return h.PreProvisionResourceReturn, h.PreProvisionResourceError
|
|
|
|
}
|
|
|
|
|
2014-09-25 12:40:44 -05:00
|
|
|
func (h *MockHook) PostProvisionResource(n *InstanceInfo, s *InstanceState) (HookAction, error) {
|
2016-07-29 12:17:48 -05:00
|
|
|
h.Lock()
|
|
|
|
defer h.Unlock()
|
|
|
|
|
2014-07-27 11:00:34 -05:00
|
|
|
h.PostProvisionResourceCalled = true
|
2014-09-25 12:40:44 -05:00
|
|
|
h.PostProvisionResourceInfo = n
|
2014-09-17 17:00:19 -05:00
|
|
|
h.PostProvisionInstanceState = s
|
2014-07-27 11:00:34 -05:00
|
|
|
return h.PostProvisionResourceReturn, h.PostProvisionResourceError
|
|
|
|
}
|
|
|
|
|
2014-09-25 12:40:44 -05:00
|
|
|
func (h *MockHook) PreProvision(n *InstanceInfo, provId string) (HookAction, error) {
|
2016-07-29 12:17:48 -05:00
|
|
|
h.Lock()
|
|
|
|
defer h.Unlock()
|
|
|
|
|
2014-07-27 11:00:34 -05:00
|
|
|
h.PreProvisionCalled = true
|
2014-09-25 12:40:44 -05:00
|
|
|
h.PreProvisionInfo = n
|
2014-07-27 11:00:34 -05:00
|
|
|
h.PreProvisionProvisionerId = provId
|
|
|
|
return h.PreProvisionReturn, h.PreProvisionError
|
|
|
|
}
|
|
|
|
|
2017-01-20 22:21:12 -06:00
|
|
|
func (h *MockHook) PostProvision(n *InstanceInfo, provId string, err error) (HookAction, error) {
|
2016-07-29 12:17:48 -05:00
|
|
|
h.Lock()
|
|
|
|
defer h.Unlock()
|
|
|
|
|
2014-07-27 11:00:34 -05:00
|
|
|
h.PostProvisionCalled = true
|
2014-09-25 12:40:44 -05:00
|
|
|
h.PostProvisionInfo = n
|
2014-07-27 11:00:34 -05:00
|
|
|
h.PostProvisionProvisionerId = provId
|
2017-01-20 22:21:12 -06:00
|
|
|
h.PostProvisionErrorArg = err
|
2014-07-27 11:00:34 -05:00
|
|
|
return h.PostProvisionReturn, h.PostProvisionError
|
|
|
|
}
|
|
|
|
|
2014-10-04 18:24:07 -05:00
|
|
|
func (h *MockHook) ProvisionOutput(
|
|
|
|
n *InstanceInfo,
|
|
|
|
provId string,
|
|
|
|
msg string) {
|
2016-07-29 12:17:48 -05:00
|
|
|
h.Lock()
|
|
|
|
defer h.Unlock()
|
|
|
|
|
2014-10-04 18:24:07 -05:00
|
|
|
h.ProvisionOutputCalled = true
|
|
|
|
h.ProvisionOutputInfo = n
|
|
|
|
h.ProvisionOutputProvisionerId = provId
|
|
|
|
h.ProvisionOutputMessage = msg
|
|
|
|
}
|
|
|
|
|
2014-09-25 12:40:44 -05:00
|
|
|
func (h *MockHook) PreRefresh(n *InstanceInfo, s *InstanceState) (HookAction, error) {
|
2016-07-29 12:17:48 -05:00
|
|
|
h.Lock()
|
|
|
|
defer h.Unlock()
|
|
|
|
|
2014-06-26 18:52:15 -05:00
|
|
|
h.PreRefreshCalled = true
|
2014-09-25 12:40:44 -05:00
|
|
|
h.PreRefreshInfo = n
|
2014-06-26 18:52:15 -05:00
|
|
|
h.PreRefreshState = s
|
|
|
|
return h.PreRefreshReturn, h.PreRefreshError
|
|
|
|
}
|
|
|
|
|
2014-09-25 12:40:44 -05:00
|
|
|
func (h *MockHook) PostRefresh(n *InstanceInfo, s *InstanceState) (HookAction, error) {
|
2016-07-29 12:17:48 -05:00
|
|
|
h.Lock()
|
|
|
|
defer h.Unlock()
|
|
|
|
|
2014-06-26 18:52:15 -05:00
|
|
|
h.PostRefreshCalled = true
|
2014-09-25 12:40:44 -05:00
|
|
|
h.PostRefreshInfo = n
|
2014-06-26 18:52:15 -05:00
|
|
|
h.PostRefreshState = s
|
|
|
|
return h.PostRefreshReturn, h.PostRefreshError
|
|
|
|
}
|
2015-02-23 21:09:48 -06:00
|
|
|
|
2016-05-04 15:02:51 -05:00
|
|
|
func (h *MockHook) PreImportState(info *InstanceInfo, id string) (HookAction, error) {
|
2016-07-29 12:17:48 -05:00
|
|
|
h.Lock()
|
|
|
|
defer h.Unlock()
|
|
|
|
|
2016-05-04 13:53:56 -05:00
|
|
|
h.PreImportStateCalled = true
|
|
|
|
h.PreImportStateInfo = info
|
2016-05-04 15:02:51 -05:00
|
|
|
h.PreImportStateId = id
|
2016-05-04 13:53:56 -05:00
|
|
|
return h.PreImportStateReturn, h.PreImportStateError
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h *MockHook) PostImportState(info *InstanceInfo, s []*InstanceState) (HookAction, error) {
|
2016-07-29 12:17:48 -05:00
|
|
|
h.Lock()
|
|
|
|
defer h.Unlock()
|
|
|
|
|
2016-05-04 13:53:56 -05:00
|
|
|
h.PostImportStateCalled = true
|
|
|
|
h.PostImportStateInfo = info
|
|
|
|
h.PostImportStateState = s
|
|
|
|
return h.PostImportStateReturn, h.PostImportStateError
|
|
|
|
}
|
|
|
|
|
2015-02-23 21:09:48 -06:00
|
|
|
func (h *MockHook) PostStateUpdate(s *State) (HookAction, error) {
|
2016-07-29 12:17:48 -05:00
|
|
|
h.Lock()
|
|
|
|
defer h.Unlock()
|
|
|
|
|
2015-02-23 21:09:48 -06:00
|
|
|
h.PostStateUpdateCalled = true
|
|
|
|
h.PostStateUpdateState = s
|
|
|
|
return h.PostStateUpdateReturn, h.PostStateUpdateError
|
|
|
|
}
|