forked from icedream/go-stagelinq
-
Notifications
You must be signed in to change notification settings - Fork 1
/
util_test.go
55 lines (50 loc) · 1.15 KB
/
util_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
package stagelinq
import (
"net"
"testing"
"github.com/stretchr/testify/require"
)
func Test_getPort(t *testing.T) {
require.Equal(t, 12345, getPort(&net.TCPAddr{
IP: net.IPv4(1, 2, 3, 4),
Port: 12345,
}))
require.Equal(t, 12345, getPort(&net.UDPAddr{
IP: net.IPv4(1, 2, 3, 4),
Port: 12345,
}))
}
func Test_makeBroadcastIP(t *testing.T) {
testValues := []struct {
IP net.IP
Mask net.IPMask
ExpectedValue net.IP
}{
{
IP: net.IPv4(1, 2, 3, 4),
Mask: net.IPv4Mask(255, 0, 0, 0),
ExpectedValue: net.IPv4(1, 255, 255, 255),
},
{
IP: net.IPv4(1, 2, 3, 4),
Mask: net.IPv4Mask(255, 255, 0, 0),
ExpectedValue: net.IPv4(1, 2, 255, 255),
},
{
IP: net.IPv4(1, 2, 3, 4),
Mask: net.IPv4Mask(255, 255, 255, 0),
ExpectedValue: net.IPv4(1, 2, 3, 255),
},
{
IP: net.IPv4(1, 2, 3, 4),
Mask: net.IPv4Mask(255, 255, 255, 254),
ExpectedValue: net.IPv4(1, 2, 3, 5),
},
}
for _, testValue := range testValues {
require.Equal(t, testValue.ExpectedValue, makeBroadcastIP(
testValue.IP,
testValue.Mask,
))
}
}