github.com/cloud-green/juju@v0.0.0-20151002100041-a00291338d3d/apiserver/storage/mock_test.go (about) 1 // Copyright 2015 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package storage_test 5 6 import ( 7 "github.com/juju/errors" 8 "github.com/juju/names" 9 "gopkg.in/juju/charm.v6-unstable" 10 11 "github.com/juju/juju/state" 12 jujustorage "github.com/juju/juju/storage" 13 ) 14 15 type mockPoolManager struct { 16 getPool func(name string) (*jujustorage.Config, error) 17 createPool func(name string, providerType jujustorage.ProviderType, attrs map[string]interface{}) (*jujustorage.Config, error) 18 deletePool func(name string) error 19 listPools func() ([]*jujustorage.Config, error) 20 } 21 22 func (m *mockPoolManager) Get(name string) (*jujustorage.Config, error) { 23 return m.getPool(name) 24 } 25 26 func (m *mockPoolManager) Create(name string, providerType jujustorage.ProviderType, attrs map[string]interface{}) (*jujustorage.Config, error) { 27 return m.createPool(name, providerType, attrs) 28 } 29 30 func (m *mockPoolManager) Delete(name string) error { 31 return m.deletePool(name) 32 } 33 34 func (m *mockPoolManager) List() ([]*jujustorage.Config, error) { 35 return m.listPools() 36 } 37 38 type mockState struct { 39 storageInstance func(names.StorageTag) (state.StorageInstance, error) 40 allStorageInstances func() ([]state.StorageInstance, error) 41 storageInstanceAttachments func(names.StorageTag) ([]state.StorageAttachment, error) 42 unitAssignedMachine func(u names.UnitTag) (names.MachineTag, error) 43 storageInstanceVolume func(names.StorageTag) (state.Volume, error) 44 volumeAttachment func(names.MachineTag, names.VolumeTag) (state.VolumeAttachment, error) 45 storageInstanceFilesystem func(names.StorageTag) (state.Filesystem, error) 46 storageInstanceFilesystemAttachment func(m names.MachineTag, f names.FilesystemTag) (state.FilesystemAttachment, error) 47 watchStorageAttachment func(names.StorageTag, names.UnitTag) state.NotifyWatcher 48 watchFilesystemAttachment func(names.MachineTag, names.FilesystemTag) state.NotifyWatcher 49 watchVolumeAttachment func(names.MachineTag, names.VolumeTag) state.NotifyWatcher 50 watchBlockDevices func(names.MachineTag) state.NotifyWatcher 51 envName string 52 volume func(tag names.VolumeTag) (state.Volume, error) 53 machineVolumeAttachments func(machine names.MachineTag) ([]state.VolumeAttachment, error) 54 volumeAttachments func(volume names.VolumeTag) ([]state.VolumeAttachment, error) 55 allVolumes func() ([]state.Volume, error) 56 filesystem func(tag names.FilesystemTag) (state.Filesystem, error) 57 machineFilesystemAttachments func(machine names.MachineTag) ([]state.FilesystemAttachment, error) 58 filesystemAttachments func(filesystem names.FilesystemTag) ([]state.FilesystemAttachment, error) 59 allFilesystems func() ([]state.Filesystem, error) 60 addStorageForUnit func(u names.UnitTag, name string, cons state.StorageConstraints) error 61 getBlockForType func(t state.BlockType) (state.Block, bool, error) 62 blockDevices func(names.MachineTag) ([]state.BlockDeviceInfo, error) 63 } 64 65 func (st *mockState) StorageInstance(s names.StorageTag) (state.StorageInstance, error) { 66 return st.storageInstance(s) 67 } 68 69 func (st *mockState) AllStorageInstances() ([]state.StorageInstance, error) { 70 return st.allStorageInstances() 71 } 72 73 func (st *mockState) StorageAttachments(tag names.StorageTag) ([]state.StorageAttachment, error) { 74 return st.storageInstanceAttachments(tag) 75 } 76 77 func (st *mockState) UnitAssignedMachine(unit names.UnitTag) (names.MachineTag, error) { 78 return st.unitAssignedMachine(unit) 79 } 80 81 func (st *mockState) FilesystemAttachment(m names.MachineTag, f names.FilesystemTag) (state.FilesystemAttachment, error) { 82 return st.storageInstanceFilesystemAttachment(m, f) 83 } 84 85 func (st *mockState) StorageInstanceFilesystem(s names.StorageTag) (state.Filesystem, error) { 86 return st.storageInstanceFilesystem(s) 87 } 88 89 func (st *mockState) StorageInstanceVolume(s names.StorageTag) (state.Volume, error) { 90 return st.storageInstanceVolume(s) 91 } 92 93 func (st *mockState) VolumeAttachment(m names.MachineTag, v names.VolumeTag) (state.VolumeAttachment, error) { 94 return st.volumeAttachment(m, v) 95 } 96 97 func (st *mockState) WatchStorageAttachment(s names.StorageTag, u names.UnitTag) state.NotifyWatcher { 98 return st.watchStorageAttachment(s, u) 99 } 100 101 func (st *mockState) WatchFilesystemAttachment(mtag names.MachineTag, f names.FilesystemTag) state.NotifyWatcher { 102 return st.watchFilesystemAttachment(mtag, f) 103 } 104 105 func (st *mockState) WatchVolumeAttachment(mtag names.MachineTag, v names.VolumeTag) state.NotifyWatcher { 106 return st.watchVolumeAttachment(mtag, v) 107 } 108 109 func (st *mockState) WatchBlockDevices(mtag names.MachineTag) state.NotifyWatcher { 110 return st.watchBlockDevices(mtag) 111 } 112 113 func (st *mockState) EnvName() (string, error) { 114 return st.envName, nil 115 } 116 117 func (st *mockState) AllVolumes() ([]state.Volume, error) { 118 return st.allVolumes() 119 } 120 121 func (st *mockState) VolumeAttachments(volume names.VolumeTag) ([]state.VolumeAttachment, error) { 122 return st.volumeAttachments(volume) 123 } 124 125 func (st *mockState) MachineVolumeAttachments(machine names.MachineTag) ([]state.VolumeAttachment, error) { 126 return st.machineVolumeAttachments(machine) 127 } 128 129 func (st *mockState) Volume(tag names.VolumeTag) (state.Volume, error) { 130 return st.volume(tag) 131 } 132 133 func (st *mockState) AllFilesystems() ([]state.Filesystem, error) { 134 return st.allFilesystems() 135 } 136 137 func (st *mockState) FilesystemAttachments(filesystem names.FilesystemTag) ([]state.FilesystemAttachment, error) { 138 return st.filesystemAttachments(filesystem) 139 } 140 141 func (st *mockState) MachineFilesystemAttachments(machine names.MachineTag) ([]state.FilesystemAttachment, error) { 142 return st.machineFilesystemAttachments(machine) 143 } 144 145 func (st *mockState) Filesystem(tag names.FilesystemTag) (state.Filesystem, error) { 146 return st.filesystem(tag) 147 } 148 149 func (st *mockState) AddStorageForUnit(u names.UnitTag, name string, cons state.StorageConstraints) error { 150 return st.addStorageForUnit(u, name, cons) 151 } 152 153 func (st *mockState) GetBlockForType(t state.BlockType) (state.Block, bool, error) { 154 return st.getBlockForType(t) 155 } 156 157 func (st *mockState) BlockDevices(m names.MachineTag) ([]state.BlockDeviceInfo, error) { 158 if st.blockDevices != nil { 159 return st.blockDevices(m) 160 } 161 return []state.BlockDeviceInfo{}, nil 162 } 163 164 type mockNotifyWatcher struct { 165 state.NotifyWatcher 166 changes chan struct{} 167 } 168 169 func (m *mockNotifyWatcher) Changes() <-chan struct{} { 170 return m.changes 171 } 172 173 type mockVolume struct { 174 state.Volume 175 tag names.VolumeTag 176 storage *names.StorageTag 177 info *state.VolumeInfo 178 } 179 180 func (m *mockVolume) StorageInstance() (names.StorageTag, error) { 181 if m.storage != nil { 182 return *m.storage, nil 183 } 184 return names.StorageTag{}, errors.NewNotAssigned(nil, "error from mock") 185 } 186 187 func (m *mockVolume) VolumeTag() names.VolumeTag { 188 return m.tag 189 } 190 191 func (m *mockVolume) Params() (state.VolumeParams, bool) { 192 return state.VolumeParams{ 193 Pool: "loop", 194 Size: 1024, 195 }, true 196 } 197 198 func (m *mockVolume) Info() (state.VolumeInfo, error) { 199 if m.info != nil { 200 return *m.info, nil 201 } 202 return state.VolumeInfo{}, errors.NotProvisionedf("%v", m.tag) 203 } 204 205 func (m *mockVolume) Status() (state.StatusInfo, error) { 206 return state.StatusInfo{Status: state.StatusAttached}, nil 207 } 208 209 type mockFilesystem struct { 210 state.Filesystem 211 tag names.FilesystemTag 212 storage *names.StorageTag 213 volume *names.VolumeTag 214 info *state.FilesystemInfo 215 } 216 217 func (m *mockFilesystem) Storage() (names.StorageTag, error) { 218 if m.storage != nil { 219 return *m.storage, nil 220 } 221 return names.StorageTag{}, errors.NewNotAssigned(nil, "error from mock") 222 } 223 224 func (m *mockFilesystem) FilesystemTag() names.FilesystemTag { 225 return m.tag 226 } 227 228 func (m *mockFilesystem) Volume() (names.VolumeTag, error) { 229 if m.volume != nil { 230 return *m.volume, nil 231 } 232 return names.VolumeTag{}, state.ErrNoBackingVolume 233 } 234 235 func (m *mockFilesystem) Info() (state.FilesystemInfo, error) { 236 if m.info != nil { 237 return *m.info, nil 238 } 239 return state.FilesystemInfo{}, errors.NotProvisionedf("filesystem") 240 } 241 242 func (m *mockFilesystem) Status() (state.StatusInfo, error) { 243 return state.StatusInfo{Status: state.StatusAttached}, nil 244 } 245 246 type mockFilesystemAttachment struct { 247 state.FilesystemAttachment 248 filesystem names.FilesystemTag 249 machine names.MachineTag 250 info *state.FilesystemAttachmentInfo 251 } 252 253 func (m *mockFilesystemAttachment) Filesystem() names.FilesystemTag { 254 return m.filesystem 255 } 256 257 func (m *mockFilesystemAttachment) Machine() names.MachineTag { 258 return m.machine 259 } 260 261 func (m *mockFilesystemAttachment) Info() (state.FilesystemAttachmentInfo, error) { 262 if m.info != nil { 263 return *m.info, nil 264 } 265 return state.FilesystemAttachmentInfo{}, errors.NotProvisionedf("filesystem attachment") 266 } 267 268 type mockStorageInstance struct { 269 state.StorageInstance 270 kind state.StorageKind 271 owner names.Tag 272 storageTag names.Tag 273 } 274 275 func (m *mockStorageInstance) Kind() state.StorageKind { 276 return m.kind 277 } 278 279 func (m *mockStorageInstance) Owner() names.Tag { 280 return m.owner 281 } 282 283 func (m *mockStorageInstance) Tag() names.Tag { 284 return m.storageTag 285 } 286 287 func (m *mockStorageInstance) StorageTag() names.StorageTag { 288 return m.storageTag.(names.StorageTag) 289 } 290 291 func (m *mockStorageInstance) CharmURL() *charm.URL { 292 panic("not implemented for test") 293 } 294 295 type mockStorageAttachment struct { 296 state.StorageAttachment 297 storage *mockStorageInstance 298 } 299 300 func (m *mockStorageAttachment) StorageInstance() names.StorageTag { 301 return m.storage.Tag().(names.StorageTag) 302 } 303 304 func (m *mockStorageAttachment) Unit() names.UnitTag { 305 return m.storage.Owner().(names.UnitTag) 306 } 307 308 type mockVolumeAttachment struct { 309 VolumeTag names.VolumeTag 310 MachineTag names.MachineTag 311 info *state.VolumeAttachmentInfo 312 } 313 314 func (va *mockVolumeAttachment) Volume() names.VolumeTag { 315 return va.VolumeTag 316 } 317 318 func (va *mockVolumeAttachment) Machine() names.MachineTag { 319 return va.MachineTag 320 } 321 322 func (va *mockVolumeAttachment) Life() state.Life { 323 panic("not implemented for test") 324 } 325 326 func (va *mockVolumeAttachment) Info() (state.VolumeAttachmentInfo, error) { 327 if va.info != nil { 328 return *va.info, nil 329 } 330 return state.VolumeAttachmentInfo{}, errors.NotProvisionedf("volume attachment") 331 } 332 333 func (va *mockVolumeAttachment) Params() (state.VolumeAttachmentParams, bool) { 334 panic("not implemented for test") 335 } 336 337 type mockBlock struct { 338 state.Block 339 t state.BlockType 340 msg string 341 } 342 343 func (b mockBlock) Type() state.BlockType { 344 return b.t 345 } 346 347 func (b mockBlock) Message() string { 348 return b.msg 349 }