github.com/niedbalski/juju@v0.0.0-20190215020005-8ff100488e47/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/storage"
    11  )
    12  
    13  var _ storage.Provider = (*StorageProvider)(nil)
    14  
    15  // StorageProvider is an implementation of storage.Provider, suitable for testing.
    16  // Each method's default behaviour may be overridden by setting the corresponding
    17  // Func field.
    18  type StorageProvider struct {
    19  	testing.Stub
    20  
    21  	// StorageScope defines the scope of storage managed by this provider.
    22  	StorageScope storage.Scope
    23  
    24  	// IsDynamic defines whether or not the provider reports that it supports
    25  	// dynamic provisioning.
    26  	IsDynamic bool
    27  
    28  	// IsReleasable defines whether or not the provider reports that it
    29  	// supports releasing storage.
    30  	IsReleasable bool
    31  
    32  	// DefaultPools_ will be returned by DefaultPools.
    33  	DefaultPools_ []*storage.Config
    34  
    35  	// VolumeSourceFunc will be called by VolumeSource, if non-nil;
    36  	// otherwise VolumeSource will return a NotSupported error.
    37  	VolumeSourceFunc func(*storage.Config) (storage.VolumeSource, error)
    38  
    39  	// FilesystemSourceFunc will be called by FilesystemSource, if non-nil;
    40  	// otherwise FilesystemSource will return a NotSupported error.
    41  	FilesystemSourceFunc func(*storage.Config) (storage.FilesystemSource, error)
    42  
    43  	// ValidateConfigFunc will be called by ValidateConfig, if non-nil;
    44  	// otherwise ValidateConfig returns nil.
    45  	ValidateConfigFunc func(*storage.Config) error
    46  
    47  	// SupportsFunc will be called by Supports, if non-nil; otherwise,
    48  	// Supports returns true.
    49  	SupportsFunc func(kind storage.StorageKind) bool
    50  }
    51  
    52  // VolumeSource is defined on storage.Provider.
    53  func (p *StorageProvider) VolumeSource(providerConfig *storage.Config) (storage.VolumeSource, error) {
    54  	p.MethodCall(p, "VolumeSource", providerConfig)
    55  	if p.VolumeSourceFunc != nil {
    56  		return p.VolumeSourceFunc(providerConfig)
    57  	}
    58  	return nil, errors.NotSupportedf("volumes")
    59  }
    60  
    61  // FilesystemSource is defined on storage.Provider.
    62  func (p *StorageProvider) FilesystemSource(providerConfig *storage.Config) (storage.FilesystemSource, error) {
    63  	p.MethodCall(p, "FilesystemSource", providerConfig)
    64  	if p.FilesystemSourceFunc != nil {
    65  		return p.FilesystemSourceFunc(providerConfig)
    66  	}
    67  	return nil, errors.NotSupportedf("filesystems")
    68  }
    69  
    70  // ValidateConfig is defined on storage.Provider.
    71  func (p *StorageProvider) ValidateConfig(providerConfig *storage.Config) error {
    72  	p.MethodCall(p, "ValidateConfig", providerConfig)
    73  	if p.ValidateConfigFunc != nil {
    74  		return p.ValidateConfigFunc(providerConfig)
    75  	}
    76  	return nil
    77  }
    78  
    79  // Supports is defined on storage.Provider.
    80  func (p *StorageProvider) Supports(kind storage.StorageKind) bool {
    81  	p.MethodCall(p, "Supports", kind)
    82  	if p.SupportsFunc != nil {
    83  		return p.SupportsFunc(kind)
    84  	}
    85  	return true
    86  }
    87  
    88  // Scope is defined on storage.Provider.
    89  func (p *StorageProvider) Scope() storage.Scope {
    90  	p.MethodCall(p, "Scope")
    91  	return p.StorageScope
    92  }
    93  
    94  // Dynamic is defined on storage.Provider.
    95  func (p *StorageProvider) Dynamic() bool {
    96  	p.MethodCall(p, "Dynamic")
    97  	return p.IsDynamic
    98  }
    99  
   100  // Releasable is defined on storage.Provider.
   101  func (p *StorageProvider) Releasable() bool {
   102  	p.MethodCall(p, "Releasable")
   103  	return p.IsReleasable
   104  }
   105  
   106  // DefaultPool is defined on storage.Provider.
   107  func (p *StorageProvider) DefaultPools() []*storage.Config {
   108  	p.MethodCall(p, "DefaultPools")
   109  	return p.DefaultPools_
   110  }