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