6 "github.com/hashicorp/terraform/configs/configschema"
9 // MockResourceProvisioner implements ResourceProvisioner but mocks out all the
10 // calls for testing purposes.
11 type MockResourceProvisioner struct {
13 // Anything you want, in case you need to store extra data with the mock.
16 GetConfigSchemaCalled bool
17 GetConfigSchemaReturnSchema *configschema.Block
18 GetConfigSchemaReturnError error
22 ApplyState *InstanceState
23 ApplyConfig *ResourceConfig
24 ApplyFn func(*InstanceState, *ResourceConfig) error
25 ApplyReturnError error
28 ValidateConfig *ResourceConfig
29 ValidateFn func(c *ResourceConfig) ([]string, []error)
30 ValidateReturnWarns []string
31 ValidateReturnErrors []error
38 var _ ResourceProvisioner = (*MockResourceProvisioner)(nil)
40 func (p *MockResourceProvisioner) GetConfigSchema() (*configschema.Block, error) {
41 p.GetConfigSchemaCalled = true
42 return p.GetConfigSchemaReturnSchema, p.GetConfigSchemaReturnError
45 func (p *MockResourceProvisioner) Validate(c *ResourceConfig) ([]string, []error) {
49 p.ValidateCalled = true
51 if p.ValidateFn != nil {
52 return p.ValidateFn(c)
54 return p.ValidateReturnWarns, p.ValidateReturnErrors
57 func (p *MockResourceProvisioner) Apply(
60 c *ResourceConfig) error {
64 p.ApplyOutput = output
74 return p.ApplyReturnError
77 func (p *MockResourceProvisioner) Stop() error {
86 return p.StopReturnError