MCPcopy Create free account
hub / github.com/pion/ice / TestInitExtIPMapping

Function TestInitExtIPMapping

agent_test.go:1605–1656  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1603}
1604
1605func TestInitExtIPMapping(t *testing.T) {
1606 defer test.CheckRoutines(t)()
1607
1608 // agent.addressRewriteMapper should be nil by default
1609 agent, err := NewAgent(&AgentConfig{})
1610 require.NoError(t, err)
1611 require.Nil(t, agent.addressRewriteMapper)
1612 require.NoError(t, agent.Close())
1613
1614 // a.addressRewriteMapper should be nil when NAT1To1IPs is a non-nil empty array
1615 agent, err = NewAgent(&AgentConfig{
1616 NAT1To1IPs: []string{},
1617 NAT1To1IPCandidateType: CandidateTypeHost,
1618 })
1619 require.NoError(t, err)
1620 require.Nil(t, agent.addressRewriteMapper)
1621 require.NoError(t, agent.Close())
1622
1623 // NewAgent should return an error when 1:1 NAT for host candidate is enabled
1624 // but the candidate type does not appear in the CandidateTypes.
1625 _, err = NewAgent(&AgentConfig{
1626 NAT1To1IPs: []string{"1.2.3.4"},
1627 NAT1To1IPCandidateType: CandidateTypeHost,
1628 CandidateTypes: []CandidateType{CandidateTypeRelay},
1629 })
1630 require.ErrorIs(t, ErrIneffectiveNAT1To1IPMappingHost, err)
1631
1632 // NewAgent should return an error when 1:1 NAT for srflx candidate is enabled
1633 // but the candidate type does not appear in the CandidateTypes.
1634 _, err = NewAgent(&AgentConfig{
1635 NAT1To1IPs: []string{"1.2.3.4"},
1636 NAT1To1IPCandidateType: CandidateTypeServerReflexive,
1637 CandidateTypes: []CandidateType{CandidateTypeRelay},
1638 })
1639 require.ErrorIs(t, ErrIneffectiveNAT1To1IPMappingSrflx, err)
1640
1641 // NewAgent should return an error when 1:1 NAT for host candidate is enabled
1642 // along with mDNS with MulticastDNSModeQueryAndGather
1643 _, err = NewAgent(&AgentConfig{
1644 NAT1To1IPs: []string{"1.2.3.4"},
1645 NAT1To1IPCandidateType: CandidateTypeHost,
1646 MulticastDNSMode: MulticastDNSModeQueryAndGather,
1647 })
1648 require.ErrorIs(t, ErrMulticastDNSWithNAT1To1IPMapping, err)
1649
1650 // NewAgent should return if newAddressRewriteMapper() returns an error.
1651 _, err = NewAgent(&AgentConfig{
1652 NAT1To1IPs: []string{"bad.2.3.4"}, // Bad IP
1653 NAT1To1IPCandidateType: CandidateTypeHost,
1654 })
1655 require.ErrorIs(t, ErrInvalidNAT1To1IPMapping, err)
1656}
1657
1658func TestBindingRequestTimeout(t *testing.T) {
1659 defer test.CheckRoutines(t)()

Callers

nothing calls this directly

Calls 2

CloseMethod · 0.95
NewAgentFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…