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/bsdp/bsdp_option_server_priority_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/bsdp/bsdp_option_server_priority_test.go')
-rw-r--r-- | dhcpv4/bsdp/bsdp_option_server_priority_test.go | 12 |
1 files changed, 3 insertions, 9 deletions
diff --git a/dhcpv4/bsdp/bsdp_option_server_priority_test.go b/dhcpv4/bsdp/bsdp_option_server_priority_test.go index d12ad55..cbcef1d 100644 --- a/dhcpv4/bsdp/bsdp_option_server_priority_test.go +++ b/dhcpv4/bsdp/bsdp_option_server_priority_test.go @@ -22,16 +22,10 @@ func TestParseOptServerPriority(t *testing.T) { o, err = ParseOptServerPriority([]byte{}) require.Error(t, err, "empty byte stream") - o, err = ParseOptServerPriority([]byte{4, 2, 1}) + o, err = ParseOptServerPriority([]byte{1}) require.Error(t, err, "short byte stream") - o, err = ParseOptServerPriority([]byte{4, 3, 1, 1}) - require.Error(t, err, "wrong priority length") - - o, err = ParseOptServerPriority([]byte{53, 2, 168, 1}) - require.Error(t, err, "wrong option code") - - o, err = ParseOptServerPriority([]byte{4, 2, 0, 100}) + o, err = ParseOptServerPriority([]byte{0, 100}) require.NoError(t, err) - require.Equal(t, 100, o.Priority) + require.Equal(t, uint16(100), o.Priority) } |