forked from juju/juju
/
provider.go
110 lines (89 loc) · 3.33 KB
/
provider.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
// Copyright 2015 Canonical Ltd.
// Licensed under the AGPLv3, see LICENCE file for details.
package dummy
import (
"github.com/juju/errors"
"github.com/juju/testing"
"github.com/juju/juju/storage"
)
var _ storage.Provider = (*StorageProvider)(nil)
// StorageProvider is an implementation of storage.Provider, suitable for testing.
// Each method's default behaviour may be overridden by setting the corresponding
// Func field.
type StorageProvider struct {
testing.Stub
// StorageScope defines the scope of storage managed by this provider.
StorageScope storage.Scope
// IsDynamic defines whether or not the provider reports that it supports
// dynamic provisioning.
IsDynamic bool
// IsReleasable defines whether or not the provider reports that it
// supports releasing storage.
IsReleasable bool
// DefaultPools_ will be returned by DefaultPools.
DefaultPools_ []*storage.Config
// VolumeSourceFunc will be called by VolumeSource, if non-nil;
// otherwise VolumeSource will return a NotSupported error.
VolumeSourceFunc func(*storage.Config) (storage.VolumeSource, error)
// FilesystemSourceFunc will be called by FilesystemSource, if non-nil;
// otherwise FilesystemSource will return a NotSupported error.
FilesystemSourceFunc func(*storage.Config) (storage.FilesystemSource, error)
// ValidateConfigFunc will be called by ValidateConfig, if non-nil;
// otherwise ValidateConfig returns nil.
ValidateConfigFunc func(*storage.Config) error
// SupportsFunc will be called by Supports, if non-nil; otherwise,
// Supports returns true.
SupportsFunc func(kind storage.StorageKind) bool
}
// VolumeSource is defined on storage.Provider.
func (p *StorageProvider) VolumeSource(providerConfig *storage.Config) (storage.VolumeSource, error) {
p.MethodCall(p, "VolumeSource", providerConfig)
if p.VolumeSourceFunc != nil {
return p.VolumeSourceFunc(providerConfig)
}
return nil, errors.NotSupportedf("volumes")
}
// FilesystemSource is defined on storage.Provider.
func (p *StorageProvider) FilesystemSource(providerConfig *storage.Config) (storage.FilesystemSource, error) {
p.MethodCall(p, "FilesystemSource", providerConfig)
if p.FilesystemSourceFunc != nil {
return p.FilesystemSourceFunc(providerConfig)
}
return nil, errors.NotSupportedf("filesystems")
}
// ValidateConfig is defined on storage.Provider.
func (p *StorageProvider) ValidateConfig(providerConfig *storage.Config) error {
p.MethodCall(p, "ValidateConfig", providerConfig)
if p.ValidateConfigFunc != nil {
return p.ValidateConfigFunc(providerConfig)
}
return nil
}
// Supports is defined on storage.Provider.
func (p *StorageProvider) Supports(kind storage.StorageKind) bool {
p.MethodCall(p, "Supports", kind)
if p.SupportsFunc != nil {
return p.SupportsFunc(kind)
}
return true
}
// Scope is defined on storage.Provider.
func (p *StorageProvider) Scope() storage.Scope {
p.MethodCall(p, "Scope")
return p.StorageScope
}
// Dynamic is defined on storage.Provider.
func (p *StorageProvider) Dynamic() bool {
p.MethodCall(p, "Dynamic")
return p.IsDynamic
}
// Releasable is defined on storage.Provider.
func (p *StorageProvider) Releasable() bool {
p.MethodCall(p, "Releasable")
return p.IsReleasable
}
// DefaultPool is defined on storage.Provider.
func (p *StorageProvider) DefaultPools() []*storage.Config {
p.MethodCall(p, "DefaultPools")
return p.DefaultPools_
}