forked from gopwn/pwn
-
Notifications
You must be signed in to change notification settings - Fork 1
/
iface_test.go
62 lines (55 loc) · 1.13 KB
/
iface_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
package pwn
import (
"reflect"
"testing"
)
// TODO: implement mock of []net.Interface for testing
// not that they work.
/*
interfaces := []net.Interface{
{
Index: 1,
MTU: 313,
Name: "test iface",
HardwareAddr: net.HardwareAddr,
Flags: net.Flags,
}
}
ifaces, err := getInterfaceAddrs(interfaces)
if err != nil {
t.Fatal(err)
}
*/
// Test IFace NOTE: there is a small chance of this failing if a new interface
// appears while this test is running
func TestIFace(t *testing.T) {
t.Parallel()
// currently only test that the function can be called
ifaces, err := GetInterfaceAddrs()
if err != nil {
t.Fatal(err)
}
if len(ifaces) < 1 {
t.Skip("len(ifaces) < 1")
}
t.Run("GetIFaceByName", func(t *testing.T) {
t.Parallel()
iface, err := GetIFaceByName(ifaces[0].Name)
if err != nil {
t.Fatal(err)
}
if !reflect.DeepEqual(iface, ifaces[0]) {
t.Fatal("iface != ifaces[0]")
}
})
t.Run("GetIFaceByIndex", func(t *testing.T) {
t.Parallel()
iface, err := GetIFaceByIndex(1)
if err != nil {
t.Fatal(err)
}
if !reflect.DeepEqual(iface, ifaces[0]) {
t.Fatal("iface != ifaces[0]")
}
})
}