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
|
package dhcpv4
import (
"net"
"testing"
"github.com/stretchr/testify/require"
)
func TestOptSubnetMask(t *testing.T) {
o := OptSubnetMask(net.IPMask{255, 255, 255, 0})
require.Equal(t, o.Code, OptionSubnetMask, "Code")
require.Equal(t, "Subnet Mask: ffffff00", o.String(), "String")
require.Equal(t, []byte{255, 255, 255, 0}, o.Value.ToBytes(), "ToBytes")
}
func TestGetSubnetMask(t *testing.T) {
m, _ := New(WithOption(OptSubnetMask(net.IPMask{})))
mask := m.SubnetMask()
require.Nil(t, mask, "empty byte stream")
m, _ = New(WithOption(OptSubnetMask(net.IPMask{255})))
mask = m.SubnetMask()
require.Nil(t, mask, "short byte stream")
m, _ = New(WithOption(OptSubnetMask(net.IPMask{255, 255, 255, 0})))
mask = m.SubnetMask()
require.Equal(t, net.IPMask{255, 255, 255, 0}, mask)
}
|