File: chrome_test.go

package info (click to toggle)
golang-github-pion-turn.v2 2.1.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bookworm-backports, forky, sid, trixie
  • size: 716 kB
  • sloc: makefile: 4
file content (40 lines) | stat: -rw-r--r-- 801 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
package proto

import (
	"bufio"
	"bytes"
	"encoding/hex"
	"testing"

	"github.com/pion/stun"
)

func TestChromeAllocRequest(t *testing.T) {
	var (
		r = bytes.NewReader(loadData(t, "01_chromeallocreq.hex"))
		s = bufio.NewScanner(r)

		data     [][]byte
		messages []*stun.Message
	)
	// Decoding hex data into binary.
	for s.Scan() {
		b, err := hex.DecodeString(s.Text())
		if err != nil {
			t.Fatal(err)
		}
		data = append(data, b)
	}
	// All hex streams decoded to raw binary format and stored in data slice.
	// Decoding packets to messages.
	for i, packet := range data {
		m := new(stun.Message)
		if _, err := m.Write(packet); err != nil {
			t.Errorf("Packet %d: %v", i, err)
		}
		messages = append(messages, m)
	}
	if len(messages) != 4 {
		t.Error("unexpected message slice list")
	}
}