-
Notifications
You must be signed in to change notification settings - Fork 61
/
macvlan_linux_test.go
136 lines (110 loc) · 3.36 KB
/
macvlan_linux_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
129
130
131
132
133
134
135
136
package tenus
import (
"net"
"testing"
"time"
)
type macvlnTest struct {
masterDev string
}
var macvlnTests = []macvlnTest{
{"master01"},
}
func Test_NewMacVlanLink(t *testing.T) {
for _, tt := range macvlnTests {
tl := &testLink{}
if err := tl.prepTestLink(tt.masterDev, "dummy"); err != nil {
t.Skipf("NewMacVlanLink test requries external command: %v", err)
}
if err := tl.create(); err != nil {
t.Fatalf("testLink.create failed: %v", err)
} else {
time.Sleep(10 * time.Millisecond)
}
mvln, err := NewMacVlanLink(tt.masterDev)
if err != nil {
t.Fatalf("NewMacVlanLink(%s) failed to run: %s", tt.masterDev, err)
}
mvlnName := mvln.NetInterface().Name
if _, err := net.InterfaceByName(mvlnName); err != nil {
tl.teardown()
t.Fatalf("Could not find %s on the host: %s", mvlnName, err)
}
testRes, err := linkInfo(mvlnName, "macvlan")
if err != nil {
tl.teardown()
t.Fatalf("Failed to list %s operation mode: %s", mvlnName, err)
}
if testRes.linkType != "macvlan" {
tl.teardown()
t.Fatalf("NewMacVlanLink(%s) failed: expected macvlan, returned %s",
tt.masterDev, testRes.linkType)
}
if testRes.linkData != "bridge" {
tl.teardown()
t.Fatalf("NewMacVlanLink(%s) failed: expected bridge, returned %s",
tt.masterDev, testRes.linkData)
}
if err := tl.teardown(); err != nil {
t.Fatalf("testLink.teardown failed: %v", err)
} else {
time.Sleep(10 * time.Millisecond)
}
}
}
type macvlnWithOptionsTest struct {
masterDev string
opts *MacVlanOptions
}
var macvlnWithOptionsTests = []macvlnWithOptionsTest{
{"master01", &MacVlanOptions{Dev: "test", MacAddr: "aa:aa:aa:aa:aa:aa", Mode: "bridge"}},
}
func Test_NewMacVlanLinkWithOptions(t *testing.T) {
for _, tt := range macvlnWithOptionsTests {
var iface *net.Interface
tl := &testLink{}
if err := tl.prepTestLink(tt.masterDev, "dummy"); err != nil {
t.Skipf("NewMacVlanLinkWithOptions test requries external command: %v", err)
}
if err := tl.create(); err != nil {
t.Fatalf("testLink.create failed: %v", err)
} else {
time.Sleep(10 * time.Millisecond)
}
mvln, err := NewMacVlanLinkWithOptions(tt.masterDev, *tt.opts)
if err != nil {
t.Fatalf("NewMacVlanLinkWithOptions(%s, %s) failed to run: %s", tt.masterDev, *tt.opts, err)
}
iface = mvln.NetInterface()
if iface.HardwareAddr.String() != tt.opts.MacAddr {
tl.teardown()
t.Fatalf("NewMacVlanLinkWithOptions(%s, %s) failed: expected %s, returned %s",
tt.masterDev, *tt.opts, tt.opts.MacAddr, iface.HardwareAddr.String())
}
mvlnName := iface.Name
if _, err := net.InterfaceByName(mvlnName); err != nil {
tl.teardown()
t.Fatalf("Could not find %s on the host: %s", mvlnName, err)
}
testRes, err := linkInfo(mvlnName, "macvlan")
if err != nil {
tl.teardown()
t.Fatalf("Failed to list %s operation mode: %s", mvlnName, err)
}
if testRes.linkType != "macvlan" {
tl.teardown()
t.Fatalf("NewMacVlanLinkWithOptions(%s, %s) failed: expected macvlan, returned %s",
tt.masterDev, *tt.opts, testRes.linkType)
}
if testRes.linkData != "bridge" {
tl.teardown()
t.Fatalf("NewMacVlanLinkWithOptions(%s, %s) failed: expected bridge, returned %s",
tt.masterDev, *tt.opts, testRes.linkData)
}
if err := tl.teardown(); err != nil {
t.Fatalf("testLink.teardown failed: %v", err)
} else {
time.Sleep(10 * time.Millisecond)
}
}
}