(t *testing.T)
| 1454 | } |
| 1455 | |
| 1456 | func TestLocalCandidateStats(t *testing.T) { //nolint:cyclop |
| 1457 | defer test.CheckRoutines(t)() |
| 1458 | |
| 1459 | // Avoid deadlocks? |
| 1460 | defer test.TimeOut(1 * time.Second).Stop() |
| 1461 | |
| 1462 | agent, err := NewAgent(&AgentConfig{}) |
| 1463 | require.NoError(t, err) |
| 1464 | defer func() { |
| 1465 | require.NoError(t, agent.Close()) |
| 1466 | }() |
| 1467 | |
| 1468 | hostConfig := &CandidateHostConfig{ |
| 1469 | Network: "udp", |
| 1470 | Address: "192.168.1.1", |
| 1471 | Port: 19216, |
| 1472 | Component: 1, |
| 1473 | } |
| 1474 | hostLocal, err := NewCandidateHost(hostConfig) |
| 1475 | require.NoError(t, err) |
| 1476 | |
| 1477 | srflxConfig := &CandidateServerReflexiveConfig{ |
| 1478 | Network: "udp", |
| 1479 | Address: "192.168.1.1", |
| 1480 | Port: 19217, |
| 1481 | Component: 1, |
| 1482 | RelAddr: "4.3.2.1", |
| 1483 | RelPort: 43212, |
| 1484 | } |
| 1485 | srflxLocal, err := NewCandidateServerReflexive(srflxConfig) |
| 1486 | require.NoError(t, err) |
| 1487 | |
| 1488 | agent.localCandidates[NetworkTypeUDP4] = []Candidate{hostLocal, srflxLocal} |
| 1489 | |
| 1490 | localStats := agent.GetLocalCandidatesStats() |
| 1491 | require.Len(t, localStats, 2) |
| 1492 | |
| 1493 | var hostLocalStat, srflxLocalStat CandidateStats |
| 1494 | for _, stats := range localStats { |
| 1495 | var candidate Candidate |
| 1496 | switch stats.ID { |
| 1497 | case hostLocal.ID(): |
| 1498 | hostLocalStat = stats |
| 1499 | candidate = hostLocal |
| 1500 | case srflxLocal.ID(): |
| 1501 | srflxLocalStat = stats |
| 1502 | candidate = srflxLocal |
| 1503 | default: |
| 1504 | t.Fatal("invalid local candidate ID") // nolint |
| 1505 | } |
| 1506 | |
| 1507 | require.Equal(t, stats.CandidateType, candidate.Type()) |
| 1508 | require.Equal(t, stats.Priority, candidate.Priority()) |
| 1509 | require.Equal(t, stats.IP, candidate.Address()) |
| 1510 | } |
| 1511 | |
| 1512 | require.Equal(t, hostLocalStat.ID, hostLocal.ID()) |
| 1513 | require.Equal(t, srflxLocalStat.ID, srflxLocal.ID()) |
nothing calls this directly
no test coverage detected
searching dependent graphs…