github.com/niedbalski/juju@v0.0.0-20190215020005-8ff100488e47/apiserver/common/storagecommon/mock_test.go (about)

     1  // Copyright 2015 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package storagecommon_test
     5  
     6  import (
     7  	"github.com/juju/errors"
     8  	"github.com/juju/testing"
     9  	"gopkg.in/juju/names.v2"
    10  
    11  	"github.com/juju/juju/apiserver/common/storagecommon"
    12  	"github.com/juju/juju/state"
    13  	"github.com/juju/juju/storage"
    14  	"github.com/juju/juju/storage/poolmanager"
    15  )
    16  
    17  type fakeStorage struct {
    18  	testing.Stub
    19  	storagecommon.StorageAccess
    20  	storagecommon.FilesystemAccess
    21  	storageInstance           func(names.StorageTag) (state.StorageInstance, error)
    22  	storageInstanceVolume     func(names.StorageTag) (state.Volume, error)
    23  	storageInstanceFilesystem func(names.StorageTag) (state.Filesystem, error)
    24  	volumeAttachment          func(names.Tag, names.VolumeTag) (state.VolumeAttachment, error)
    25  	volumeAttachmentPlan      func(names.Tag, names.VolumeTag) (state.VolumeAttachmentPlan, error)
    26  	filesystemAttachment      func(names.Tag, names.FilesystemTag) (state.FilesystemAttachment, error)
    27  	blockDevices              func(names.MachineTag) ([]state.BlockDeviceInfo, error)
    28  }
    29  
    30  func (s *fakeStorage) StorageInstance(tag names.StorageTag) (state.StorageInstance, error) {
    31  	s.MethodCall(s, "StorageInstance", tag)
    32  	return s.storageInstance(tag)
    33  }
    34  
    35  func (s *fakeStorage) StorageInstanceVolume(tag names.StorageTag) (state.Volume, error) {
    36  	s.MethodCall(s, "StorageInstanceVolume", tag)
    37  	return s.storageInstanceVolume(tag)
    38  }
    39  
    40  func (s *fakeStorage) VolumeAttachment(m names.Tag, v names.VolumeTag) (state.VolumeAttachment, error) {
    41  	s.MethodCall(s, "VolumeAttachment", m, v)
    42  	return s.volumeAttachment(m, v)
    43  }
    44  
    45  func (s *fakeStorage) VolumeAttachmentPlan(host names.Tag, volume names.VolumeTag) (state.VolumeAttachmentPlan, error) {
    46  	s.MethodCall(s, "VolumeAttachmentPlan", host, volume)
    47  	return s.volumeAttachmentPlan(host, volume)
    48  }
    49  
    50  func (s *fakeStorage) BlockDevices(m names.MachineTag) ([]state.BlockDeviceInfo, error) {
    51  	s.MethodCall(s, "BlockDevices", m)
    52  	return s.blockDevices(m)
    53  }
    54  
    55  func (s *fakeStorage) StorageInstanceFilesystem(tag names.StorageTag) (state.Filesystem, error) {
    56  	s.MethodCall(s, "StorageInstanceFilesystem", tag)
    57  	return s.storageInstanceFilesystem(tag)
    58  }
    59  
    60  func (s *fakeStorage) FilesystemAttachment(m names.Tag, fs names.FilesystemTag) (state.FilesystemAttachment, error) {
    61  	s.MethodCall(s, "FilesystemAttachment", m, fs)
    62  	return s.filesystemAttachment(m, fs)
    63  }
    64  
    65  type fakeStorageInstance struct {
    66  	state.StorageInstance
    67  	tag   names.StorageTag
    68  	owner names.Tag
    69  	kind  state.StorageKind
    70  }
    71  
    72  func (i *fakeStorageInstance) StorageTag() names.StorageTag {
    73  	return i.tag
    74  }
    75  
    76  func (i *fakeStorageInstance) Tag() names.Tag {
    77  	return i.tag
    78  }
    79  
    80  func (i *fakeStorageInstance) Owner() (names.Tag, bool) {
    81  	return i.owner, i.owner != nil
    82  }
    83  
    84  func (i *fakeStorageInstance) Kind() state.StorageKind {
    85  	return i.kind
    86  }
    87  
    88  type fakeStorageAttachment struct {
    89  	state.StorageAttachment
    90  	storageTag names.StorageTag
    91  }
    92  
    93  func (a *fakeStorageAttachment) StorageInstance() names.StorageTag {
    94  	return a.storageTag
    95  }
    96  
    97  type fakeVolume struct {
    98  	state.Volume
    99  	tag    names.VolumeTag
   100  	params *state.VolumeParams
   101  	info   *state.VolumeInfo
   102  }
   103  
   104  func (v *fakeVolume) VolumeTag() names.VolumeTag {
   105  	return v.tag
   106  }
   107  
   108  func (v *fakeVolume) Tag() names.Tag {
   109  	return v.tag
   110  }
   111  
   112  func (v *fakeVolume) Params() (state.VolumeParams, bool) {
   113  	if v.params == nil {
   114  		return state.VolumeParams{}, false
   115  	}
   116  	return *v.params, true
   117  }
   118  
   119  func (v *fakeVolume) Info() (state.VolumeInfo, error) {
   120  	if v.info == nil {
   121  		return state.VolumeInfo{}, errors.NotProvisionedf("volume %v", v.tag.Id())
   122  	}
   123  	return *v.info, nil
   124  }
   125  
   126  type fakeVolumeAttachment struct {
   127  	state.VolumeAttachment
   128  	info *state.VolumeAttachmentInfo
   129  }
   130  
   131  func (v *fakeVolumeAttachment) Info() (state.VolumeAttachmentInfo, error) {
   132  	if v.info == nil {
   133  		return state.VolumeAttachmentInfo{}, errors.NotProvisionedf("volume attachment")
   134  	}
   135  	return *v.info, nil
   136  }
   137  
   138  type fakeVolumeAttachmentPlan struct {
   139  	state.VolumeAttachmentPlan
   140  	blockInfo *state.BlockDeviceInfo
   141  	err       error
   142  }
   143  
   144  func (p *fakeVolumeAttachmentPlan) BlockDeviceInfo() (state.BlockDeviceInfo, error) {
   145  	if p.blockInfo == nil {
   146  		return state.BlockDeviceInfo{}, p.err
   147  	}
   148  	return *p.blockInfo, p.err
   149  }
   150  
   151  type fakePoolManager struct {
   152  	poolmanager.PoolManager
   153  }
   154  
   155  func (pm *fakePoolManager) Get(name string) (*storage.Config, error) {
   156  	return nil, errors.NotFoundf("pool")
   157  }
   158  
   159  type fakeFilesystem struct {
   160  	state.Filesystem
   161  	tag    names.FilesystemTag
   162  	params *state.FilesystemParams
   163  	info   *state.FilesystemInfo
   164  }
   165  
   166  func (v *fakeFilesystem) FilesystemTag() names.FilesystemTag {
   167  	return v.tag
   168  }
   169  
   170  func (v *fakeFilesystem) Tag() names.Tag {
   171  	return v.tag
   172  }
   173  
   174  func (v *fakeFilesystem) Params() (state.FilesystemParams, bool) {
   175  	if v.params == nil {
   176  		return state.FilesystemParams{}, false
   177  	}
   178  	return *v.params, true
   179  }
   180  
   181  func (v *fakeFilesystem) Info() (state.FilesystemInfo, error) {
   182  	if v.info == nil {
   183  		return state.FilesystemInfo{}, errors.NotProvisionedf("filesystem %v", v.tag.Id())
   184  	}
   185  	return *v.info, nil
   186  }
   187  
   188  type fakeFilesystemAttachment struct {
   189  	state.FilesystemAttachment
   190  	info *state.FilesystemAttachmentInfo
   191  }
   192  
   193  func (v *fakeFilesystemAttachment) Info() (state.FilesystemAttachmentInfo, error) {
   194  	if v.info == nil {
   195  		return state.FilesystemAttachmentInfo{}, errors.NotProvisionedf("filesystem attachment")
   196  	}
   197  	return *v.info, nil
   198  }