Skip to content

Commit

Permalink
Add tests for Agent.Get{Local,Remote}Candidates()
Browse files Browse the repository at this point in the history
  • Loading branch information
stv0g committed Jul 4, 2023
1 parent ef63705 commit 52bac76
Showing 1 changed file with 68 additions and 0 deletions.
68 changes: 68 additions & 0 deletions agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1322,6 +1322,74 @@ func TestGetRemoteCredentials(t *testing.T) {
assert.NoError(t, a.Close())
}

func TestGetRemoteCandidates(t *testing.T) {
var config AgentConfig

a, err := NewAgent(&config)
if err != nil {
t.Fatalf("Error constructing ice.Agent: %v", err)
}

expectedCandidates := []Candidate{}

for i := 0; i < 5; i++ {
cfg := CandidateHostConfig{
Network: "udp",
Address: "192.168.0.2",
Port: 1000 + i,
Component: 1,
}

cand, errCand := NewCandidateHost(&cfg)
assert.NoError(t, errCand)

expectedCandidates = append(expectedCandidates, cand)

a.addRemoteCandidate(cand)
}

actualCandidates, err := a.GetRemoteCandidates()
assert.NoError(t, err)
assert.ElementsMatch(t, expectedCandidates, actualCandidates)

assert.NoError(t, a.Close())
}

func TestGetLocalCandidates(t *testing.T) {
var config AgentConfig

a, err := NewAgent(&config)
if err != nil {
t.Fatalf("Error constructing ice.Agent: %v", err)
}

dummyConn := &net.UDPConn{}
expectedCandidates := []Candidate{}

for i := 0; i < 5; i++ {
cfg := CandidateHostConfig{
Network: "udp",
Address: "192.168.0.2",
Port: 1000 + i,
Component: 1,
}

cand, errCand := NewCandidateHost(&cfg)
assert.NoError(t, errCand)

expectedCandidates = append(expectedCandidates, cand)

err = a.addCandidate(context.Background(), cand, dummyConn)
assert.NoError(t, err)
}

actualCandidates, err := a.GetLocalCandidates()
assert.NoError(t, err)
assert.ElementsMatch(t, expectedCandidates, actualCandidates)

assert.NoError(t, a.Close())
}

func TestCloseInConnectionStateCallback(t *testing.T) {
report := test.CheckRoutines(t)
defer report()
Expand Down

0 comments on commit 52bac76

Please sign in to comment.