forked from evergreen-ci/evergreen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvsphere_mock_test.go
68 lines (52 loc) · 1.41 KB
/
vsphere_mock_test.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
// +build go1.7
package cloud
import (
"context"
"github.com/evergreen-ci/evergreen/model/host"
"github.com/pkg/errors"
"github.com/vmware/govmomi/vim25/types"
)
type vsphereClientMock struct {
// API call options
failInit bool
failIP bool
failPowerState bool
failCreate bool
failDelete bool
// Other options
isActive bool
}
func (c *vsphereClientMock) Init(context.Context, *authOptions) error {
if c.failInit {
return errors.New("failed to initialize instance")
}
return nil
}
func (c *vsphereClientMock) GetIP(context.Context, *host.Host) (string, error) {
if c.failIP {
return "", errors.New("failed to get IP")
}
return "0.0.0.0", nil
}
func (c *vsphereClientMock) GetPowerState(context.Context, *host.Host) (types.VirtualMachinePowerState, error) {
if c.failPowerState {
err := errors.New("failed to read power state")
return types.VirtualMachinePowerState(""), err
}
if !c.isActive {
return types.VirtualMachinePowerStatePoweredOff, nil
}
return types.VirtualMachinePowerStatePoweredOn, nil
}
func (c *vsphereClientMock) CreateInstance(ctx context.Context, h *host.Host, _ *vsphereSettings) (string, error) {
if c.failCreate {
return "", errors.New("failed to create instance")
}
return h.Id, nil
}
func (c *vsphereClientMock) DeleteInstance(context.Context, *host.Host) error {
if c.failDelete {
return errors.New("failed to delete instance")
}
return nil
}