This repository has been archived by the owner on Sep 6, 2021. It is now read-only.
forked from cloudfoundry/bosh-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fake_vm.go
224 lines (173 loc) · 4.89 KB
/
fake_vm.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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
package fakes
import (
"time"
biagentclient "github.com/cloudfoundry/bosh-agent/agentclient"
bias "github.com/cloudfoundry/bosh-agent/agentclient/applyspec"
bidisk "github.com/cloudfoundry/bosh-cli/deployment/disk"
bideplmanifest "github.com/cloudfoundry/bosh-cli/deployment/manifest"
biui "github.com/cloudfoundry/bosh-cli/ui"
)
type FakeVM struct {
cid string
ExistsCalled int
ExistsFound bool
ExistsErr error
AgentClientReturn biagentclient.AgentClient
UpdateDisksInputs []UpdateDisksInput
UpdateDisksDisks []bidisk.Disk
UpdateDisksErr error
ApplyInputs []ApplyInput
ApplyErr error
StartCalled int
StartErr error
AttachDiskInputs []AttachDiskInput
attachDiskBehavior map[string]error
DetachDiskInputs []DetachDiskInput
detachDiskBehavior map[string]error
WaitUntilReadyInputs []WaitUntilReadyInput
WaitUntilReadyErr error
WaitToBeRunningInputs []WaitInput
WaitToBeRunningErr error
DeleteCalled int
DeleteErr error
StopCalled int
StopErr error
ListDisksDisks []bidisk.Disk
ListDisksErr error
UnmountDiskInputs []UnmountDiskInput
UnmountDiskErr error
MigrateDiskCalledTimes int
MigrateDiskErr error
RunScriptInputs []string
RunScriptErrors map[string]error
GetStateResult biagentclient.AgentState
GetStateCalled int
GetStateErr error
}
type UpdateDisksInput struct {
DiskPool bideplmanifest.DiskPool
Stage biui.Stage
}
type ApplyInput struct {
ApplySpec bias.ApplySpec
}
type WaitUntilReadyInput struct {
Timeout time.Duration
Delay time.Duration
}
type WaitInput struct {
MaxAttempts int
Delay time.Duration
}
type AttachDiskInput struct {
Disk bidisk.Disk
}
type DetachDiskInput struct {
Disk bidisk.Disk
}
type UnmountDiskInput struct {
Disk bidisk.Disk
}
func NewFakeVM(cid string) *FakeVM {
return &FakeVM{
ExistsFound: true,
ApplyInputs: []ApplyInput{},
WaitUntilReadyInputs: []WaitUntilReadyInput{},
WaitToBeRunningInputs: []WaitInput{},
AttachDiskInputs: []AttachDiskInput{},
DetachDiskInputs: []DetachDiskInput{},
UnmountDiskInputs: []UnmountDiskInput{},
attachDiskBehavior: map[string]error{},
detachDiskBehavior: map[string]error{},
cid: cid,
RunScriptErrors: map[string]error{},
}
}
func (vm *FakeVM) CID() string {
return vm.cid
}
func (vm *FakeVM) Exists() (bool, error) {
vm.ExistsCalled++
return vm.ExistsFound, vm.ExistsErr
}
func (vm *FakeVM) AgentClient() biagentclient.AgentClient {
return vm.AgentClientReturn
}
func (vm *FakeVM) WaitUntilReady(timeout time.Duration, delay time.Duration) error {
vm.WaitUntilReadyInputs = append(vm.WaitUntilReadyInputs, WaitUntilReadyInput{
Timeout: timeout,
Delay: delay,
})
return vm.WaitUntilReadyErr
}
func (vm *FakeVM) UpdateDisks(diskPool bideplmanifest.DiskPool, eventLoggerStage biui.Stage) ([]bidisk.Disk, error) {
vm.UpdateDisksInputs = append(vm.UpdateDisksInputs, UpdateDisksInput{
DiskPool: diskPool,
Stage: eventLoggerStage,
})
return vm.UpdateDisksDisks, vm.UpdateDisksErr
}
func (vm *FakeVM) Apply(applySpec bias.ApplySpec) error {
vm.ApplyInputs = append(vm.ApplyInputs, ApplyInput{
ApplySpec: applySpec,
})
return vm.ApplyErr
}
func (vm *FakeVM) Start() error {
vm.StartCalled++
return vm.StartErr
}
func (vm *FakeVM) WaitToBeRunning(maxAttempts int, delay time.Duration) error {
vm.WaitToBeRunningInputs = append(vm.WaitToBeRunningInputs, WaitInput{
MaxAttempts: maxAttempts,
Delay: delay,
})
return vm.WaitToBeRunningErr
}
func (vm *FakeVM) AttachDisk(disk bidisk.Disk) error {
vm.AttachDiskInputs = append(vm.AttachDiskInputs, AttachDiskInput{
Disk: disk,
})
return vm.attachDiskBehavior[disk.CID()]
}
func (vm *FakeVM) DetachDisk(disk bidisk.Disk) error {
vm.DetachDiskInputs = append(vm.DetachDiskInputs, DetachDiskInput{
Disk: disk,
})
return vm.detachDiskBehavior[disk.CID()]
}
func (vm *FakeVM) UnmountDisk(disk bidisk.Disk) error {
vm.UnmountDiskInputs = append(vm.UnmountDiskInputs, UnmountDiskInput{
Disk: disk,
})
return vm.UnmountDiskErr
}
func (vm *FakeVM) MigrateDisk() error {
vm.MigrateDiskCalledTimes++
return vm.MigrateDiskErr
}
func (vm *FakeVM) Stop() error {
vm.StopCalled++
return vm.StopErr
}
func (vm *FakeVM) Disks() ([]bidisk.Disk, error) {
return vm.ListDisksDisks, vm.ListDisksErr
}
func (vm *FakeVM) RunScript(script string, options map[string]interface{}) error {
vm.RunScriptInputs = append(vm.RunScriptInputs, script)
return vm.RunScriptErrors[script]
}
func (vm *FakeVM) Delete() error {
vm.DeleteCalled++
return vm.DeleteErr
}
func (vm *FakeVM) SetAttachDiskBehavior(disk bidisk.Disk, err error) {
vm.attachDiskBehavior[disk.CID()] = err
}
func (vm *FakeVM) SetDetachDiskBehavior(disk bidisk.Disk, err error) {
vm.detachDiskBehavior[disk.CID()] = err
}
func (vm *FakeVM) GetState() (biagentclient.AgentState, error) {
vm.GetStateCalled++
return vm.GetStateResult, vm.GetStateErr
}