github.com/axw/juju@v0.0.0-20161005053422-4bd6544d08d4/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  	// DefaultPools_ will be returned by DefaultPools.
    29  	DefaultPools_ []*storage.Config
    30  
    31  	// VolumeSourceFunc will be called by VolumeSource, if non-nil;
    32  	// otherwise VolumeSource will return a NotSupported error.
    33  	VolumeSourceFunc func(*storage.Config) (storage.VolumeSource, error)
    34  
    35  	// FilesystemSourceFunc will be called by FilesystemSource, if non-nil;
    36  	// otherwise FilesystemSource will return a NotSupported error.
    37  	FilesystemSourceFunc func(*storage.Config) (storage.FilesystemSource, error)
    38  
    39  	// ValidateConfigFunc will be called by ValidateConfig, if non-nil;
    40  	// otherwise ValidateConfig returns nil.
    41  	ValidateConfigFunc func(*storage.Config) error
    42  
    43  	// SupportsFunc will be called by Supports, if non-nil; otherwise,
    44  	// Supports returns true.
    45  	SupportsFunc func(kind storage.StorageKind) bool
    46  }
    47  
    48  // VolumeSource is defined on storage.Provider.
    49  func (p *StorageProvider) VolumeSource(providerConfig *storage.Config) (storage.VolumeSource, error) {
    50  	p.MethodCall(p, "VolumeSource", providerConfig)
    51  	if p.VolumeSourceFunc != nil {
    52  		return p.VolumeSourceFunc(providerConfig)
    53  	}
    54  	return nil, errors.NotSupportedf("volumes")
    55  }
    56  
    57  // FilesystemSource is defined on storage.Provider.
    58  func (p *StorageProvider) FilesystemSource(providerConfig *storage.Config) (storage.FilesystemSource, error) {
    59  	p.MethodCall(p, "FilesystemSource", providerConfig)
    60  	if p.FilesystemSourceFunc != nil {
    61  		return p.FilesystemSourceFunc(providerConfig)
    62  	}
    63  	return nil, errors.NotSupportedf("filesystems")
    64  }
    65  
    66  // ValidateConfig is defined on storage.Provider.
    67  func (p *StorageProvider) ValidateConfig(providerConfig *storage.Config) error {
    68  	p.MethodCall(p, "ValidateConfig", providerConfig)
    69  	if p.ValidateConfigFunc != nil {
    70  		return p.ValidateConfigFunc(providerConfig)
    71  	}
    72  	return nil
    73  }
    74  
    75  // Supports is defined on storage.Provider.
    76  func (p *StorageProvider) Supports(kind storage.StorageKind) bool {
    77  	p.MethodCall(p, "Supports", kind)
    78  	if p.SupportsFunc != nil {
    79  		return p.SupportsFunc(kind)
    80  	}
    81  	return true
    82  }
    83  
    84  // Scope is defined on storage.Provider.
    85  func (p *StorageProvider) Scope() storage.Scope {
    86  	p.MethodCall(p, "Scope")
    87  	return p.StorageScope
    88  }
    89  
    90  // Dynamic is defined on storage.Provider.
    91  func (p *StorageProvider) Dynamic() bool {
    92  	p.MethodCall(p, "Dynamic")
    93  	return p.IsDynamic
    94  }
    95  
    96  // DefaultPool is defined on storage.Provider.
    97  func (p *StorageProvider) DefaultPools() []*storage.Config {
    98  	p.MethodCall(p, "DefaultPools")
    99  	return p.DefaultPools_
   100  }