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