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