github.com/niedbalski/juju@v0.0.0-20190215020005-8ff100488e47/apiserver/facades/agent/uniter/mock_test.go (about) 1 // Copyright 2015 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package uniter_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/facades/agent/uniter" 12 "github.com/juju/juju/state" 13 ) 14 15 type fakeStorage struct { 16 testing.Stub 17 uniter.StorageStateInterface 18 uniter.StorageFilesystemInterface 19 storageInstance func(names.StorageTag) (state.StorageInstance, error) 20 storageInstanceVolume func(names.StorageTag) (state.Volume, error) 21 volumeAttachment func(names.Tag, names.VolumeTag) (state.VolumeAttachment, error) 22 volumeAttachmentPlan func(names.Tag, names.VolumeTag) (state.VolumeAttachmentPlan, error) 23 blockDevices func(names.MachineTag) ([]state.BlockDeviceInfo, error) 24 watchVolumeAttachment func(names.Tag, names.VolumeTag) state.NotifyWatcher 25 watchBlockDevices func(names.MachineTag) state.NotifyWatcher 26 watchStorageAttachment func(names.StorageTag, names.UnitTag) state.NotifyWatcher 27 } 28 29 func (s *fakeStorage) StorageInstance(tag names.StorageTag) (state.StorageInstance, error) { 30 s.MethodCall(s, "StorageInstance", tag) 31 return s.storageInstance(tag) 32 } 33 34 func (s *fakeStorage) StorageInstanceVolume(tag names.StorageTag) (state.Volume, error) { 35 s.MethodCall(s, "StorageInstanceVolume", tag) 36 return s.storageInstanceVolume(tag) 37 } 38 39 func (s *fakeStorage) VolumeAttachment(m names.Tag, v names.VolumeTag) (state.VolumeAttachment, error) { 40 s.MethodCall(s, "VolumeAttachment", m, v) 41 return s.volumeAttachment(m, v) 42 } 43 44 func (s *fakeStorage) VolumeAttachmentPlan(host names.Tag, volume names.VolumeTag) (state.VolumeAttachmentPlan, error) { 45 s.MethodCall(s, "VolumeAttachmentPlan", host, volume) 46 return s.volumeAttachmentPlan(host, volume) 47 } 48 49 func (s *fakeStorage) BlockDevices(m names.MachineTag) ([]state.BlockDeviceInfo, error) { 50 s.MethodCall(s, "BlockDevices", m) 51 return s.blockDevices(m) 52 } 53 54 func (s *fakeStorage) WatchVolumeAttachment(host names.Tag, v names.VolumeTag) state.NotifyWatcher { 55 s.MethodCall(s, "WatchVolumeAttachment", host, v) 56 return s.watchVolumeAttachment(host, v) 57 } 58 59 func (s *fakeStorage) WatchBlockDevices(m names.MachineTag) state.NotifyWatcher { 60 s.MethodCall(s, "WatchBlockDevices", m) 61 return s.watchBlockDevices(m) 62 } 63 64 func (s *fakeStorage) WatchStorageAttachment(st names.StorageTag, u names.UnitTag) state.NotifyWatcher { 65 s.MethodCall(s, "WatchStorageAttachment", st, u) 66 return s.watchStorageAttachment(st, u) 67 } 68 69 type fakeStorageInstance struct { 70 state.StorageInstance 71 tag names.StorageTag 72 owner names.Tag 73 kind state.StorageKind 74 } 75 76 func (i *fakeStorageInstance) StorageTag() names.StorageTag { 77 return i.tag 78 } 79 80 func (i *fakeStorageInstance) Tag() names.Tag { 81 return i.tag 82 } 83 84 func (i *fakeStorageInstance) Owner() (names.Tag, bool) { 85 return i.owner, i.owner != nil 86 } 87 88 func (i *fakeStorageInstance) Kind() state.StorageKind { 89 return i.kind 90 } 91 92 type fakeVolume struct { 93 state.Volume 94 tag names.VolumeTag 95 params *state.VolumeParams 96 info *state.VolumeInfo 97 } 98 99 func (v *fakeVolume) VolumeTag() names.VolumeTag { 100 return v.tag 101 } 102 103 func (v *fakeVolume) Tag() names.Tag { 104 return v.tag 105 } 106 107 func (v *fakeVolume) Params() (state.VolumeParams, bool) { 108 if v.params == nil { 109 return state.VolumeParams{}, false 110 } 111 return *v.params, true 112 } 113 114 func (v *fakeVolume) Info() (state.VolumeInfo, error) { 115 if v.info == nil { 116 return state.VolumeInfo{}, errors.NotProvisionedf("volume %v", v.tag.Id()) 117 } 118 return *v.info, nil 119 } 120 121 type nopSyncStarter struct{} 122 123 func (nopSyncStarter) StartSync() {}