forked from cloudfoundry/bosh-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fake_cloud.go
190 lines (155 loc) · 3.91 KB
/
fake_cloud.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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
package fakes
import (
"github.com/cloudfoundry/bosh-cli/cloud"
biproperty "github.com/cloudfoundry/bosh-utils/property"
)
type FakeCloud struct {
CreateStemcellInputs []CreateStemcellInput
CreateStemcellCID string
CreateStemcellErr error
HasVMInput HasVMInput
HasVMFound bool
HasVMErr error
CreateVMInput CreateVMInput
CreateVMCID string
CreateVMErr error
CreateDiskInput CreateDiskInput
CreateDiskCID string
CreateDiskErr error
AttachDiskInput AttachDiskInput
AttachDiskErr error
DetachDiskInput DetachDiskInput
DetachDiskErr error
DeleteVMInput DeleteVMInput
DeleteVMErr error
DeleteDiskInputs []DeleteDiskInput
DeleteDiskErr error
DeleteStemcellInputs []DeleteStemcellInput
DeleteStemcellErr error
SetVMMetadataCid string
SetVMMetadataMetadata cloud.VMMetadata
SetVMMetadataError error
}
type CreateStemcellInput struct {
ImagePath string
CloudProperties biproperty.Map
}
type HasVMInput struct {
VMCID string
}
type CreateVMInput struct {
AgentID string
StemcellCID string
CloudProperties biproperty.Map
NetworksInterfaces map[string]biproperty.Map
Env biproperty.Map
}
type CreateDiskInput struct {
Size int
CloudProperties biproperty.Map
InstanceID string
}
type AttachDiskInput struct {
VMCID string
DiskCID string
}
type DetachDiskInput struct {
VMCID string
DiskCID string
}
type DeleteVMInput struct {
VMCID string
}
type DeleteDiskInput struct {
DiskCID string
}
type DeleteStemcellInput struct {
StemcellCID string
}
func NewFakeCloud() *FakeCloud {
return &FakeCloud{
CreateStemcellInputs: []CreateStemcellInput{},
DeleteDiskInputs: []DeleteDiskInput{},
}
}
func (c *FakeCloud) CreateStemcell(imagePath string, cloudProperties biproperty.Map) (string, error) {
c.CreateStemcellInputs = append(c.CreateStemcellInputs, CreateStemcellInput{
ImagePath: imagePath,
CloudProperties: cloudProperties,
})
return c.CreateStemcellCID, c.CreateStemcellErr
}
func (c *FakeCloud) DeleteStemcell(stemcellCID string) error {
c.DeleteStemcellInputs = append(c.DeleteStemcellInputs, DeleteStemcellInput{
StemcellCID: stemcellCID,
})
return c.DeleteStemcellErr
}
func (c *FakeCloud) HasVM(vmCID string) (bool, error) {
c.HasVMInput = HasVMInput{
VMCID: vmCID,
}
return c.HasVMFound, c.HasVMErr
}
func (c *FakeCloud) CreateVM(
agentID string,
stemcellCID string,
cloudProperties biproperty.Map,
networksInterfaces map[string]biproperty.Map,
env biproperty.Map,
) (string, error) {
c.CreateVMInput = CreateVMInput{
AgentID: agentID,
StemcellCID: stemcellCID,
CloudProperties: cloudProperties,
NetworksInterfaces: networksInterfaces,
Env: env,
}
return c.CreateVMCID, c.CreateVMErr
}
func (c *FakeCloud) SetVMMetadata(cid string, metadata cloud.VMMetadata) error {
c.SetVMMetadataCid = cid
c.SetVMMetadataMetadata = metadata
return c.SetVMMetadataError
}
func (c *FakeCloud) CreateDisk(
size int,
cloudProperties biproperty.Map,
instanceID string,
) (string, error) {
c.CreateDiskInput = CreateDiskInput{
Size: size,
CloudProperties: cloudProperties,
InstanceID: instanceID,
}
return c.CreateDiskCID, c.CreateDiskErr
}
func (c *FakeCloud) AttachDisk(vmCID, diskCID string) error {
c.AttachDiskInput = AttachDiskInput{
VMCID: vmCID,
DiskCID: diskCID,
}
return c.AttachDiskErr
}
func (c *FakeCloud) DetachDisk(vmCID, diskCID string) error {
c.DetachDiskInput = DetachDiskInput{
VMCID: vmCID,
DiskCID: diskCID,
}
return c.DetachDiskErr
}
func (c *FakeCloud) DeleteVM(vmCID string) error {
c.DeleteVMInput = DeleteVMInput{
VMCID: vmCID,
}
return c.DeleteVMErr
}
func (c *FakeCloud) DeleteDisk(diskCID string) error {
c.DeleteDiskInputs = append(c.DeleteDiskInputs, DeleteDiskInput{
DiskCID: diskCID,
})
return c.DeleteDiskErr
}
func (c *FakeCloud) String() string {
return "FakeCloud{}"
}