diff options
author | Christopher Koch <chrisko@google.com> | 2018-12-28 20:19:14 -0800 |
---|---|---|
committer | insomniac <insomniacslk@users.noreply.github.com> | 2019-01-10 23:01:22 +0000 |
commit | e87114a6e449d7a2e458b5529923e5668dfa3a11 (patch) | |
tree | 7c5ec350c8eb859400a159b881081ffe0dbd4ef0 /dhcpv4/option_generic_test.go | |
parent | 108ed92e1c9901936541020bc3214533acce77bb (diff) |
dhcpv4: simplify option parsing.
option's codes and lengths were being parsed twice: once in ParseOption
and once in each option type's Parse implementation. Consolidate such
that it only happens once.
Additionally, only pass data to options that they should parse -- we
know the length before the Parse function is called, so the option only
gets to see the data it needs to see.
Also, use uio.Lexer to simplify parsing code in general. Easier to read
and reason about.
Diffstat (limited to 'dhcpv4/option_generic_test.go')
-rw-r--r-- | dhcpv4/option_generic_test.go | 10 |
1 files changed, 1 insertions, 9 deletions
diff --git a/dhcpv4/option_generic_test.go b/dhcpv4/option_generic_test.go index dbc0fc1..5c34903 100644 --- a/dhcpv4/option_generic_test.go +++ b/dhcpv4/option_generic_test.go @@ -8,7 +8,7 @@ import ( func TestParseOptionGeneric(t *testing.T) { // Empty bytestream produces error - _, err := ParseOptionGeneric([]byte{}) + _, err := ParseOptionGeneric(OptionHostName, []byte{}) require.Error(t, err, "error from empty bytestream") } @@ -20,14 +20,6 @@ func TestOptionGenericCode(t *testing.T) { require.Equal(t, OptionDHCPMessageType, o.Code()) } -func TestOptionGenericData(t *testing.T) { - o := OptionGeneric{ - OptionCode: OptionNameServer, - Data: []byte{192, 168, 0, 1}, - } - require.Equal(t, []byte{192, 168, 0, 1}, o.Data) -} - func TestOptionGenericToBytes(t *testing.T) { o := OptionGeneric{ OptionCode: OptionDHCPMessageType, |