opentofu/terraform/hook_mock.go

246 lines
6.1 KiB
Go
Raw Normal View History

2014-06-26 18:52:15 -05:00
package terraform
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 {
sync.Mutex
2014-06-27 00:09:16 -05:00
PreApplyCalled bool
PreApplyInfo *InstanceInfo
2014-09-17 18:33:24 -05:00
PreApplyDiff *InstanceDiff
PreApplyState *InstanceState
2014-06-27 00:09:16 -05:00
PreApplyReturn HookAction
PreApplyError error
PostApplyCalled bool
PostApplyInfo *InstanceInfo
PostApplyState *InstanceState
PostApplyError error
PostApplyReturn HookAction
PostApplyReturnError error
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
PreDiffInfo *InstanceInfo
PreDiffState *InstanceState
2014-06-26 19:17:10 -05:00
PreDiffReturn HookAction
PreDiffError error
PostDiffCalled bool
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
PreProvisionResourceInfo *InstanceInfo
PreProvisionInstanceState *InstanceState
2014-07-27 11:00:34 -05:00
PreProvisionResourceReturn HookAction
PreProvisionResourceError error
PostProvisionResourceCalled bool
PostProvisionResourceInfo *InstanceInfo
PostProvisionInstanceState *InstanceState
2014-07-27 11:00:34 -05:00
PostProvisionResourceReturn HookAction
PostProvisionResourceError error
PreProvisionCalled bool
PreProvisionInfo *InstanceInfo
2014-07-27 11:00:34 -05:00
PreProvisionProvisionerId string
PreProvisionReturn HookAction
PreProvisionError error
PostProvisionCalled bool
PostProvisionInfo *InstanceInfo
2014-07-27 11:00:34 -05:00
PostProvisionProvisionerId string
PostProvisionErrorArg error
2014-07-27 11:00:34 -05:00
PostProvisionReturn HookAction
PostProvisionError error
ProvisionOutputCalled bool
ProvisionOutputInfo *InstanceInfo
ProvisionOutputProvisionerId string
ProvisionOutputMessage string
2014-06-26 18:52:15 -05:00
PostRefreshCalled bool
PostRefreshInfo *InstanceInfo
PostRefreshState *InstanceState
2014-06-26 18:52:15 -05:00
PostRefreshReturn HookAction
PostRefreshError error
PreRefreshCalled bool
PreRefreshInfo *InstanceInfo
PreRefreshState *InstanceState
2014-06-26 18:52:15 -05:00
PreRefreshReturn HookAction
PreRefreshError error
PreImportStateCalled bool
PreImportStateInfo *InstanceInfo
PreImportStateId string
PreImportStateReturn HookAction
PreImportStateError error
PostImportStateCalled bool
PostImportStateInfo *InstanceInfo
PostImportStateState []*InstanceState
PostImportStateReturn HookAction
PostImportStateError error
PostStateUpdateCalled bool
PostStateUpdateState *State
PostStateUpdateReturn HookAction
PostStateUpdateError error
2014-06-26 18:52:15 -05:00
}
func (h *MockHook) PreApply(n *InstanceInfo, s *InstanceState, d *InstanceDiff) (HookAction, error) {
h.Lock()
defer h.Unlock()
2014-06-27 00:09:16 -05:00
h.PreApplyCalled = true
h.PreApplyInfo = n
2014-06-27 00:09:16 -05:00
h.PreApplyDiff = d
h.PreApplyState = s
return h.PreApplyReturn, h.PreApplyError
}
func (h *MockHook) PostApply(n *InstanceInfo, s *InstanceState, e error) (HookAction, error) {
h.Lock()
defer h.Unlock()
2014-06-27 00:09:16 -05:00
h.PostApplyCalled = true
h.PostApplyInfo = n
2014-06-27 00:09:16 -05:00
h.PostApplyState = s
h.PostApplyError = e
if h.PostApplyFn != nil {
return h.PostApplyFn(n, s, e)
}
return h.PostApplyReturn, h.PostApplyReturnError
2014-06-27 00:09:16 -05:00
}
func (h *MockHook) PreDiff(n *InstanceInfo, s *InstanceState) (HookAction, error) {
h.Lock()
defer h.Unlock()
2014-06-26 19:17:10 -05:00
h.PreDiffCalled = true
h.PreDiffInfo = n
2014-06-26 19:17:10 -05:00
h.PreDiffState = s
return h.PreDiffReturn, h.PreDiffError
}
func (h *MockHook) PostDiff(n *InstanceInfo, d *InstanceDiff) (HookAction, error) {
h.Lock()
defer h.Unlock()
2014-06-26 19:17:10 -05:00
h.PostDiffCalled = true
h.PostDiffInfo = n
2014-06-26 19:17:10 -05:00
h.PostDiffDiff = d
return h.PostDiffReturn, h.PostDiffError
}
func (h *MockHook) PreProvisionResource(n *InstanceInfo, s *InstanceState) (HookAction, error) {
h.Lock()
defer h.Unlock()
2014-07-27 11:00:34 -05:00
h.PreProvisionResourceCalled = true
h.PreProvisionResourceInfo = n
h.PreProvisionInstanceState = s
2014-07-27 11:00:34 -05:00
return h.PreProvisionResourceReturn, h.PreProvisionResourceError
}
func (h *MockHook) PostProvisionResource(n *InstanceInfo, s *InstanceState) (HookAction, error) {
h.Lock()
defer h.Unlock()
2014-07-27 11:00:34 -05:00
h.PostProvisionResourceCalled = true
h.PostProvisionResourceInfo = n
h.PostProvisionInstanceState = s
2014-07-27 11:00:34 -05:00
return h.PostProvisionResourceReturn, h.PostProvisionResourceError
}
func (h *MockHook) PreProvision(n *InstanceInfo, provId string) (HookAction, error) {
h.Lock()
defer h.Unlock()
2014-07-27 11:00:34 -05:00
h.PreProvisionCalled = true
h.PreProvisionInfo = n
2014-07-27 11:00:34 -05:00
h.PreProvisionProvisionerId = provId
return h.PreProvisionReturn, h.PreProvisionError
}
func (h *MockHook) PostProvision(n *InstanceInfo, provId string, err error) (HookAction, error) {
h.Lock()
defer h.Unlock()
2014-07-27 11:00:34 -05:00
h.PostProvisionCalled = true
h.PostProvisionInfo = n
2014-07-27 11:00:34 -05:00
h.PostProvisionProvisionerId = provId
h.PostProvisionErrorArg = err
2014-07-27 11:00:34 -05:00
return h.PostProvisionReturn, h.PostProvisionError
}
func (h *MockHook) ProvisionOutput(
n *InstanceInfo,
provId string,
msg string) {
h.Lock()
defer h.Unlock()
h.ProvisionOutputCalled = true
h.ProvisionOutputInfo = n
h.ProvisionOutputProvisionerId = provId
h.ProvisionOutputMessage = msg
}
func (h *MockHook) PreRefresh(n *InstanceInfo, s *InstanceState) (HookAction, error) {
h.Lock()
defer h.Unlock()
2014-06-26 18:52:15 -05:00
h.PreRefreshCalled = true
h.PreRefreshInfo = n
2014-06-26 18:52:15 -05:00
h.PreRefreshState = s
return h.PreRefreshReturn, h.PreRefreshError
}
func (h *MockHook) PostRefresh(n *InstanceInfo, s *InstanceState) (HookAction, error) {
h.Lock()
defer h.Unlock()
2014-06-26 18:52:15 -05:00
h.PostRefreshCalled = true
h.PostRefreshInfo = n
2014-06-26 18:52:15 -05:00
h.PostRefreshState = s
return h.PostRefreshReturn, h.PostRefreshError
}
func (h *MockHook) PreImportState(info *InstanceInfo, id string) (HookAction, error) {
h.Lock()
defer h.Unlock()
h.PreImportStateCalled = true
h.PreImportStateInfo = info
h.PreImportStateId = id
return h.PreImportStateReturn, h.PreImportStateError
}
func (h *MockHook) PostImportState(info *InstanceInfo, s []*InstanceState) (HookAction, error) {
h.Lock()
defer h.Unlock()
h.PostImportStateCalled = true
h.PostImportStateInfo = info
h.PostImportStateState = s
return h.PostImportStateReturn, h.PostImportStateError
}
func (h *MockHook) PostStateUpdate(s *State) (HookAction, error) {
h.Lock()
defer h.Unlock()
h.PostStateUpdateCalled = true
h.PostStateUpdateState = s
return h.PostStateUpdateReturn, h.PostStateUpdateError
}