github.com/trawler/terraform@v0.10.8-0.20171106022149-4b1c7a1d9b48/terraform/hook_mock.go (about) 1 package terraform 2 3 import "sync" 4 5 // MockHook is an implementation of Hook that can be used for tests. 6 // It records all of its function calls. 7 type MockHook struct { 8 sync.Mutex 9 10 PreApplyCalled bool 11 PreApplyInfo *InstanceInfo 12 PreApplyDiff *InstanceDiff 13 PreApplyState *InstanceState 14 PreApplyReturn HookAction 15 PreApplyError error 16 17 PostApplyCalled bool 18 PostApplyInfo *InstanceInfo 19 PostApplyState *InstanceState 20 PostApplyError error 21 PostApplyReturn HookAction 22 PostApplyReturnError error 23 PostApplyFn func(*InstanceInfo, *InstanceState, error) (HookAction, error) 24 25 PreDiffCalled bool 26 PreDiffInfo *InstanceInfo 27 PreDiffState *InstanceState 28 PreDiffReturn HookAction 29 PreDiffError error 30 31 PostDiffCalled bool 32 PostDiffInfo *InstanceInfo 33 PostDiffDiff *InstanceDiff 34 PostDiffReturn HookAction 35 PostDiffError error 36 37 PreProvisionResourceCalled bool 38 PreProvisionResourceInfo *InstanceInfo 39 PreProvisionInstanceState *InstanceState 40 PreProvisionResourceReturn HookAction 41 PreProvisionResourceError error 42 43 PostProvisionResourceCalled bool 44 PostProvisionResourceInfo *InstanceInfo 45 PostProvisionInstanceState *InstanceState 46 PostProvisionResourceReturn HookAction 47 PostProvisionResourceError error 48 49 PreProvisionCalled bool 50 PreProvisionInfo *InstanceInfo 51 PreProvisionProvisionerId string 52 PreProvisionReturn HookAction 53 PreProvisionError error 54 55 PostProvisionCalled bool 56 PostProvisionInfo *InstanceInfo 57 PostProvisionProvisionerId string 58 PostProvisionErrorArg error 59 PostProvisionReturn HookAction 60 PostProvisionError error 61 62 ProvisionOutputCalled bool 63 ProvisionOutputInfo *InstanceInfo 64 ProvisionOutputProvisionerId string 65 ProvisionOutputMessage string 66 67 PostRefreshCalled bool 68 PostRefreshInfo *InstanceInfo 69 PostRefreshState *InstanceState 70 PostRefreshReturn HookAction 71 PostRefreshError error 72 73 PreRefreshCalled bool 74 PreRefreshInfo *InstanceInfo 75 PreRefreshState *InstanceState 76 PreRefreshReturn HookAction 77 PreRefreshError error 78 79 PreImportStateCalled bool 80 PreImportStateInfo *InstanceInfo 81 PreImportStateId string 82 PreImportStateReturn HookAction 83 PreImportStateError error 84 85 PostImportStateCalled bool 86 PostImportStateInfo *InstanceInfo 87 PostImportStateState []*InstanceState 88 PostImportStateReturn HookAction 89 PostImportStateError error 90 91 PostStateUpdateCalled bool 92 PostStateUpdateState *State 93 PostStateUpdateReturn HookAction 94 PostStateUpdateError error 95 } 96 97 func (h *MockHook) PreApply(n *InstanceInfo, s *InstanceState, d *InstanceDiff) (HookAction, error) { 98 h.Lock() 99 defer h.Unlock() 100 101 h.PreApplyCalled = true 102 h.PreApplyInfo = n 103 h.PreApplyDiff = d 104 h.PreApplyState = s 105 return h.PreApplyReturn, h.PreApplyError 106 } 107 108 func (h *MockHook) PostApply(n *InstanceInfo, s *InstanceState, e error) (HookAction, error) { 109 h.Lock() 110 defer h.Unlock() 111 112 h.PostApplyCalled = true 113 h.PostApplyInfo = n 114 h.PostApplyState = s 115 h.PostApplyError = e 116 117 if h.PostApplyFn != nil { 118 return h.PostApplyFn(n, s, e) 119 } 120 121 return h.PostApplyReturn, h.PostApplyReturnError 122 } 123 124 func (h *MockHook) PreDiff(n *InstanceInfo, s *InstanceState) (HookAction, error) { 125 h.Lock() 126 defer h.Unlock() 127 128 h.PreDiffCalled = true 129 h.PreDiffInfo = n 130 h.PreDiffState = s 131 return h.PreDiffReturn, h.PreDiffError 132 } 133 134 func (h *MockHook) PostDiff(n *InstanceInfo, d *InstanceDiff) (HookAction, error) { 135 h.Lock() 136 defer h.Unlock() 137 138 h.PostDiffCalled = true 139 h.PostDiffInfo = n 140 h.PostDiffDiff = d 141 return h.PostDiffReturn, h.PostDiffError 142 } 143 144 func (h *MockHook) PreProvisionResource(n *InstanceInfo, s *InstanceState) (HookAction, error) { 145 h.Lock() 146 defer h.Unlock() 147 148 h.PreProvisionResourceCalled = true 149 h.PreProvisionResourceInfo = n 150 h.PreProvisionInstanceState = s 151 return h.PreProvisionResourceReturn, h.PreProvisionResourceError 152 } 153 154 func (h *MockHook) PostProvisionResource(n *InstanceInfo, s *InstanceState) (HookAction, error) { 155 h.Lock() 156 defer h.Unlock() 157 158 h.PostProvisionResourceCalled = true 159 h.PostProvisionResourceInfo = n 160 h.PostProvisionInstanceState = s 161 return h.PostProvisionResourceReturn, h.PostProvisionResourceError 162 } 163 164 func (h *MockHook) PreProvision(n *InstanceInfo, provId string) (HookAction, error) { 165 h.Lock() 166 defer h.Unlock() 167 168 h.PreProvisionCalled = true 169 h.PreProvisionInfo = n 170 h.PreProvisionProvisionerId = provId 171 return h.PreProvisionReturn, h.PreProvisionError 172 } 173 174 func (h *MockHook) PostProvision(n *InstanceInfo, provId string, err error) (HookAction, error) { 175 h.Lock() 176 defer h.Unlock() 177 178 h.PostProvisionCalled = true 179 h.PostProvisionInfo = n 180 h.PostProvisionProvisionerId = provId 181 h.PostProvisionErrorArg = err 182 return h.PostProvisionReturn, h.PostProvisionError 183 } 184 185 func (h *MockHook) ProvisionOutput( 186 n *InstanceInfo, 187 provId string, 188 msg string) { 189 h.Lock() 190 defer h.Unlock() 191 192 h.ProvisionOutputCalled = true 193 h.ProvisionOutputInfo = n 194 h.ProvisionOutputProvisionerId = provId 195 h.ProvisionOutputMessage = msg 196 } 197 198 func (h *MockHook) PreRefresh(n *InstanceInfo, s *InstanceState) (HookAction, error) { 199 h.Lock() 200 defer h.Unlock() 201 202 h.PreRefreshCalled = true 203 h.PreRefreshInfo = n 204 h.PreRefreshState = s 205 return h.PreRefreshReturn, h.PreRefreshError 206 } 207 208 func (h *MockHook) PostRefresh(n *InstanceInfo, s *InstanceState) (HookAction, error) { 209 h.Lock() 210 defer h.Unlock() 211 212 h.PostRefreshCalled = true 213 h.PostRefreshInfo = n 214 h.PostRefreshState = s 215 return h.PostRefreshReturn, h.PostRefreshError 216 } 217 218 func (h *MockHook) PreImportState(info *InstanceInfo, id string) (HookAction, error) { 219 h.Lock() 220 defer h.Unlock() 221 222 h.PreImportStateCalled = true 223 h.PreImportStateInfo = info 224 h.PreImportStateId = id 225 return h.PreImportStateReturn, h.PreImportStateError 226 } 227 228 func (h *MockHook) PostImportState(info *InstanceInfo, s []*InstanceState) (HookAction, error) { 229 h.Lock() 230 defer h.Unlock() 231 232 h.PostImportStateCalled = true 233 h.PostImportStateInfo = info 234 h.PostImportStateState = s 235 return h.PostImportStateReturn, h.PostImportStateError 236 } 237 238 func (h *MockHook) PostStateUpdate(s *State) (HookAction, error) { 239 h.Lock() 240 defer h.Unlock() 241 242 h.PostStateUpdateCalled = true 243 h.PostStateUpdateState = s 244 return h.PostStateUpdateReturn, h.PostStateUpdateError 245 }