-
Notifications
You must be signed in to change notification settings - Fork 0
/
hypervisor_test.go
128 lines (114 loc) · 3.36 KB
/
hypervisor_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
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
package lazyjack_test
import (
"fmt"
"github.com/pmichali/lazyjack"
)
type MockHypervisor struct {
simNotExists bool
simRunning bool
simDeleteNetFail bool
simDeleteContainerFail bool
simRunFailed bool
simInterfaceGetFail bool
simNoV4Interface bool
simDeleteInterfaceFail bool
simAddRouteFail bool
simRouteExists bool
simCreateNetFail bool
simCreateVolumeFail bool
simDeleteVolumeFail bool
simInspectVolumeFail bool
simBadVolumeInfo bool
mountPoint string
}
func (mh *MockHypervisor) ResourceState(r string) string {
if mh.simNotExists {
return lazyjack.ResourceNotPresent
}
if mh.simRunning {
return lazyjack.ResourceRunning
}
return lazyjack.ResourceExists
}
func (mh *MockHypervisor) DeleteNetwork(string) error {
if mh.simDeleteNetFail {
return fmt.Errorf("mock fail delete of network")
}
return nil
}
func (mh *MockHypervisor) DeleteContainer(name string) error {
if mh.simDeleteContainerFail {
return fmt.Errorf("mock fail delete of container")
}
return nil
}
func (mh *MockHypervisor) RunContainer(name string, args []string) error {
if mh.simRunFailed {
return fmt.Errorf("mock fail to run container")
}
return nil
}
func (mh *MockHypervisor) GetInterfaceConfig(name, ifName string) (string, error) {
if mh.simInterfaceGetFail {
return "", fmt.Errorf("mock fail getting interface info")
}
ifConfig := `39139: eth0@if39140: <BROADCAST,MULTICAST,UP,LOWER_UP,M-DOWN> mtu 1500 qdisc noqueue state UP
link/ether 02:42:ac:12:00:02 brd ff:ff:ff:ff:ff:ff
inet 172.18.0.2/16 scope global eth0
valid_lft forever preferred_lft forever
inet6 fd00:10::100/64 scope global flags 02
valid_lft forever preferred_lft forever
inet6 fe80::42:acff:fe12:2/64 scope link
valid_lft forever preferred_lft forever`
if mh.simNoV4Interface {
ifConfig = `39139: eth0@if39140: <BROADCAST,MULTICAST,UP,LOWER_UP,M-DOWN> mtu 1500 qdisc noqueue state UP
link/ether 02:42:ac:12:00:02 brd ff:ff:ff:ff:ff:ff
inet6 fd00:10::100/64 scope global flags 02
valid_lft forever preferred_lft forever
inet6 fe80::42:acff:fe12:2/64 scope link
valid_lft forever preferred_lft forever`
}
return ifConfig, nil
}
func (mh *MockHypervisor) DeleteV4Address(container, ip string) error {
if mh.simDeleteInterfaceFail {
return fmt.Errorf("mock fail delete of IP")
}
return nil
}
func (mh *MockHypervisor) AddV6Route(container, dest, via string) error {
if mh.simAddRouteFail {
return fmt.Errorf("mock fail add route")
}
if mh.simRouteExists {
return fmt.Errorf("exit status 2")
}
return nil
}
func (mh *MockHypervisor) CreateNetwork(name, cidr, v4cidr, gw string) error {
if mh.simCreateNetFail {
return fmt.Errorf("mock fail create of network")
}
return nil
}
func (mh *MockHypervisor) CreateVolume(name string) error {
if mh.simCreateVolumeFail {
return fmt.Errorf("mock fail create of volume")
}
return nil
}
func (mh *MockHypervisor) DeleteVolume(name string) error {
if mh.simDeleteVolumeFail {
return fmt.Errorf("mock fail delete of volume")
}
return nil
}
func (mh *MockHypervisor) GetVolumeMountPoint(name string) (string, error) {
if mh.simInspectVolumeFail {
return "", fmt.Errorf("mock fail inspect of volume")
}
if mh.simBadVolumeInfo {
return "/tmp/volume-mount-point-failure", nil
}
return mh.mountPoint, nil
}