github.com/wikibal01/hashicorp-terraform@v0.11.12-beta1/terraform/hook_test.go (about)

     1  package terraform
     2  
     3  import (
     4  	"testing"
     5  )
     6  
     7  func TestNilHook_impl(t *testing.T) {
     8  	var _ Hook = new(NilHook)
     9  }
    10  
    11  // testHook is a Hook implementation that logs the calls it receives.
    12  // It is intended for testing that core code is emitting the correct hooks
    13  // for a given situation.
    14  type testHook struct {
    15  	Calls []*testHookCall
    16  }
    17  
    18  // testHookCall represents a single call in testHook.
    19  // This hook just logs string names to make it easy to write "want" expressions
    20  // in tests that can DeepEqual against the real calls.
    21  type testHookCall struct {
    22  	Action     string
    23  	InstanceID string
    24  }
    25  
    26  func (h *testHook) PreApply(i *InstanceInfo, s *InstanceState, d *InstanceDiff) (HookAction, error) {
    27  	h.Calls = append(h.Calls, &testHookCall{"PreApply", i.ResourceAddress().String()})
    28  	return HookActionContinue, nil
    29  }
    30  
    31  func (h *testHook) PostApply(i *InstanceInfo, s *InstanceState, err error) (HookAction, error) {
    32  	h.Calls = append(h.Calls, &testHookCall{"PostApply", i.ResourceAddress().String()})
    33  	return HookActionContinue, nil
    34  }
    35  
    36  func (h *testHook) PreDiff(i *InstanceInfo, s *InstanceState) (HookAction, error) {
    37  	h.Calls = append(h.Calls, &testHookCall{"PreDiff", i.ResourceAddress().String()})
    38  	return HookActionContinue, nil
    39  }
    40  
    41  func (h *testHook) PostDiff(i *InstanceInfo, d *InstanceDiff) (HookAction, error) {
    42  	h.Calls = append(h.Calls, &testHookCall{"PostDiff", i.ResourceAddress().String()})
    43  	return HookActionContinue, nil
    44  }
    45  
    46  func (h *testHook) PreProvisionResource(i *InstanceInfo, s *InstanceState) (HookAction, error) {
    47  	h.Calls = append(h.Calls, &testHookCall{"PreProvisionResource", i.ResourceAddress().String()})
    48  	return HookActionContinue, nil
    49  }
    50  
    51  func (h *testHook) PostProvisionResource(i *InstanceInfo, s *InstanceState) (HookAction, error) {
    52  	h.Calls = append(h.Calls, &testHookCall{"PostProvisionResource", i.ResourceAddress().String()})
    53  	return HookActionContinue, nil
    54  }
    55  
    56  func (h *testHook) PreProvision(i *InstanceInfo, n string) (HookAction, error) {
    57  	h.Calls = append(h.Calls, &testHookCall{"PreProvision", i.ResourceAddress().String()})
    58  	return HookActionContinue, nil
    59  }
    60  
    61  func (h *testHook) PostProvision(i *InstanceInfo, n string, err error) (HookAction, error) {
    62  	h.Calls = append(h.Calls, &testHookCall{"PostProvision", i.ResourceAddress().String()})
    63  	return HookActionContinue, nil
    64  }
    65  
    66  func (h *testHook) ProvisionOutput(i *InstanceInfo, n string, m string) {
    67  	h.Calls = append(h.Calls, &testHookCall{"ProvisionOutput", i.ResourceAddress().String()})
    68  }
    69  
    70  func (h *testHook) PreRefresh(i *InstanceInfo, s *InstanceState) (HookAction, error) {
    71  	h.Calls = append(h.Calls, &testHookCall{"PreRefresh", i.ResourceAddress().String()})
    72  	return HookActionContinue, nil
    73  }
    74  
    75  func (h *testHook) PostRefresh(i *InstanceInfo, s *InstanceState) (HookAction, error) {
    76  	h.Calls = append(h.Calls, &testHookCall{"PostRefresh", i.ResourceAddress().String()})
    77  	return HookActionContinue, nil
    78  }
    79  
    80  func (h *testHook) PreImportState(i *InstanceInfo, n string) (HookAction, error) {
    81  	h.Calls = append(h.Calls, &testHookCall{"PreImportState", i.ResourceAddress().String()})
    82  	return HookActionContinue, nil
    83  }
    84  
    85  func (h *testHook) PostImportState(i *InstanceInfo, ss []*InstanceState) (HookAction, error) {
    86  	h.Calls = append(h.Calls, &testHookCall{"PostImportState", i.ResourceAddress().String()})
    87  	return HookActionContinue, nil
    88  }
    89  
    90  func (h *testHook) PostStateUpdate(s *State) (HookAction, error) {
    91  	h.Calls = append(h.Calls, &testHookCall{"PostStateUpdate", ""})
    92  	return HookActionContinue, nil
    93  }
    94  
    95  var _ Hook = new(testHook)