File: alpn_test.go

package info (click to toggle)
golang-github-pion-dtls-v3 3.0.7-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 2,124 kB
  • sloc: makefile: 4
file content (36 lines) | stat: -rw-r--r-- 1,000 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
// SPDX-FileCopyrightText: 2023 The Pion community <https://pion.ly>
// SPDX-License-Identifier: MIT

package extension

import (
	"testing"

	"github.com/stretchr/testify/assert"
)

func TestALPN(t *testing.T) {
	extension := ALPN{
		ProtocolNameList: []string{"http/1.1", "spdy/1", "spdy/2", "spdy/3"},
	}

	raw, err := extension.Marshal()
	assert.NoError(t, err)

	newExtension := ALPN{}
	assert.NoError(t, newExtension.Unmarshal(raw))
	assert.Equal(t, extension.ProtocolNameList, newExtension.ProtocolNameList)
}

func TestALPNProtocolSelection(t *testing.T) {
	selectedProtocol, err := ALPNProtocolSelection([]string{"http/1.1", "spd/1"}, []string{"spd/1"})
	assert.NoError(t, err)
	assert.Equal(t, "spd/1", selectedProtocol)

	_, err = ALPNProtocolSelection([]string{"http/1.1"}, []string{"spd/1"})
	assert.ErrorIs(t, err, errALPNNoAppProto)

	selectedProtocol, err = ALPNProtocolSelection([]string{"http/1.1", "spd/1"}, []string{})
	assert.NoError(t, err)
	assert.Empty(t, selectedProtocol)
}