github.com/mwhudson/juju@v0.0.0-20160512215208-90ff01f3497f/storage/provider/dummy/provider.go (about)

     1  // Copyright 2015 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package dummy
     5  
     6  import (
     7  	"github.com/juju/errors"
     8  	"github.com/juju/testing"
     9  
    10  	"github.com/juju/juju/environs/config"
    11  	"github.com/juju/juju/storage"
    12  )
    13  
    14  var _ storage.Provider = (*StorageProvider)(nil)
    15  
    16  // StorageProvider is an implementation of storage.Provider, suitable for testing.
    17  // Each method's default behaviour may be overridden by setting the corresponding
    18  // Func field.
    19  type StorageProvider struct {
    20  	testing.Stub
    21  
    22  	// StorageScope defines the scope of storage managed by this provider.
    23  	StorageScope storage.Scope
    24  
    25  	// IsDynamic defines whether or not the provider reports that it supports
    26  	// dynamic provisioning.
    27  	IsDynamic bool
    28  
    29  	// VolumeSourceFunc will be called by VolumeSource, if non-nil;
    30  	// otherwise VolumeSource will return a NotSupported error.
    31  	VolumeSourceFunc func(*config.Config, *storage.Config) (storage.VolumeSource, error)
    32  
    33  	// FilesystemSourceFunc will be called by FilesystemSource, if non-nil;
    34  	// otherwise FilesystemSource will return a NotSupported error.
    35  	FilesystemSourceFunc func(*config.Config, *storage.Config) (storage.FilesystemSource, error)
    36  
    37  	// ValidateConfigFunc will be called by ValidateConfig, if non-nil;
    38  	// otherwise ValidateConfig returns nil.
    39  	ValidateConfigFunc func(*storage.Config) error
    40  
    41  	// SupportsFunc will be called by Supports, if non-nil; otherwise,
    42  	// Supports returns true.
    43  	SupportsFunc func(kind storage.StorageKind) bool
    44  }
    45  
    46  // VolumeSource is defined on storage.Provider.
    47  func (p *StorageProvider) VolumeSource(environConfig *config.Config, providerConfig *storage.Config) (storage.VolumeSource, error) {
    48  	p.MethodCall(p, "VolumeSource", environConfig, providerConfig)
    49  	if p.VolumeSourceFunc != nil {
    50  		return p.VolumeSourceFunc(environConfig, providerConfig)
    51  	}
    52  	return nil, errors.NotSupportedf("volumes")
    53  }
    54  
    55  // FilesystemSource is defined on storage.Provider.
    56  func (p *StorageProvider) FilesystemSource(environConfig *config.Config, providerConfig *storage.Config) (storage.FilesystemSource, error) {
    57  	p.MethodCall(p, "FilesystemSource", environConfig, providerConfig)
    58  	if p.FilesystemSourceFunc != nil {
    59  		return p.FilesystemSourceFunc(environConfig, providerConfig)
    60  	}
    61  	return nil, errors.NotSupportedf("filesystems")
    62  }
    63  
    64  // ValidateConfig is defined on storage.Provider.
    65  func (p *StorageProvider) ValidateConfig(providerConfig *storage.Config) error {
    66  	p.MethodCall(p, "ValidateConfig", providerConfig)
    67  	if p.ValidateConfigFunc != nil {
    68  		return p.ValidateConfigFunc(providerConfig)
    69  	}
    70  	return nil
    71  }
    72  
    73  // Supports is defined on storage.Provider.
    74  func (p *StorageProvider) Supports(kind storage.StorageKind) bool {
    75  	p.MethodCall(p, "Supports", kind)
    76  	if p.SupportsFunc != nil {
    77  		return p.SupportsFunc(kind)
    78  	}
    79  	return true
    80  }
    81  
    82  // Scope is defined on storage.Provider.
    83  func (p *StorageProvider) Scope() storage.Scope {
    84  	p.MethodCall(p, "Scope")
    85  	return p.StorageScope
    86  }
    87  
    88  // Dynamic is defined on storage.Provider.
    89  func (p *StorageProvider) Dynamic() bool {
    90  	p.MethodCall(p, "Dynamic")
    91  	return p.IsDynamic
    92  }