File: recorder_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 (42 lines) | stat: -rw-r--r-- 1,019 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
package dhcp6test

import (
	"bytes"
	"reflect"
	"testing"

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

// TestRecorder verifies that a Recorder properly captures information
// when a message is sent.
func TestRecorder(t *testing.T) {
	mt := dhcp6.MessageTypeAdvertise
	txID := [3]byte{0, 1, 2}
	clientID := dhcp6opts.NewDUIDLL(1, []byte{0, 1, 0, 1, 0, 1})

	r := NewRecorder(txID)
	if err := r.Options().Add(dhcp6.OptionClientID, clientID); err != nil {
		t.Fatal(err)
	}

	if _, err := r.Send(mt); err != nil {
		t.Fatal(err)
	}

	if want, got := mt, r.MessageType; want != got {
		t.Fatalf("unexpected message type: %v != %v", want, got)
	}
	if want, got := txID[:], r.TransactionID[:]; !bytes.Equal(want, got) {
		t.Fatalf("unexpected transaction ID: %v != %v", want, got)
	}

	duid, err := dhcp6opts.GetClientID(r.Options())
	if err != nil {
		t.Fatal(err)
	}
	if want, got := clientID, duid; !reflect.DeepEqual(want, got) {
		t.Fatalf("unexpected client ID: %v != %v", want, got)
	}
}