This repository has been archived by the owner on Sep 14, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
zapi_interfaces_test.go
90 lines (66 loc) · 1.61 KB
/
zapi_interfaces_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
package zevenetlb
import (
"runtime"
"testing"
ping "github.com/sparrc/go-ping"
)
const (
unitTestVirtualInterfaceName = "eth0:unittest"
unitTestVirtualInterfaceIP = "10.209.0.31"
)
func TestGetAllNetworkInterfaces(t *testing.T) {
session := createTestSession(t)
res, err := session.GetAllNetworkInterfaces()
if err != nil {
t.Fatal(err)
}
if len(res) <= 0 {
t.Fatal("No NICs returned")
}
}
func TestGetAllVirtualInterfaces(t *testing.T) {
session := createTestSession(t)
res, err := session.GetAllVirtualInterfaces()
if err != nil {
t.Fatal(err)
}
if len(res) <= 0 {
t.Fatal("No NICs returned")
}
}
func TestRoundtripVirtualInterface(t *testing.T) {
session := createTestSession(t)
// ensure the virtualInterface does not exist
_, err := session.DeleteVirtualInterface(unitTestVirtualInterfaceName)
if err != nil {
t.Fatal(err)
}
// create the new virtualInterface
vint, err := session.CreateVirtualInterface(unitTestVirtualInterfaceName, unitTestVirtualInterfaceIP)
if err != nil {
t.Fatal(err)
}
defer session.DeleteVirtualInterface(vint.Name)
t.Logf("New Int: %v, Status: %v", vint.Name, vint.Status)
// try to connect
pinger, err := ping.NewPinger(vint.IP)
if err != nil {
t.Fatal(err)
}
if runtime.GOOS == "windows" {
pinger.SetPrivileged(true)
}
pinger.Count = 3
pinger.Run() // blocks until finished
if err != nil {
t.Fatal(err)
}
// done, delete the virtualInterface
deleted, err := session.DeleteVirtualInterface(vint.Name)
if err != nil {
t.Fatal(err)
}
if !deleted {
t.Fatal("Expected deleting the virtual Interface to succeed, but failed")
}
}