File: request_test.go

package info (click to toggle)
golang-github-mdlayher-dhcp6 0.0~git20190311.2a67805-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 400 kB
  • sloc: makefile: 3
file content (51 lines) | stat: -rw-r--r-- 1,138 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package dhcp6server

import (
	"net"
	"reflect"
	"testing"

	"github.com/mdlayher/dhcp6"
	"github.com/mdlayher/dhcp6/dhcp6opts"
)

// TestParseRequest verifies that ParseRequest returns a consistent
// Request struct for use in Handler types.
func TestParseRequest(t *testing.T) {
	p := &dhcp6.Packet{
		MessageType:   dhcp6.MessageTypeSolicit,
		TransactionID: [3]byte{1, 2, 3},
		Options:       make(dhcp6.Options),
	}
	var uuid [16]byte
	p.Options.Add(dhcp6.OptionClientID, dhcp6opts.NewDUIDUUID(uuid))

	addr := &net.UDPAddr{
		IP:   net.ParseIP("::1"),
		Port: 546,
	}

	buf, err := p.MarshalBinary()
	if err != nil {
		t.Fatal(err)
	}

	r := &Request{
		MessageType:   p.MessageType,
		TransactionID: p.TransactionID,
		Options:       make(dhcp6.Options),
		Length:        int64(len(buf)),
		RemoteAddr:    "[::1]:546",
	}
	r.Options.Add(dhcp6.OptionClientID, dhcp6opts.NewDUIDUUID(uuid))

	gotR, err := ParseRequest(buf, addr)
	if err != nil {
		t.Fatal(err)
	}

	if want, got := r, gotR; !reflect.DeepEqual(want, got) {
		t.Fatalf("unexpected Request for ParseRequest(%v, %v)\n- want: %v\n-  got: %v",
			p, addr, want, got)
	}
}