github.com/turtlemonvh/terraform@v0.6.9-0.20151204001754-8e40b6b855e8/terraform/eval_context_mock.go (about)

     1  package terraform
     2  
     3  import (
     4  	"sync"
     5  
     6  	"github.com/hashicorp/terraform/config"
     7  )
     8  
     9  // MockEvalContext is a mock version of EvalContext that can be used
    10  // for tests.
    11  type MockEvalContext struct {
    12  	HookCalled bool
    13  	HookHook   Hook
    14  	HookError  error
    15  
    16  	InputCalled bool
    17  	InputInput  UIInput
    18  
    19  	InitProviderCalled   bool
    20  	InitProviderName     string
    21  	InitProviderProvider ResourceProvider
    22  	InitProviderError    error
    23  
    24  	ProviderCalled   bool
    25  	ProviderName     string
    26  	ProviderProvider ResourceProvider
    27  
    28  	CloseProviderCalled   bool
    29  	CloseProviderName     string
    30  	CloseProviderProvider ResourceProvider
    31  
    32  	ProviderInputCalled bool
    33  	ProviderInputName   string
    34  	ProviderInputConfig map[string]interface{}
    35  
    36  	SetProviderInputCalled bool
    37  	SetProviderInputName   string
    38  	SetProviderInputConfig map[string]interface{}
    39  
    40  	ConfigureProviderCalled bool
    41  	ConfigureProviderName   string
    42  	ConfigureProviderConfig *ResourceConfig
    43  	ConfigureProviderError  error
    44  
    45  	SetProviderConfigCalled bool
    46  	SetProviderConfigName   string
    47  	SetProviderConfigConfig *ResourceConfig
    48  
    49  	ParentProviderConfigCalled bool
    50  	ParentProviderConfigName   string
    51  	ParentProviderConfigConfig *ResourceConfig
    52  
    53  	InitProvisionerCalled      bool
    54  	InitProvisionerName        string
    55  	InitProvisionerProvisioner ResourceProvisioner
    56  	InitProvisionerError       error
    57  
    58  	ProvisionerCalled      bool
    59  	ProvisionerName        string
    60  	ProvisionerProvisioner ResourceProvisioner
    61  
    62  	CloseProvisionerCalled      bool
    63  	CloseProvisionerName        string
    64  	CloseProvisionerProvisioner ResourceProvisioner
    65  
    66  	InterpolateCalled       bool
    67  	InterpolateConfig       *config.RawConfig
    68  	InterpolateResource     *Resource
    69  	InterpolateConfigResult *ResourceConfig
    70  	InterpolateError        error
    71  
    72  	PathCalled bool
    73  	PathPath   []string
    74  
    75  	SetVariablesCalled    bool
    76  	SetVariablesModule    string
    77  	SetVariablesVariables map[string]string
    78  
    79  	DiffCalled bool
    80  	DiffDiff   *Diff
    81  	DiffLock   *sync.RWMutex
    82  
    83  	StateCalled bool
    84  	StateState  *State
    85  	StateLock   *sync.RWMutex
    86  }
    87  
    88  func (c *MockEvalContext) Hook(fn func(Hook) (HookAction, error)) error {
    89  	c.HookCalled = true
    90  	if c.HookHook != nil {
    91  		if _, err := fn(c.HookHook); err != nil {
    92  			return err
    93  		}
    94  	}
    95  
    96  	return c.HookError
    97  }
    98  
    99  func (c *MockEvalContext) Input() UIInput {
   100  	c.InputCalled = true
   101  	return c.InputInput
   102  }
   103  
   104  func (c *MockEvalContext) InitProvider(n string) (ResourceProvider, error) {
   105  	c.InitProviderCalled = true
   106  	c.InitProviderName = n
   107  	return c.InitProviderProvider, c.InitProviderError
   108  }
   109  
   110  func (c *MockEvalContext) Provider(n string) ResourceProvider {
   111  	c.ProviderCalled = true
   112  	c.ProviderName = n
   113  	return c.ProviderProvider
   114  }
   115  
   116  func (c *MockEvalContext) CloseProvider(n string) error {
   117  	c.CloseProviderCalled = true
   118  	c.CloseProviderName = n
   119  	return nil
   120  }
   121  
   122  func (c *MockEvalContext) ConfigureProvider(n string, cfg *ResourceConfig) error {
   123  	c.ConfigureProviderCalled = true
   124  	c.ConfigureProviderName = n
   125  	c.ConfigureProviderConfig = cfg
   126  	return c.ConfigureProviderError
   127  }
   128  
   129  func (c *MockEvalContext) SetProviderConfig(
   130  	n string, cfg *ResourceConfig) error {
   131  	c.SetProviderConfigCalled = true
   132  	c.SetProviderConfigName = n
   133  	c.SetProviderConfigConfig = cfg
   134  	return nil
   135  }
   136  
   137  func (c *MockEvalContext) ParentProviderConfig(n string) *ResourceConfig {
   138  	c.ParentProviderConfigCalled = true
   139  	c.ParentProviderConfigName = n
   140  	return c.ParentProviderConfigConfig
   141  }
   142  
   143  func (c *MockEvalContext) ProviderInput(n string) map[string]interface{} {
   144  	c.ProviderInputCalled = true
   145  	c.ProviderInputName = n
   146  	return c.ProviderInputConfig
   147  }
   148  
   149  func (c *MockEvalContext) SetProviderInput(n string, cfg map[string]interface{}) {
   150  	c.SetProviderInputCalled = true
   151  	c.SetProviderInputName = n
   152  	c.SetProviderInputConfig = cfg
   153  }
   154  
   155  func (c *MockEvalContext) InitProvisioner(n string) (ResourceProvisioner, error) {
   156  	c.InitProvisionerCalled = true
   157  	c.InitProvisionerName = n
   158  	return c.InitProvisionerProvisioner, c.InitProvisionerError
   159  }
   160  
   161  func (c *MockEvalContext) Provisioner(n string) ResourceProvisioner {
   162  	c.ProvisionerCalled = true
   163  	c.ProvisionerName = n
   164  	return c.ProvisionerProvisioner
   165  }
   166  
   167  func (c *MockEvalContext) CloseProvisioner(n string) error {
   168  	c.CloseProvisionerCalled = true
   169  	c.CloseProvisionerName = n
   170  	return nil
   171  }
   172  
   173  func (c *MockEvalContext) Interpolate(
   174  	config *config.RawConfig, resource *Resource) (*ResourceConfig, error) {
   175  	c.InterpolateCalled = true
   176  	c.InterpolateConfig = config
   177  	c.InterpolateResource = resource
   178  	return c.InterpolateConfigResult, c.InterpolateError
   179  }
   180  
   181  func (c *MockEvalContext) Path() []string {
   182  	c.PathCalled = true
   183  	return c.PathPath
   184  }
   185  
   186  func (c *MockEvalContext) SetVariables(n string, vs map[string]string) {
   187  	c.SetVariablesCalled = true
   188  	c.SetVariablesModule = n
   189  	c.SetVariablesVariables = vs
   190  }
   191  
   192  func (c *MockEvalContext) Diff() (*Diff, *sync.RWMutex) {
   193  	c.DiffCalled = true
   194  	return c.DiffDiff, c.DiffLock
   195  }
   196  
   197  func (c *MockEvalContext) State() (*State, *sync.RWMutex) {
   198  	c.StateCalled = true
   199  	return c.StateState, c.StateLock
   200  }