summaryrefslogtreecommitdiffhomepage
path: root/dhcpv4/option_generic_test.go
diff options
context:
space:
mode:
authorChristopher Koch <chrisko@google.com>2018-12-29 14:48:10 -0800
committerinsomniac <insomniacslk@users.noreply.github.com>2019-01-24 08:05:49 +0000
commitc90ab10024ada840e24bb028a3405961e8e4c26a (patch)
tree9b8af0c1b80ee6efc112921f9a14b92d6c73f8eb /dhcpv4/option_generic_test.go
parent2be5cae32d33f01ddecf6f167a9c0e5290e6d58f (diff)
dhcpv4: nicer API for option parsing.
From: r := d.GetOneOption(OptionRouter).(*OptRouter).Routers d.UpdateOption(&OptRouter{Routers: []net.IP{net.IP{192, 168, 0, 1}}}) To: r := GetRouter(d.Options) d.UpdateOption(OptRouter(net.IP{192, 168, 0, 1}, ...))
Diffstat (limited to 'dhcpv4/option_generic_test.go')
-rw-r--r--dhcpv4/option_generic_test.go40
1 files changed, 6 insertions, 34 deletions
diff --git a/dhcpv4/option_generic_test.go b/dhcpv4/option_generic_test.go
index ee35d65..4c4f2e8 100644
--- a/dhcpv4/option_generic_test.go
+++ b/dhcpv4/option_generic_test.go
@@ -6,42 +6,14 @@ import (
"github.com/stretchr/testify/require"
)
-func TestParseOptionGeneric(t *testing.T) {
- // Empty bytestream produces error
- _, err := ParseOptionGeneric(OptionHostName, []byte{})
- require.Error(t, err, "error from empty bytestream")
-}
-
func TestOptionGenericCode(t *testing.T) {
- o := OptionGeneric{
- OptionCode: OptionDHCPMessageType,
- Data: []byte{byte(MessageTypeDiscover)},
- }
- require.Equal(t, OptionDHCPMessageType, o.Code())
-}
-
-func TestOptionGenericToBytes(t *testing.T) {
- o := OptionGeneric{
- OptionCode: OptionDHCPMessageType,
- Data: []byte{byte(MessageTypeDiscover)},
- }
- serialized := o.ToBytes()
- expected := []byte{1}
- require.Equal(t, expected, serialized)
-}
-
-func TestOptionGenericString(t *testing.T) {
- o := OptionGeneric{
- OptionCode: OptionDHCPMessageType,
- Data: []byte{byte(MessageTypeDiscover)},
- }
- require.Equal(t, "DHCP Message Type -> [1]", o.String())
+ o := OptGeneric(OptionDHCPMessageType, []byte{byte(MessageTypeDiscover)})
+ require.Equal(t, OptionDHCPMessageType, o.Code)
+ require.Equal(t, []byte{1}, o.Value.ToBytes())
+ require.Equal(t, "DHCP Message Type: [1]", o.String())
}
func TestOptionGenericStringUnknown(t *testing.T) {
- o := OptionGeneric{
- OptionCode: optionCode(102), // Returned option code.
- Data: []byte{byte(MessageTypeDiscover)},
- }
- require.Equal(t, "unknown (102) -> [1]", o.String())
+ o := OptGeneric(optionCode(102), []byte{byte(MessageTypeDiscover)})
+ require.Equal(t, "unknown (102): [1]", o.String())
}