forked from milosgajdos/tenus
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvlan_linux_test.go
More file actions
75 lines (62 loc) · 1.63 KB
/
vlan_linux_test.go
File metadata and controls
75 lines (62 loc) · 1.63 KB
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
package tenus
import (
"net"
"strconv"
"testing"
"time"
)
type vlnTest struct {
masterDev string
id uint16
}
var vlnTests = []vlnTest{
{"master01", 10},
{"master02", 20},
}
func Test_NewVlanLink(t *testing.T) {
for _, tt := range vlnTests {
tl := &testLink{}
if err := tl.prepTestLink(tt.masterDev, "dummy"); err != nil {
t.Skipf("NewVlanLink 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)
}
vln, err := NewVlanLink(tt.masterDev, tt.id)
if err != nil {
t.Fatalf("NewVlanLink(%s, %s) failed to run: %s", tt.masterDev, tt.id, err)
}
vlnName := vln.NetInterface().Name
if _, err := net.InterfaceByName(vlnName); err != nil {
tl.teardown()
t.Fatalf("Could not find %s on the host: %s", vlnName, err)
}
testRes, err := linkInfo(vlnName, "vlan")
if err != nil {
tl.teardown()
t.Fatalf("Failed to list %s operation mode: %s", vlnName, err)
}
if testRes.linkType != "vlan" {
tl.teardown()
t.Fatalf("NewMacVlanLink(%s, %d) failed: expected vlan, returned %s",
tt.masterDev, tt.id, testRes.linkType)
}
id, err := strconv.Atoi(testRes.linkData)
if err != nil {
tl.teardown()
t.Fatalf("Failed to convert link data %s : %s", testRes.linkData, err)
}
if uint16(id) != tt.id {
tl.teardown()
t.Fatalf("NewMacVlanLink(%s, %d) failed: expected %d, returned %d",
tt.masterDev, tt.id, tt.id, id)
}
if err := tl.teardown(); err != nil {
t.Fatalf("testLink.teardown failed: %v", err)
} else {
time.Sleep(10 * time.Millisecond)
}
}
}