summaryrefslogtreecommitdiffhomepage
path: root/dhcpv4/dhcpv4_test.go
diff options
context:
space:
mode:
authorPablo Mazzini <pmazzini@gmail.com>2018-07-29 11:10:52 +0100
committerinsomniac <insomniacslk@users.noreply.github.com>2018-07-29 11:10:52 +0100
commitb30145cf5536cc1a134ad83cfce21f0b7249cf84 (patch)
tree3837752ad20321eda2ef03735cace1203cedad18 /dhcpv4/dhcpv4_test.go
parent46ce21cd90de7e082c7ef2eaefb6e499fa80fb3a (diff)
add NewReplyFromRequest (#100)
Diffstat (limited to 'dhcpv4/dhcpv4_test.go')
-rw-r--r--dhcpv4/dhcpv4_test.go30
1 files changed, 30 insertions, 0 deletions
diff --git a/dhcpv4/dhcpv4_test.go b/dhcpv4/dhcpv4_test.go
index 9d44810..55e082d 100644
--- a/dhcpv4/dhcpv4_test.go
+++ b/dhcpv4/dhcpv4_test.go
@@ -290,6 +290,8 @@ func TestNewToBytes(t *testing.T) {
}
// Magic Cookie
expected = append(expected, MagicCookie...)
+ // End
+ expected = append(expected, 0xff)
d, err := New()
require.NoError(t, err)
@@ -322,6 +324,24 @@ func TestGetOption(t *testing.T) {
require.Equal(t, d.GetOneOption(OptionRouter), nil)
}
+func TestAddOption(t *testing.T) {
+ d, err := New()
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ hostnameOpt := &OptionGeneric{OptionCode: OptionHostName, Data: []byte("darkstar")}
+ bootFileOpt1 := &OptionGeneric{OptionCode: OptionBootfileName, Data: []byte("boot.img")}
+ bootFileOpt2 := &OptionGeneric{OptionCode: OptionBootfileName, Data: []byte("boot2.img")}
+ d.AddOption(hostnameOpt)
+ d.AddOption(bootFileOpt1)
+ d.AddOption(bootFileOpt2)
+
+ options := d.Options()
+ require.Equal(t, len(options), 4)
+ require.Equal(t, options[3].Code(), OptionEnd)
+}
+
func TestDHCPv4RequestFromOffer(t *testing.T) {
offer, err := New()
require.NoError(t, err)
@@ -333,6 +353,16 @@ func TestDHCPv4RequestFromOffer(t *testing.T) {
require.Equal(t, MessageTypeRequest, *req.MessageType())
}
+func TestNewReplyFromRequest(t *testing.T) {
+ discover, err := New()
+ require.NoError(t, err)
+ discover.SetGatewayIPAddr(net.IPv4(192, 168, 0, 1))
+ reply, err := NewReplyFromRequest(discover)
+ require.NoError(t, err)
+ require.Equal(t, discover.TransactionID(), reply.TransactionID())
+ require.Equal(t, discover.GatewayIPAddr(), reply.GatewayIPAddr())
+}
+
func TestDHCPv4MessageTypeNil(t *testing.T) {
m, err := New()
require.NoError(t, err)