forked from sabhiram/go-wol
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmagic_packet_test.go
More file actions
75 lines (66 loc) · 1.58 KB
/
magic_packet_test.go
File metadata and controls
75 lines (66 loc) · 1.58 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 wol
import (
"github.com/stretchr/testify/assert"
"net"
"testing"
)
func TestNewMagicPacket(test *testing.T) {
var PositiveTestCases = []struct {
mac string
expected MACAddress
}{
{"00:00:00:00:00:00", MACAddress{0, 0, 0, 0, 0, 0}},
{"00:ff:01:03:00:00", MACAddress{0, 255, 1, 3, 0, 0}},
{"00-ff-01-03-00-00", MACAddress{0, 255, 1, 3, 0, 0}},
}
for _, t := range PositiveTestCases {
pkt, err := NewMagicPacket(t.mac)
for _, v := range pkt.header {
assert.Equal(test, int(v), 255)
}
for _, mac := range pkt.payload {
assert.Equal(test, t.expected, mac)
}
assert.Equal(test, err, nil)
}
}
func TestNewMagicPacketNegative(test *testing.T) {
var NegativeTestCases = []struct {
mac string
}{
{"00x00:00:00:00:00"},
{"00:00:Z0:00:00:00"},
}
for _, t := range NegativeTestCases {
_, err := NewMagicPacket(t.mac)
assert.NotNil(test, err)
}
}
func TestGetIpFromInterface(test *testing.T) {
interfaces, err := net.Interfaces()
assert.Nil(test, err)
// We can't actually enforce that we get a valid IP, but
// either the error or the pointer should be nil
for _, i := range interfaces {
addr, err := GetIpFromInterface(i.Name)
if err == nil {
assert.NotNil(test, addr)
} else {
assert.Nil(test, addr)
}
}
}
func TestGetIpFromInterfaceNegative(test *testing.T) {
// Test some fake interfaces
var NegativeTestCases = []struct {
iface string
}{
{"fake-interface-0"},
{"fake-interface-1"},
}
for _, t := range NegativeTestCases {
addr, err := GetIpFromInterface(t.iface)
assert.Nil(test, addr)
assert.NotNil(test, err)
}
}