1
// Copyright 2015 Canonical Ltd.
2
// Licensed under the AGPLv3, see LICENCE file for details.
4
package storagecommon_test
7
"github.com/juju/errors"
8
"github.com/juju/testing"
9
"gopkg.in/juju/names.v2"
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"
17
type fakeStorage struct {
19
storagecommon.StorageInterface
20
storageInstance func(names.StorageTag) (state.StorageInstance, error)
21
storageInstanceVolume func(names.StorageTag) (state.Volume, error)
22
volumeAttachment func(names.MachineTag, names.VolumeTag) (state.VolumeAttachment, error)
23
blockDevices func(names.MachineTag) ([]state.BlockDeviceInfo, error)
24
watchVolumeAttachment func(names.MachineTag, names.VolumeTag) state.NotifyWatcher
25
watchBlockDevices func(names.MachineTag) state.NotifyWatcher
26
watchStorageAttachment func(names.StorageTag, names.UnitTag) state.NotifyWatcher
29
func (s *fakeStorage) StorageInstance(tag names.StorageTag) (state.StorageInstance, error) {
30
s.MethodCall(s, "StorageInstance", tag)
31
return s.storageInstance(tag)
34
func (s *fakeStorage) StorageInstanceVolume(tag names.StorageTag) (state.Volume, error) {
35
s.MethodCall(s, "StorageInstanceVolume", tag)
36
return s.storageInstanceVolume(tag)
39
func (s *fakeStorage) VolumeAttachment(m names.MachineTag, v names.VolumeTag) (state.VolumeAttachment, error) {
40
s.MethodCall(s, "VolumeAttachment", m, v)
41
return s.volumeAttachment(m, v)
44
func (s *fakeStorage) BlockDevices(m names.MachineTag) ([]state.BlockDeviceInfo, error) {
45
s.MethodCall(s, "BlockDevices", m)
46
return s.blockDevices(m)
49
func (s *fakeStorage) WatchVolumeAttachment(m names.MachineTag, v names.VolumeTag) state.NotifyWatcher {
50
s.MethodCall(s, "WatchVolumeAttachment", m, v)
51
return s.watchVolumeAttachment(m, v)
54
func (s *fakeStorage) WatchBlockDevices(m names.MachineTag) state.NotifyWatcher {
55
s.MethodCall(s, "WatchBlockDevices", m)
56
return s.watchBlockDevices(m)
59
func (s *fakeStorage) WatchStorageAttachment(st names.StorageTag, u names.UnitTag) state.NotifyWatcher {
60
s.MethodCall(s, "WatchStorageAttachment", st, u)
61
return s.watchStorageAttachment(st, u)
64
type fakeStorageInstance struct {
68
kind state.StorageKind
71
func (i *fakeStorageInstance) StorageTag() names.StorageTag {
75
func (i *fakeStorageInstance) Tag() names.Tag {
79
func (i *fakeStorageInstance) Owner() names.Tag {
83
func (i *fakeStorageInstance) Kind() state.StorageKind {
87
type fakeStorageAttachment struct {
88
state.StorageAttachment
89
storageTag names.StorageTag
92
func (a *fakeStorageAttachment) StorageInstance() names.StorageTag {
96
type fakeVolume struct {
99
params *state.VolumeParams
100
info *state.VolumeInfo
103
func (v *fakeVolume) VolumeTag() names.VolumeTag {
107
func (v *fakeVolume) Tag() names.Tag {
111
func (v *fakeVolume) Params() (state.VolumeParams, bool) {
113
return state.VolumeParams{}, false
115
return *v.params, true
118
func (v *fakeVolume) Info() (state.VolumeInfo, error) {
120
return state.VolumeInfo{}, errors.NotProvisionedf("volume %v", v.tag.Id())
125
type fakeVolumeAttachment struct {
126
state.VolumeAttachment
127
info *state.VolumeAttachmentInfo
130
func (v *fakeVolumeAttachment) Info() (state.VolumeAttachmentInfo, error) {
132
return state.VolumeAttachmentInfo{}, errors.NotProvisionedf("volume attachment")
137
type fakePoolManager struct {
138
poolmanager.PoolManager
141
func (pm *fakePoolManager) Get(name string) (*storage.Config, error) {
142
return nil, errors.NotFoundf("pool")
145
type nopSyncStarter struct{}
147
func (nopSyncStarter) StartSync() {}