forked from cloudfoundry/bosh-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fake_vm_deployer.go
81 lines (68 loc) · 2.08 KB
/
fake_vm_deployer.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
package fakes
import (
bicloud "github.com/cloudfoundry/bosh-cli/cloud"
bideplmanifest "github.com/cloudfoundry/bosh-cli/deployment/manifest"
bisshtunnel "github.com/cloudfoundry/bosh-cli/deployment/sshtunnel"
bivm "github.com/cloudfoundry/bosh-cli/deployment/vm"
bistemcell "github.com/cloudfoundry/bosh-cli/stemcell"
biui "github.com/cloudfoundry/bosh-cli/ui"
)
type FakeVMDeployer struct {
DeployInputs []VMDeployInput
DeployOutputs []vmDeployOutput
WaitUntilReadyInputs []WaitUntilReadyInput
WaitUntilReadyErr error
}
type VMDeployInput struct {
Cloud bicloud.Cloud
Manifest bideplmanifest.Manifest
Stemcell bistemcell.CloudStemcell
MbusURL string
EventLoggerStage biui.Stage
}
type WaitUntilReadyInput struct {
VM bivm.VM
SSHTunnelOptions bisshtunnel.Options
EventLoggerStage biui.Stage
}
type vmDeployOutput struct {
vm bivm.VM
err error
}
func NewFakeVMDeployer() *FakeVMDeployer {
return &FakeVMDeployer{
DeployInputs: []VMDeployInput{},
DeployOutputs: []vmDeployOutput{},
}
}
func (m *FakeVMDeployer) Deploy(
cloud bicloud.Cloud,
deploymentManifest bideplmanifest.Manifest,
stemcell bistemcell.CloudStemcell,
mbusURL string,
eventLoggerStage biui.Stage,
) (bivm.VM, error) {
input := VMDeployInput{
Cloud: cloud,
Manifest: deploymentManifest,
Stemcell: stemcell,
MbusURL: mbusURL,
EventLoggerStage: eventLoggerStage,
}
m.DeployInputs = append(m.DeployInputs, input)
output := m.DeployOutputs[0]
m.DeployOutputs = m.DeployOutputs[1:]
return output.vm, output.err
}
func (m *FakeVMDeployer) WaitUntilReady(vm bivm.VM, sshTunnelOptions bisshtunnel.Options, eventLoggerStage biui.Stage) error {
input := WaitUntilReadyInput{
VM: vm,
SSHTunnelOptions: sshTunnelOptions,
EventLoggerStage: eventLoggerStage,
}
m.WaitUntilReadyInputs = append(m.WaitUntilReadyInputs, input)
return m.WaitUntilReadyErr
}
func (m *FakeVMDeployer) SetDeployBehavior(vm bivm.VM, err error) {
m.DeployOutputs = append(m.DeployOutputs, vmDeployOutput{vm: vm, err: err})
}