github.com/federicobaldo/terraform@v0.6.15-0.20160323222747-b20f680cbf05/terraform/resource_provisioner_mock.go (about)

     1  package terraform
     2  
     3  // MockResourceProvisioner implements ResourceProvisioner but mocks out all the
     4  // calls for testing purposes.
     5  type MockResourceProvisioner struct {
     6  	// Anything you want, in case you need to store extra data with the mock.
     7  	Meta interface{}
     8  
     9  	ApplyCalled      bool
    10  	ApplyOutput      UIOutput
    11  	ApplyState       *InstanceState
    12  	ApplyConfig      *ResourceConfig
    13  	ApplyFn          func(*InstanceState, *ResourceConfig) error
    14  	ApplyReturnError error
    15  
    16  	ValidateCalled       bool
    17  	ValidateConfig       *ResourceConfig
    18  	ValidateFn           func(c *ResourceConfig) ([]string, []error)
    19  	ValidateReturnWarns  []string
    20  	ValidateReturnErrors []error
    21  }
    22  
    23  func (p *MockResourceProvisioner) Validate(c *ResourceConfig) ([]string, []error) {
    24  	p.ValidateCalled = true
    25  	p.ValidateConfig = c
    26  	if p.ValidateFn != nil {
    27  		return p.ValidateFn(c)
    28  	}
    29  	return p.ValidateReturnWarns, p.ValidateReturnErrors
    30  }
    31  
    32  func (p *MockResourceProvisioner) Apply(
    33  	output UIOutput,
    34  	state *InstanceState,
    35  	c *ResourceConfig) error {
    36  	p.ApplyCalled = true
    37  	p.ApplyOutput = output
    38  	p.ApplyState = state
    39  	p.ApplyConfig = c
    40  	if p.ApplyFn != nil {
    41  		return p.ApplyFn(state, c)
    42  	}
    43  	return p.ApplyReturnError
    44  }