@@ -8,6 +8,45 @@ import (
88 "github.com/stretchr/testify/assert"
99)
1010
11+ const stdOutOneHostOnlyNetwork = `Name: vboxnet0
12+ GUID: 786f6276-656e-4074-8000-0a0027000000
13+ DHCP: Disabled
14+ IPAddress: 192.168.99.1
15+ NetworkMask: 255.255.255.0
16+ IPV6Address:
17+ IPV6NetworkMaskPrefixLength: 0
18+ HardwareAddress: 0a:00:27:00:00:00
19+ MediumType: Ethernet
20+ Status: Up
21+ VBoxNetworkName: HostInterfaceNetworking-vboxnet0
22+
23+ `
24+ const stdOutTwoHostOnlyNetwork = `Name: vboxnet0
25+ GUID: 786f6276-656e-4074-8000-0a0027000000
26+ DHCP: Disabled
27+ IPAddress: 192.168.99.1
28+ NetworkMask: 255.255.255.0
29+ IPV6Address:
30+ IPV6NetworkMaskPrefixLength: 0
31+ HardwareAddress: 0a:00:27:00:00:00
32+ MediumType: Ethernet
33+ Status: Up
34+ VBoxNetworkName: HostInterfaceNetworking-vboxnet0
35+
36+ Name: vboxnet1
37+ GUID: 786f6276-656e-4174-8000-0a0027000001
38+ DHCP: Disabled
39+ IPAddress: 192.168.99.1
40+ NetworkMask: 255.255.255.0
41+ IPV6Address:
42+ IPV6NetworkMaskPrefixLength: 0
43+ HardwareAddress: 0a:00:27:00:00:01
44+ MediumType: Ethernet
45+ Status: Up
46+ VBoxNetworkName: HostInterfaceNetworking-vboxnet1
47+
48+ `
49+
1150// Tests that when we have a host only network which matches our expectations,
1251// it gets returned correctly.
1352func TestGetHostOnlyNetworkHappy (t * testing.T ) {
@@ -87,20 +126,8 @@ func TestGetHostOnlyNetworkWindows10Bug(t *testing.T) {
87126
88127func TestListHostOnlyNetworks (t * testing.T ) {
89128 vbox := & VBoxManagerMock {
90- args : "list hostonlyifs" ,
91- stdOut : `Name: vboxnet0
92- GUID: 786f6276-656e-4074-8000-0a0027000000
93- DHCP: Disabled
94- IPAddress: 192.168.99.1
95- NetworkMask: 255.255.255.0
96- IPV6Address:
97- IPV6NetworkMaskPrefixLength: 0
98- HardwareAddress: 0a:00:27:00:00:00
99- MediumType: Ethernet
100- Status: Up
101- VBoxNetworkName: HostInterfaceNetworking-vboxnet0
102-
103- ` ,
129+ args : "list hostonlyifs" ,
130+ stdOut : stdOutOneHostOnlyNetwork ,
104131 }
105132
106133 nets , err := listHostOnlyNetworks (vbox )
@@ -125,32 +152,8 @@ VBoxNetworkName: HostInterfaceNetworking-vboxnet0
125152
126153func TestListTwoHostOnlyNetworks (t * testing.T ) {
127154 vbox := & VBoxManagerMock {
128- args : "list hostonlyifs" ,
129- stdOut : `Name: vboxnet0
130- GUID: 786f6276-656e-4074-8000-0a0027000000
131- DHCP: Disabled
132- IPAddress: 192.168.99.1
133- NetworkMask: 255.255.255.0
134- IPV6Address:
135- IPV6NetworkMaskPrefixLength: 0
136- HardwareAddress: 0a:00:27:00:00:00
137- MediumType: Ethernet
138- Status: Up
139- VBoxNetworkName: HostInterfaceNetworking-vboxnet0
140-
141- Name: vboxnet1
142- GUID: 786f6276-656e-4174-8000-0a0027000001
143- DHCP: Disabled
144- IPAddress: 192.168.99.1
145- NetworkMask: 255.255.255.0
146- IPV6Address:
147- IPV6NetworkMaskPrefixLength: 0
148- HardwareAddress: 0a:00:27:00:00:01
149- MediumType: Ethernet
150- Status: Up
151- VBoxNetworkName: HostInterfaceNetworking-vboxnet1
152-
153- ` ,
155+ args : "list hostonlyifs" ,
156+ stdOut : stdOutTwoHostOnlyNetwork ,
154157 }
155158
156159 nets , err := listHostOnlyNetworks (vbox )
@@ -195,3 +198,16 @@ VBoxNetworkName: HostInterfaceNetworking-vboxnet1`,
195198 assert .True (t , present )
196199 assert .Equal (t , "vboxnet0" , net .Name )
197200}
201+
202+ func TestGetHostOnlyNetwork (t * testing.T ) {
203+ vbox := & VBoxManagerMock {
204+ args : "list hostonlyifs" ,
205+ stdOut : stdOutOneHostOnlyNetwork ,
206+ }
207+
208+ net , err := getOrCreateHostOnlyNetwork (net .ParseIP ("192.168.99.1" ), parseIPv4Mask ("255.255.255.0" ), nil , nil , nil , vbox )
209+
210+ assert .NotNil (t , net )
211+ assert .Equal (t , "HostInterfaceNetworking-vboxnet0" , net .NetworkName )
212+ assert .NoError (t , err )
213+ }
0 commit comments