summaryrefslogtreecommitdiffhomepage
path: root/dhcpv4/option_userclass_test.go
diff options
context:
space:
mode:
authorSean Karlage <skarlage@fb.com>2018-08-11 14:30:48 -0700
committerSean Karlage <skarlage@fb.com>2018-08-11 14:32:26 -0700
commit8ea2525c898436a2a935580de67727bbe7035c85 (patch)
tree69d35d17c238feabb07ef07a907aae5520104911 /dhcpv4/option_userclass_test.go
parent2b05c7d03724d31529886d98f738499ac06ead7e (diff)
parenta6212f1f72e94821a29894fb66656a981bd035d0 (diff)
Merge branch 'master' into dhcpv4-moar-tests
Diffstat (limited to 'dhcpv4/option_userclass_test.go')
-rw-r--r--dhcpv4/option_userclass_test.go57
1 files changed, 47 insertions, 10 deletions
diff --git a/dhcpv4/option_userclass_test.go b/dhcpv4/option_userclass_test.go
index 5b71ea5..f6039df 100644
--- a/dhcpv4/option_userclass_test.go
+++ b/dhcpv4/option_userclass_test.go
@@ -9,16 +9,30 @@ import (
func TestOptUserClassToBytes(t *testing.T) {
opt := OptUserClass{
UserClasses: [][]byte{[]byte("linuxboot")},
+ Rfc3004: true,
}
data := opt.ToBytes()
expected := []byte{
- 77, // OPTION_USER_CLASS
+ 77, // OptionUserClass
10, // length
9, 'l', 'i', 'n', 'u', 'x', 'b', 'o', 'o', 't',
}
require.Equal(t, expected, data)
}
+func TestOptUserClassMicrosoftToBytes(t *testing.T) {
+ opt := OptUserClass{
+ UserClasses: [][]byte{[]byte("linuxboot")},
+ }
+ data := opt.ToBytes()
+ expected := []byte{
+ 77, // OptionUserClass
+ 9, // length
+ 'l', 'i', 'n', 'u', 'x', 'b', 'o', 'o', 't',
+ }
+ require.Equal(t, expected, data)
+}
+
func TestParseOptUserClassMultiple(t *testing.T) {
expected := []byte{
77, 15,
@@ -38,6 +52,36 @@ func TestParseOptUserClassNone(t *testing.T) {
require.Error(t, err)
}
+func TestParseOptUserClassMicrosoft(t *testing.T) {
+ expected := []byte{
+ 77, 9, 'l', 'i', 'n', 'u', 'x', 'b', 'o', 'o', 't',
+ }
+ opt, err := ParseOptUserClass(expected)
+ require.NoError(t, err)
+ require.Equal(t, 1, len(opt.UserClasses))
+ require.Equal(t, []byte("linuxboot"), opt.UserClasses[0])
+}
+
+func TestParseOptUserClassMicrosoftShort(t *testing.T) {
+ expected := []byte{
+ 77, 1, 'l',
+ }
+ opt, err := ParseOptUserClass(expected)
+ require.NoError(t, err)
+ require.Equal(t, 1, len(opt.UserClasses))
+ require.Equal(t, []byte("l"), opt.UserClasses[0])
+}
+
+func TestParseOptUserClassMicrosoftLongerThanLength(t *testing.T) {
+ expected := []byte{
+ 77, 9, 'l', 'i', 'n', 'u', 'x', 'b', 'o', 'o', 't', 'X',
+ }
+ opt, err := ParseOptUserClass(expected)
+ require.NoError(t, err)
+ require.Equal(t, 1, len(opt.UserClasses))
+ require.Equal(t, []byte("linuxboot"), opt.UserClasses[0])
+}
+
func TestParseOptUserClass(t *testing.T) {
expected := []byte{
77, 10, 9, 'l', 'i', 'n', 'u', 'x', 'b', 'o', 'o', 't',
@@ -54,10 +98,11 @@ func TestOptUserClassToBytesMultiple(t *testing.T) {
[]byte("linuxboot"),
[]byte("test"),
},
+ Rfc3004: true,
}
data := opt.ToBytes()
expected := []byte{
- 77, // OPTION_USER_CLASS
+ 77, // OptionUserClass
15, // length
9, 'l', 'i', 'n', 'u', 'x', 'b', 'o', 'o', 't',
4, 't', 'e', 's', 't',
@@ -75,14 +120,6 @@ func TestParseOptUserClassLongerThanLength(t *testing.T) {
require.Equal(t, []byte("linuxboot"), opt.UserClasses[0])
}
-func TestParseOptUserClassShorterThanLength(t *testing.T) {
- expected := []byte{
- 77, 10, 10, 'l', 'i', 'n', 'u', 'x', 'b', 'o', 'o', 't',
- }
- _, err := ParseOptUserClass(expected)
- require.Error(t, err)
-}
-
func TestParseOptUserClassShorterTotalLength(t *testing.T) {
expected := []byte{
77, 11, 10, 'l', 'i', 'n', 'u', 'x', 'b', 'o', 'o', 't',