github.com/cloud-green/juju@v0.0.0-20151002100041-a00291338d3d/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/names"
     9  	"github.com/juju/testing"
    10  	"launchpad.net/tomb"
    11  
    12  	"github.com/juju/juju/apiserver/common/storagecommon"
    13  	"github.com/juju/juju/state"
    14  	"github.com/juju/juju/storage"
    15  	"github.com/juju/juju/storage/poolmanager"
    16  )
    17  
    18  type fakeStorage struct {
    19  	testing.Stub
    20  	storagecommon.StorageInterface
    21  	storageInstance        func(names.StorageTag) (state.StorageInstance, error)
    22  	storageInstanceVolume  func(names.StorageTag) (state.Volume, error)
    23  	volumeAttachment       func(names.MachineTag, names.VolumeTag) (state.VolumeAttachment, error)
    24  	blockDevices           func(names.MachineTag) ([]state.BlockDeviceInfo, error)
    25  	watchVolumeAttachment  func(names.MachineTag, names.VolumeTag) state.NotifyWatcher
    26  	watchBlockDevices      func(names.MachineTag) state.NotifyWatcher
    27  	watchStorageAttachment func(names.StorageTag, names.UnitTag) state.NotifyWatcher
    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.MachineTag, 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) BlockDevices(m names.MachineTag) ([]state.BlockDeviceInfo, error) {
    46  	s.MethodCall(s, "BlockDevices", m)
    47  	return s.blockDevices(m)
    48  }
    49  
    50  func (s *fakeStorage) WatchVolumeAttachment(m names.MachineTag, v names.VolumeTag) state.NotifyWatcher {
    51  	s.MethodCall(s, "WatchVolumeAttachment", m, v)
    52  	return s.watchVolumeAttachment(m, v)
    53  }
    54  
    55  func (s *fakeStorage) WatchBlockDevices(m names.MachineTag) state.NotifyWatcher {
    56  	s.MethodCall(s, "WatchBlockDevices", m)
    57  	return s.watchBlockDevices(m)
    58  }
    59  
    60  func (s *fakeStorage) WatchStorageAttachment(st names.StorageTag, u names.UnitTag) state.NotifyWatcher {
    61  	s.MethodCall(s, "WatchStorageAttachment", st, u)
    62  	return s.watchStorageAttachment(st, u)
    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 {
    81  	return i.owner
    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 fakePoolManager struct {
   139  	poolmanager.PoolManager
   140  }
   141  
   142  func (pm *fakePoolManager) Get(name string) (*storage.Config, error) {
   143  	return nil, errors.NotFoundf("pool")
   144  }
   145  
   146  type fakeNotifyWatcher struct {
   147  	tomb.Tomb
   148  	ch chan struct{}
   149  }
   150  
   151  func (w *fakeNotifyWatcher) Kill() {
   152  	w.Tomb.Kill(nil)
   153  	w.Tomb.Done()
   154  }
   155  
   156  func (w *fakeNotifyWatcher) Stop() error {
   157  	w.Kill()
   158  	return w.Wait()
   159  }
   160  
   161  func (w *fakeNotifyWatcher) Changes() <-chan struct{} {
   162  	return w.ch
   163  }
   164  
   165  type nopSyncStarter struct{}
   166  
   167  func (nopSyncStarter) StartSync() {}