forked from milosgajdos/tenus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bridge_linux_test.go
81 lines (66 loc) · 1.83 KB
/
bridge_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
package tenus
import (
"net"
"testing"
"time"
)
func Test_NewBridge(t *testing.T) {
tl := &testLink{}
br, err := NewBridge()
if err != nil {
t.Fatalf("NewBridge() failed to run: %s", err)
}
brName := br.NetInterface().Name
if err := tl.prepTestLink(brName, "bridge"); err != nil {
t.Skipf("NewBridge test requries external command: %v", err)
}
if _, err := net.InterfaceByName(brName); err != nil {
tl.teardown()
t.Fatalf("Could not find %s on the host: %s", brName, err)
}
testRes, err := linkInfo(brName, "bridge")
if err != nil {
tl.teardown()
t.Fatalf("Failed to list %s operation mode: %s", brName, err)
}
if testRes.linkType != "bridge" {
tl.teardown()
t.Fatalf("NewBridge() failed: expected linktype bridge, returned %s", testRes.linkType)
}
if err := tl.teardown(); err != nil {
t.Fatalf("testLink.teardown failed: %v", err)
} else {
time.Sleep(10 * time.Millisecond)
}
}
func Test_NewBridgeWithName(t *testing.T) {
brTests := []string{"br01", "br02", "br03"}
for _, tt := range brTests {
tl := &testLink{}
_, err := NewBridgeWithName(tt)
if err != nil {
t.Fatalf("NewBridge(%s) failed to run: %s", tt, err)
}
if err := tl.prepTestLink(tt, "bridge"); err != nil {
t.Skipf("test requries external command: %v", err)
}
if _, err := net.InterfaceByName(tt); err != nil {
tl.teardown()
t.Fatalf("Could not find %s on the host: %s", tt, err)
}
testRes, err := linkInfo(tt, "bridge")
if err != nil {
tl.teardown()
t.Fatalf("Failed to list %s operation mode: %s", tt, err)
}
if testRes.linkType != "bridge" {
tl.teardown()
t.Fatalf("NewBridge() failed: expected linktype bridge, returned %s", testRes.linkType)
}
if err := tl.teardown(); err != nil {
t.Fatalf("testIfcLink.teardown failed: %v", err)
} else {
time.Sleep(10 * time.Millisecond)
}
}
}