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