-
Notifications
You must be signed in to change notification settings - Fork 162
/
agent_get_best_valid_candidate_pair_test.go
57 lines (43 loc) · 1.55 KB
/
agent_get_best_valid_candidate_pair_test.go
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
52
53
54
55
56
57
// SPDX-FileCopyrightText: 2023 The Pion community <https://pion.ly>
// SPDX-License-Identifier: MIT
//go:build !js
// +build !js
package ice
import (
"testing"
"github.com/stretchr/testify/require"
)
func TestAgentGetBestValidCandidatePair(t *testing.T) {
f := setupTestAgentGetBestValidCandidatePair(t)
defer func() {
require.NoError(t, f.sut.Close())
}()
remoteCandidatesFromLowestPriorityToHighest := []Candidate{f.relayRemote, f.srflxRemote, f.prflxRemote, f.hostRemote}
for _, remoteCandidate := range remoteCandidatesFromLowestPriorityToHighest {
candidatePair := f.sut.addPair(f.hostLocal, remoteCandidate)
candidatePair.state = CandidatePairStateSucceeded
actualBestPair := f.sut.getBestValidCandidatePair()
expectedBestPair := &CandidatePair{Remote: remoteCandidate, Local: f.hostLocal, state: CandidatePairStateSucceeded}
require.Equal(t, actualBestPair.String(), expectedBestPair.String())
}
}
func setupTestAgentGetBestValidCandidatePair(t *testing.T) *TestAgentGetBestValidCandidatePairFixture {
fixture := new(TestAgentGetBestValidCandidatePairFixture)
fixture.hostLocal = newHostLocal(t)
fixture.relayRemote = newRelayRemote(t)
fixture.srflxRemote = newSrflxRemote(t)
fixture.prflxRemote = newPrflxRemote(t)
fixture.hostRemote = newHostRemote(t)
agent, err := NewAgent(&AgentConfig{})
require.NoError(t, err)
fixture.sut = agent
return fixture
}
type TestAgentGetBestValidCandidatePairFixture struct {
sut *Agent
hostLocal Candidate
relayRemote Candidate
srflxRemote Candidate
prflxRemote Candidate
hostRemote Candidate
}