mirror of
https://github.com/pion/ice.git
synced 2025-09-26 19:41:11 +08:00
Use testify/require instead of testify/assert
Don't continue to run a test if it has already failed
This commit is contained in:

committed by
Sean DuBois

parent
fdca6c47c0
commit
05ab684741
@@ -14,7 +14,6 @@ import (
|
||||
"github.com/pion/logging"
|
||||
"github.com/pion/transport/v3/stdnet"
|
||||
"github.com/pion/transport/v3/test"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
@@ -199,12 +198,12 @@ func TestActiveTCP_NonBlocking(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
assert.NoError(t, aAgent.AddRemoteCandidate(invalidCandidate))
|
||||
assert.NoError(t, bAgent.AddRemoteCandidate(invalidCandidate))
|
||||
require.NoError(t, aAgent.AddRemoteCandidate(invalidCandidate))
|
||||
require.NoError(t, bAgent.AddRemoteCandidate(invalidCandidate))
|
||||
|
||||
connect(aAgent, bAgent)
|
||||
|
||||
<-isConnected
|
||||
assert.NoError(t, aAgent.Close())
|
||||
assert.NoError(t, bAgent.Close())
|
||||
require.NoError(t, aAgent.Close())
|
||||
require.NoError(t, bAgent.Close())
|
||||
}
|
||||
|
@@ -9,7 +9,6 @@ package ice
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
@@ -28,7 +27,7 @@ func TestAgentGetBestValidCandidatePair(t *testing.T) {
|
||||
require.Equal(t, actualBestPair.String(), expectedBestPair.String())
|
||||
}
|
||||
|
||||
assert.NoError(t, f.sut.Close())
|
||||
require.NoError(t, f.sut.Close())
|
||||
}
|
||||
|
||||
func setupTestAgentGetBestValidCandidatePair(t *testing.T) *TestAgentGetBestValidCandidatePairFixture {
|
||||
|
299
agent_test.go
299
agent_test.go
@@ -20,7 +20,6 @@ import (
|
||||
"github.com/pion/stun/v2"
|
||||
"github.com/pion/transport/v3/test"
|
||||
"github.com/pion/transport/v3/vnet"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
@@ -44,9 +43,9 @@ func TestHandlePeerReflexive(t *testing.T) {
|
||||
|
||||
t.Run("UDP prflx candidate from handleInbound()", func(t *testing.T) {
|
||||
a, err := NewAgent(&AgentConfig{})
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.NoError(t, a.loop.Run(a.loop, func(_ context.Context) {
|
||||
require.NoError(t, a.loop.Run(a.loop, func(_ context.Context) {
|
||||
a.selector = &controllingSelector{agent: a, log: a.log}
|
||||
|
||||
hostConfig := CandidateHostConfig{
|
||||
@@ -103,14 +102,14 @@ func TestHandlePeerReflexive(t *testing.T) {
|
||||
t.Fatal("Port number mismatch")
|
||||
}
|
||||
}))
|
||||
assert.NoError(t, a.Close())
|
||||
require.NoError(t, a.Close())
|
||||
})
|
||||
|
||||
t.Run("Bad network type with handleInbound()", func(t *testing.T) {
|
||||
a, err := NewAgent(&AgentConfig{})
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.NoError(t, a.loop.Run(a.loop, func(_ context.Context) {
|
||||
require.NoError(t, a.loop.Run(a.loop, func(_ context.Context) {
|
||||
a.selector = &controllingSelector{agent: a, log: a.log}
|
||||
|
||||
hostConfig := CandidateHostConfig{
|
||||
@@ -134,14 +133,14 @@ func TestHandlePeerReflexive(t *testing.T) {
|
||||
}
|
||||
}))
|
||||
|
||||
assert.NoError(t, a.Close())
|
||||
require.NoError(t, a.Close())
|
||||
})
|
||||
|
||||
t.Run("Success from unknown remote, prflx candidate MUST only be created via Binding Request", func(t *testing.T) {
|
||||
a, err := NewAgent(&AgentConfig{})
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.NoError(t, a.loop.Run(a.loop, func(_ context.Context) {
|
||||
require.NoError(t, a.loop.Run(a.loop, func(_ context.Context) {
|
||||
a.selector = &controllingSelector{agent: a, log: a.log}
|
||||
tID := [stun.TransactionIDSize]byte{}
|
||||
copy(tID[:], "ABC")
|
||||
@@ -177,7 +176,7 @@ func TestHandlePeerReflexive(t *testing.T) {
|
||||
}
|
||||
}))
|
||||
|
||||
assert.NoError(t, a.Close())
|
||||
require.NoError(t, a.Close())
|
||||
})
|
||||
}
|
||||
|
||||
@@ -195,21 +194,21 @@ func TestConnectivityOnStartup(t *testing.T) {
|
||||
CIDR: "0.0.0.0/0",
|
||||
LoggerFactory: logging.NewDefaultLoggerFactory(),
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
net0, err := vnet.NewNet(&vnet.NetConfig{
|
||||
StaticIPs: []string{"192.168.0.1"},
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
assert.NoError(t, wan.AddNet(net0))
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, wan.AddNet(net0))
|
||||
|
||||
net1, err := vnet.NewNet(&vnet.NetConfig{
|
||||
StaticIPs: []string{"192.168.0.2"},
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
assert.NoError(t, wan.AddNet(net1))
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, wan.AddNet(net1))
|
||||
|
||||
assert.NoError(t, wan.Start())
|
||||
require.NoError(t, wan.Start())
|
||||
|
||||
aNotifier, aConnected := onConnected()
|
||||
bNotifier, bConnected := onConnected()
|
||||
@@ -242,10 +241,10 @@ func TestConnectivityOnStartup(t *testing.T) {
|
||||
aConn, bConn := func(aAgent, bAgent *Agent) (*Conn, *Conn) {
|
||||
// Manual signaling
|
||||
aUfrag, aPwd, err := aAgent.GetLocalUserCredentials()
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
bUfrag, bPwd, err := bAgent.GetLocalUserCredentials()
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
gatherAndExchangeCandidates(aAgent, bAgent)
|
||||
|
||||
@@ -288,10 +287,8 @@ func TestConnectivityOnStartup(t *testing.T) {
|
||||
<-aConnected
|
||||
<-bConnected
|
||||
|
||||
assert.NoError(t, wan.Stop())
|
||||
if !closePipe(t, aConn, bConn) {
|
||||
return
|
||||
}
|
||||
require.NoError(t, wan.Stop())
|
||||
closePipe(t, aConn, bConn)
|
||||
}
|
||||
|
||||
func TestConnectivityLite(t *testing.T) {
|
||||
@@ -350,9 +347,7 @@ func TestConnectivityLite(t *testing.T) {
|
||||
<-aConnected
|
||||
<-bConnected
|
||||
|
||||
if !closePipe(t, aConn, bConn) {
|
||||
return
|
||||
}
|
||||
closePipe(t, aConn, bConn)
|
||||
}
|
||||
|
||||
func TestInboundValidity(t *testing.T) {
|
||||
@@ -401,7 +396,7 @@ func TestInboundValidity(t *testing.T) {
|
||||
t.Fatal("Binding with invalid MessageIntegrity was able to create prflx candidate")
|
||||
}
|
||||
|
||||
assert.NoError(t, a.Close())
|
||||
require.NoError(t, a.Close())
|
||||
})
|
||||
|
||||
t.Run("Invalid Binding success responses should be discarded", func(t *testing.T) {
|
||||
@@ -415,7 +410,7 @@ func TestInboundValidity(t *testing.T) {
|
||||
t.Fatal("Binding with invalid MessageIntegrity was able to create prflx candidate")
|
||||
}
|
||||
|
||||
assert.NoError(t, a.Close())
|
||||
require.NoError(t, a.Close())
|
||||
})
|
||||
|
||||
t.Run("Discard non-binding messages", func(t *testing.T) {
|
||||
@@ -429,7 +424,7 @@ func TestInboundValidity(t *testing.T) {
|
||||
t.Fatal("non-binding message was able to create prflxRemote")
|
||||
}
|
||||
|
||||
assert.NoError(t, a.Close())
|
||||
require.NoError(t, a.Close())
|
||||
})
|
||||
|
||||
t.Run("Valid bind request", func(t *testing.T) {
|
||||
@@ -447,15 +442,15 @@ func TestInboundValidity(t *testing.T) {
|
||||
}
|
||||
})
|
||||
|
||||
assert.NoError(t, err)
|
||||
assert.NoError(t, a.Close())
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, a.Close())
|
||||
})
|
||||
|
||||
t.Run("Valid bind without fingerprint", func(t *testing.T) {
|
||||
a, err := NewAgent(&AgentConfig{})
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.NoError(t, a.loop.Run(a.loop, func(_ context.Context) {
|
||||
require.NoError(t, a.loop.Run(a.loop, func(_ context.Context) {
|
||||
a.selector = &controllingSelector{agent: a, log: a.log}
|
||||
msg, err := stun.Build(stun.BindingRequest, stun.TransactionID,
|
||||
stun.NewUsername(a.localUfrag+":"+a.remoteUfrag),
|
||||
@@ -472,7 +467,7 @@ func TestInboundValidity(t *testing.T) {
|
||||
}
|
||||
}))
|
||||
|
||||
assert.NoError(t, a.Close())
|
||||
require.NoError(t, a.Close())
|
||||
})
|
||||
|
||||
t.Run("Success with invalid TransactionID", func(t *testing.T) {
|
||||
@@ -500,14 +495,14 @@ func TestInboundValidity(t *testing.T) {
|
||||
stun.NewShortTermIntegrity(a.remotePwd),
|
||||
stun.Fingerprint,
|
||||
)
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
a.handleInbound(msg, local, remote)
|
||||
if len(a.remoteCandidates) != 0 {
|
||||
t.Fatal("unknown remote was able to create a candidate")
|
||||
}
|
||||
|
||||
assert.NoError(t, a.Close())
|
||||
require.NoError(t, a.Close())
|
||||
})
|
||||
}
|
||||
|
||||
@@ -516,7 +511,7 @@ func TestInvalidAgentStarts(t *testing.T) {
|
||||
defer report()
|
||||
|
||||
a, err := NewAgent(&AgentConfig{})
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
ctx := context.Background()
|
||||
ctx, cancel := context.WithTimeout(ctx, 100*time.Millisecond)
|
||||
@@ -538,7 +533,7 @@ func TestInvalidAgentStarts(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
assert.NoError(t, a.Close())
|
||||
require.NoError(t, a.Close())
|
||||
}
|
||||
|
||||
// Assert that Agent emits Connecting/Connected/Disconnected/Failed/Closed messages
|
||||
@@ -602,8 +597,8 @@ func TestConnectionStateCallback(t *testing.T) {
|
||||
<-isDisconnected
|
||||
<-isFailed
|
||||
|
||||
assert.NoError(t, aAgent.Close())
|
||||
assert.NoError(t, bAgent.Close())
|
||||
require.NoError(t, aAgent.Close())
|
||||
require.NoError(t, bAgent.Close())
|
||||
|
||||
<-isClosed
|
||||
}
|
||||
@@ -619,7 +614,7 @@ func TestInvalidGather(t *testing.T) {
|
||||
if !errors.Is(err, ErrNoOnCandidateHandler) {
|
||||
t.Fatal("trickle GatherCandidates succeeded without OnCandidate")
|
||||
}
|
||||
assert.NoError(t, a.Close())
|
||||
require.NoError(t, a.Close())
|
||||
})
|
||||
}
|
||||
|
||||
@@ -753,7 +748,7 @@ func TestCandidatePairStats(t *testing.T) {
|
||||
prflxPairStat.State.String())
|
||||
}
|
||||
|
||||
assert.NoError(t, a.Close())
|
||||
require.NoError(t, a.Close())
|
||||
}
|
||||
|
||||
func TestLocalCandidateStats(t *testing.T) {
|
||||
@@ -834,7 +829,7 @@ func TestLocalCandidateStats(t *testing.T) {
|
||||
t.Fatal("missing srflx local stat")
|
||||
}
|
||||
|
||||
assert.NoError(t, a.Close())
|
||||
require.NoError(t, a.Close())
|
||||
}
|
||||
|
||||
func TestRemoteCandidateStats(t *testing.T) {
|
||||
@@ -954,7 +949,7 @@ func TestRemoteCandidateStats(t *testing.T) {
|
||||
t.Fatal("missing host remote stat")
|
||||
}
|
||||
|
||||
assert.NoError(t, a.Close())
|
||||
require.NoError(t, a.Close())
|
||||
}
|
||||
|
||||
func TestInitExtIPMapping(t *testing.T) {
|
||||
@@ -969,7 +964,7 @@ func TestInitExtIPMapping(t *testing.T) {
|
||||
if a.extIPMapper != nil {
|
||||
t.Fatal("a.extIPMapper should be nil by default")
|
||||
}
|
||||
assert.NoError(t, a.Close())
|
||||
require.NoError(t, a.Close())
|
||||
|
||||
// a.extIPMapper should be nil when NAT1To1IPs is a non-nil empty array
|
||||
a, err = NewAgent(&AgentConfig{
|
||||
@@ -982,7 +977,7 @@ func TestInitExtIPMapping(t *testing.T) {
|
||||
if a.extIPMapper != nil {
|
||||
t.Fatal("a.extIPMapper should be nil by default")
|
||||
}
|
||||
assert.NoError(t, a.Close())
|
||||
require.NoError(t, a.Close())
|
||||
|
||||
// NewAgent should return an error when 1:1 NAT for host candidate is enabled
|
||||
// but the candidate type does not appear in the CandidateTypes.
|
||||
@@ -1034,7 +1029,7 @@ func TestBindingRequestTimeout(t *testing.T) {
|
||||
const expectedRemovalCount = 2
|
||||
|
||||
a, err := NewAgent(&AgentConfig{})
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
now := time.Now()
|
||||
a.pendingBindingRequests = append(a.pendingBindingRequests, bindingRequest{
|
||||
@@ -1051,8 +1046,8 @@ func TestBindingRequestTimeout(t *testing.T) {
|
||||
})
|
||||
|
||||
a.invalidatePendingBindingRequests(now)
|
||||
assert.Equal(t, expectedRemovalCount, len(a.pendingBindingRequests), "Binding invalidation due to timeout did not remove the correct number of binding requests")
|
||||
assert.NoError(t, a.Close())
|
||||
require.Equal(t, expectedRemovalCount, len(a.pendingBindingRequests), "Binding invalidation due to timeout did not remove the correct number of binding requests")
|
||||
require.NoError(t, a.Close())
|
||||
}
|
||||
|
||||
// TestAgentCredentials checks if local username fragments and passwords (if set) meet RFC standard
|
||||
@@ -1069,10 +1064,10 @@ func TestAgentCredentials(t *testing.T) {
|
||||
// If set, they should follow the default 16/128 bits random number generator strategy
|
||||
|
||||
agent, err := NewAgent(&AgentConfig{LoggerFactory: log})
|
||||
assert.NoError(t, err)
|
||||
assert.GreaterOrEqual(t, len([]rune(agent.localUfrag))*8, 24)
|
||||
assert.GreaterOrEqual(t, len([]rune(agent.localPwd))*8, 128)
|
||||
assert.NoError(t, agent.Close())
|
||||
require.NoError(t, err)
|
||||
require.GreaterOrEqual(t, len([]rune(agent.localUfrag))*8, 24)
|
||||
require.GreaterOrEqual(t, len([]rune(agent.localPwd))*8, 128)
|
||||
require.NoError(t, agent.Close())
|
||||
|
||||
// Should honor RFC standards
|
||||
// Local values MUST be unguessable, with at least 128 bits of
|
||||
@@ -1080,10 +1075,10 @@ func TestAgentCredentials(t *testing.T) {
|
||||
// at least 24 bits of output to generate the username fragment.
|
||||
|
||||
_, err = NewAgent(&AgentConfig{LocalUfrag: "xx", LoggerFactory: log})
|
||||
assert.EqualError(t, err, ErrLocalUfragInsufficientBits.Error())
|
||||
require.EqualError(t, err, ErrLocalUfragInsufficientBits.Error())
|
||||
|
||||
_, err = NewAgent(&AgentConfig{LocalPwd: "xxxxxx", LoggerFactory: log})
|
||||
assert.EqualError(t, err, ErrLocalPwdInsufficientBits.Error())
|
||||
require.EqualError(t, err, ErrLocalPwdInsufficientBits.Error())
|
||||
}
|
||||
|
||||
// Assert that Agent on Failure deletes all existing candidates
|
||||
@@ -1106,13 +1101,13 @@ func TestConnectionStateFailedDeleteAllCandidates(t *testing.T) {
|
||||
}
|
||||
|
||||
aAgent, err := NewAgent(cfg)
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
bAgent, err := NewAgent(cfg)
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
isFailed := make(chan interface{})
|
||||
assert.NoError(t, aAgent.OnConnectionStateChange(func(c ConnectionState) {
|
||||
require.NoError(t, aAgent.OnConnectionStateChange(func(c ConnectionState) {
|
||||
if c == ConnectionStateFailed {
|
||||
close(isFailed)
|
||||
}
|
||||
@@ -1122,15 +1117,15 @@ func TestConnectionStateFailedDeleteAllCandidates(t *testing.T) {
|
||||
<-isFailed
|
||||
|
||||
done := make(chan struct{})
|
||||
assert.NoError(t, aAgent.loop.Run(aAgent.loop, func(context.Context) {
|
||||
assert.Equal(t, len(aAgent.remoteCandidates), 0)
|
||||
assert.Equal(t, len(aAgent.localCandidates), 0)
|
||||
require.NoError(t, aAgent.loop.Run(context.Background(), func(context.Context) {
|
||||
require.Equal(t, len(aAgent.remoteCandidates), 0)
|
||||
require.Equal(t, len(aAgent.localCandidates), 0)
|
||||
close(done)
|
||||
}))
|
||||
<-done
|
||||
|
||||
assert.NoError(t, aAgent.Close())
|
||||
assert.NoError(t, bAgent.Close())
|
||||
require.NoError(t, aAgent.Close())
|
||||
require.NoError(t, bAgent.Close())
|
||||
}
|
||||
|
||||
// Assert that the ICE Agent can go directly from Connecting -> Failed on both sides
|
||||
@@ -1151,10 +1146,10 @@ func TestConnectionStateConnectingToFailed(t *testing.T) {
|
||||
}
|
||||
|
||||
aAgent, err := NewAgent(cfg)
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
bAgent, err := NewAgent(cfg)
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
var isFailed sync.WaitGroup
|
||||
var isChecking sync.WaitGroup
|
||||
@@ -1174,24 +1169,24 @@ func TestConnectionStateConnectingToFailed(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
assert.NoError(t, aAgent.OnConnectionStateChange(connectionStateCheck))
|
||||
assert.NoError(t, bAgent.OnConnectionStateChange(connectionStateCheck))
|
||||
require.NoError(t, aAgent.OnConnectionStateChange(connectionStateCheck))
|
||||
require.NoError(t, bAgent.OnConnectionStateChange(connectionStateCheck))
|
||||
|
||||
go func() {
|
||||
_, err := aAgent.Accept(context.TODO(), "InvalidFrag", "InvalidPwd")
|
||||
assert.Error(t, err)
|
||||
require.Error(t, err)
|
||||
}()
|
||||
|
||||
go func() {
|
||||
_, err := bAgent.Dial(context.TODO(), "InvalidFrag", "InvalidPwd")
|
||||
assert.Error(t, err)
|
||||
require.Error(t, err)
|
||||
}()
|
||||
|
||||
isChecking.Wait()
|
||||
isFailed.Wait()
|
||||
|
||||
assert.NoError(t, aAgent.Close())
|
||||
assert.NoError(t, bAgent.Close())
|
||||
require.NoError(t, aAgent.Close())
|
||||
require.NoError(t, bAgent.Close())
|
||||
}
|
||||
|
||||
func TestAgentRestart(t *testing.T) {
|
||||
@@ -1210,26 +1205,26 @@ func TestAgentRestart(t *testing.T) {
|
||||
})
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
assert.NoError(t, connB.agent.OnConnectionStateChange(func(c ConnectionState) {
|
||||
require.NoError(t, connB.agent.OnConnectionStateChange(func(c ConnectionState) {
|
||||
if c == ConnectionStateFailed || c == ConnectionStateDisconnected {
|
||||
cancel()
|
||||
}
|
||||
}))
|
||||
|
||||
connA.agent.gatheringState = GatheringStateGathering
|
||||
assert.NoError(t, connA.agent.Restart("", ""))
|
||||
require.NoError(t, connA.agent.Restart("", ""))
|
||||
|
||||
<-ctx.Done()
|
||||
assert.NoError(t, connA.agent.Close())
|
||||
assert.NoError(t, connB.agent.Close())
|
||||
require.NoError(t, connA.agent.Close())
|
||||
require.NoError(t, connB.agent.Close())
|
||||
})
|
||||
|
||||
t.Run("Restart When Closed", func(t *testing.T) {
|
||||
agent, err := NewAgent(&AgentConfig{})
|
||||
assert.NoError(t, err)
|
||||
assert.NoError(t, agent.Close())
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, agent.Close())
|
||||
|
||||
assert.Equal(t, ErrClosed, agent.Restart("", ""))
|
||||
require.Equal(t, ErrClosed, agent.Restart("", ""))
|
||||
})
|
||||
|
||||
t.Run("Restart One Side", func(t *testing.T) {
|
||||
@@ -1239,22 +1234,22 @@ func TestAgentRestart(t *testing.T) {
|
||||
})
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
assert.NoError(t, connB.agent.OnConnectionStateChange(func(c ConnectionState) {
|
||||
require.NoError(t, connB.agent.OnConnectionStateChange(func(c ConnectionState) {
|
||||
if c == ConnectionStateFailed || c == ConnectionStateDisconnected {
|
||||
cancel()
|
||||
}
|
||||
}))
|
||||
assert.NoError(t, connA.agent.Restart("", ""))
|
||||
require.NoError(t, connA.agent.Restart("", ""))
|
||||
|
||||
<-ctx.Done()
|
||||
assert.NoError(t, connA.agent.Close())
|
||||
assert.NoError(t, connB.agent.Close())
|
||||
require.NoError(t, connA.agent.Close())
|
||||
require.NoError(t, connB.agent.Close())
|
||||
})
|
||||
|
||||
t.Run("Restart Both Sides", func(t *testing.T) {
|
||||
// Get all addresses of candidates concatenated
|
||||
generateCandidateAddressStrings := func(candidates []Candidate, err error) (out string) {
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
for _, c := range candidates {
|
||||
out += c.Address() + ":"
|
||||
@@ -1272,23 +1267,23 @@ func TestAgentRestart(t *testing.T) {
|
||||
connBFirstCandidates := generateCandidateAddressStrings(connB.agent.GetLocalCandidates())
|
||||
|
||||
aNotifier, aConnected := onConnected()
|
||||
assert.NoError(t, connA.agent.OnConnectionStateChange(aNotifier))
|
||||
require.NoError(t, connA.agent.OnConnectionStateChange(aNotifier))
|
||||
|
||||
bNotifier, bConnected := onConnected()
|
||||
assert.NoError(t, connB.agent.OnConnectionStateChange(bNotifier))
|
||||
require.NoError(t, connB.agent.OnConnectionStateChange(bNotifier))
|
||||
|
||||
// Restart and Re-Signal
|
||||
assert.NoError(t, connA.agent.Restart("", ""))
|
||||
assert.NoError(t, connB.agent.Restart("", ""))
|
||||
require.NoError(t, connA.agent.Restart("", ""))
|
||||
require.NoError(t, connB.agent.Restart("", ""))
|
||||
|
||||
// Exchange Candidates and Credentials
|
||||
ufrag, pwd, err := connB.agent.GetLocalUserCredentials()
|
||||
assert.NoError(t, err)
|
||||
assert.NoError(t, connA.agent.SetRemoteCredentials(ufrag, pwd))
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, connA.agent.SetRemoteCredentials(ufrag, pwd))
|
||||
|
||||
ufrag, pwd, err = connA.agent.GetLocalUserCredentials()
|
||||
assert.NoError(t, err)
|
||||
assert.NoError(t, connB.agent.SetRemoteCredentials(ufrag, pwd))
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, connB.agent.SetRemoteCredentials(ufrag, pwd))
|
||||
|
||||
gatherAndExchangeCandidates(connA.agent, connB.agent)
|
||||
|
||||
@@ -1297,11 +1292,11 @@ func TestAgentRestart(t *testing.T) {
|
||||
<-bConnected
|
||||
|
||||
// Assert that we have new candidates each time
|
||||
assert.NotEqual(t, connAFirstCandidates, generateCandidateAddressStrings(connA.agent.GetLocalCandidates()))
|
||||
assert.NotEqual(t, connBFirstCandidates, generateCandidateAddressStrings(connB.agent.GetLocalCandidates()))
|
||||
require.NotEqual(t, connAFirstCandidates, generateCandidateAddressStrings(connA.agent.GetLocalCandidates()))
|
||||
require.NotEqual(t, connBFirstCandidates, generateCandidateAddressStrings(connB.agent.GetLocalCandidates()))
|
||||
|
||||
assert.NoError(t, connA.agent.Close())
|
||||
assert.NoError(t, connB.agent.Close())
|
||||
require.NoError(t, connA.agent.Close())
|
||||
require.NoError(t, connB.agent.Close())
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1316,12 +1311,12 @@ func TestGetRemoteCredentials(t *testing.T) {
|
||||
a.remotePwd = "remotePwd"
|
||||
|
||||
actualUfrag, actualPwd, err := a.GetRemoteUserCredentials()
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, actualUfrag, a.remoteUfrag)
|
||||
assert.Equal(t, actualPwd, a.remotePwd)
|
||||
require.Equal(t, actualUfrag, a.remoteUfrag)
|
||||
require.Equal(t, actualPwd, a.remotePwd)
|
||||
|
||||
assert.NoError(t, a.Close())
|
||||
require.NoError(t, a.Close())
|
||||
}
|
||||
|
||||
func TestGetRemoteCandidates(t *testing.T) {
|
||||
@@ -1343,7 +1338,7 @@ func TestGetRemoteCandidates(t *testing.T) {
|
||||
}
|
||||
|
||||
cand, errCand := NewCandidateHost(&cfg)
|
||||
assert.NoError(t, errCand)
|
||||
require.NoError(t, errCand)
|
||||
|
||||
expectedCandidates = append(expectedCandidates, cand)
|
||||
|
||||
@@ -1351,10 +1346,10 @@ func TestGetRemoteCandidates(t *testing.T) {
|
||||
}
|
||||
|
||||
actualCandidates, err := a.GetRemoteCandidates()
|
||||
assert.NoError(t, err)
|
||||
assert.ElementsMatch(t, expectedCandidates, actualCandidates)
|
||||
require.NoError(t, err)
|
||||
require.ElementsMatch(t, expectedCandidates, actualCandidates)
|
||||
|
||||
assert.NoError(t, a.Close())
|
||||
require.NoError(t, a.Close())
|
||||
}
|
||||
|
||||
func TestGetLocalCandidates(t *testing.T) {
|
||||
@@ -1377,19 +1372,19 @@ func TestGetLocalCandidates(t *testing.T) {
|
||||
}
|
||||
|
||||
cand, errCand := NewCandidateHost(&cfg)
|
||||
assert.NoError(t, errCand)
|
||||
require.NoError(t, errCand)
|
||||
|
||||
expectedCandidates = append(expectedCandidates, cand)
|
||||
|
||||
err = a.addCandidate(context.Background(), cand, dummyConn)
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
actualCandidates, err := a.GetLocalCandidates()
|
||||
assert.NoError(t, err)
|
||||
assert.ElementsMatch(t, expectedCandidates, actualCandidates)
|
||||
require.NoError(t, err)
|
||||
require.ElementsMatch(t, expectedCandidates, actualCandidates)
|
||||
|
||||
assert.NoError(t, a.Close())
|
||||
require.NoError(t, a.Close())
|
||||
}
|
||||
|
||||
func TestCloseInConnectionStateCallback(t *testing.T) {
|
||||
@@ -1429,7 +1424,7 @@ func TestCloseInConnectionStateCallback(t *testing.T) {
|
||||
switch c {
|
||||
case ConnectionStateConnected:
|
||||
<-isConnected
|
||||
assert.NoError(t, aAgent.Close())
|
||||
require.NoError(t, aAgent.Close())
|
||||
case ConnectionStateClosed:
|
||||
close(isClosed)
|
||||
default:
|
||||
@@ -1443,7 +1438,7 @@ func TestCloseInConnectionStateCallback(t *testing.T) {
|
||||
close(isConnected)
|
||||
|
||||
<-isClosed
|
||||
assert.NoError(t, bAgent.Close())
|
||||
require.NoError(t, bAgent.Close())
|
||||
}
|
||||
|
||||
func TestRunTaskInConnectionStateCallback(t *testing.T) {
|
||||
@@ -1475,8 +1470,8 @@ func TestRunTaskInConnectionStateCallback(t *testing.T) {
|
||||
err = aAgent.OnConnectionStateChange(func(c ConnectionState) {
|
||||
if c == ConnectionStateConnected {
|
||||
_, _, errCred := aAgent.GetLocalUserCredentials()
|
||||
assert.NoError(t, errCred)
|
||||
assert.NoError(t, aAgent.Restart("", ""))
|
||||
require.NoError(t, errCred)
|
||||
require.NoError(t, aAgent.Restart("", ""))
|
||||
close(isComplete)
|
||||
}
|
||||
})
|
||||
@@ -1487,8 +1482,8 @@ func TestRunTaskInConnectionStateCallback(t *testing.T) {
|
||||
connect(aAgent, bAgent)
|
||||
|
||||
<-isComplete
|
||||
assert.NoError(t, aAgent.Close())
|
||||
assert.NoError(t, bAgent.Close())
|
||||
require.NoError(t, aAgent.Close())
|
||||
require.NoError(t, bAgent.Close())
|
||||
}
|
||||
|
||||
func TestRunTaskInSelectedCandidatePairChangeCallback(t *testing.T) {
|
||||
@@ -1521,7 +1516,7 @@ func TestRunTaskInSelectedCandidatePairChangeCallback(t *testing.T) {
|
||||
if err = aAgent.OnSelectedCandidatePairChange(func(Candidate, Candidate) {
|
||||
go func() {
|
||||
_, _, errCred := aAgent.GetLocalUserCredentials()
|
||||
assert.NoError(t, errCred)
|
||||
require.NoError(t, errCred)
|
||||
close(isTested)
|
||||
}()
|
||||
}); err != nil {
|
||||
@@ -1539,8 +1534,8 @@ func TestRunTaskInSelectedCandidatePairChangeCallback(t *testing.T) {
|
||||
|
||||
<-isComplete
|
||||
<-isTested
|
||||
assert.NoError(t, aAgent.Close())
|
||||
assert.NoError(t, bAgent.Close())
|
||||
require.NoError(t, aAgent.Close())
|
||||
require.NoError(t, bAgent.Close())
|
||||
}
|
||||
|
||||
// Assert that a Lite agent goes to disconnected and failed
|
||||
@@ -1596,27 +1591,27 @@ func TestLiteLifecycle(t *testing.T) {
|
||||
|
||||
<-aConnected
|
||||
<-bConnected
|
||||
assert.NoError(t, aAgent.Close())
|
||||
require.NoError(t, aAgent.Close())
|
||||
|
||||
<-bDisconnected
|
||||
<-bFailed
|
||||
assert.NoError(t, bAgent.Close())
|
||||
require.NoError(t, bAgent.Close())
|
||||
}
|
||||
|
||||
func TestNilCandidate(t *testing.T) {
|
||||
a, err := NewAgent(&AgentConfig{})
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.NoError(t, a.AddRemoteCandidate(nil))
|
||||
assert.NoError(t, a.Close())
|
||||
require.NoError(t, a.AddRemoteCandidate(nil))
|
||||
require.NoError(t, a.Close())
|
||||
}
|
||||
|
||||
func TestNilCandidatePair(t *testing.T) {
|
||||
a, err := NewAgent(&AgentConfig{})
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
a.setSelectedPair(nil)
|
||||
assert.NoError(t, a.Close())
|
||||
require.NoError(t, a.Close())
|
||||
}
|
||||
|
||||
func TestGetSelectedCandidatePair(t *testing.T) {
|
||||
@@ -1630,15 +1625,15 @@ func TestGetSelectedCandidatePair(t *testing.T) {
|
||||
CIDR: "0.0.0.0/0",
|
||||
LoggerFactory: logging.NewDefaultLoggerFactory(),
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
net, err := vnet.NewNet(&vnet.NetConfig{
|
||||
StaticIPs: []string{"192.168.0.1"},
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
assert.NoError(t, wan.AddNet(net))
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, wan.AddNet(net))
|
||||
|
||||
assert.NoError(t, wan.Start())
|
||||
require.NoError(t, wan.Start())
|
||||
|
||||
cfg := &AgentConfig{
|
||||
NetworkTypes: supportedNetworkTypes(),
|
||||
@@ -1646,35 +1641,35 @@ func TestGetSelectedCandidatePair(t *testing.T) {
|
||||
}
|
||||
|
||||
aAgent, err := NewAgent(cfg)
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
bAgent, err := NewAgent(cfg)
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
aAgentPair, err := aAgent.GetSelectedCandidatePair()
|
||||
assert.NoError(t, err)
|
||||
assert.Nil(t, aAgentPair)
|
||||
require.NoError(t, err)
|
||||
require.Nil(t, aAgentPair)
|
||||
|
||||
bAgentPair, err := bAgent.GetSelectedCandidatePair()
|
||||
assert.NoError(t, err)
|
||||
assert.Nil(t, bAgentPair)
|
||||
require.NoError(t, err)
|
||||
require.Nil(t, bAgentPair)
|
||||
|
||||
connect(aAgent, bAgent)
|
||||
|
||||
aAgentPair, err = aAgent.GetSelectedCandidatePair()
|
||||
assert.NoError(t, err)
|
||||
assert.NotNil(t, aAgentPair)
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, aAgentPair)
|
||||
|
||||
bAgentPair, err = bAgent.GetSelectedCandidatePair()
|
||||
assert.NoError(t, err)
|
||||
assert.NotNil(t, bAgentPair)
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, bAgentPair)
|
||||
|
||||
assert.True(t, bAgentPair.Local.Equal(aAgentPair.Remote))
|
||||
assert.True(t, bAgentPair.Remote.Equal(aAgentPair.Local))
|
||||
require.True(t, bAgentPair.Local.Equal(aAgentPair.Remote))
|
||||
require.True(t, bAgentPair.Remote.Equal(aAgentPair.Local))
|
||||
|
||||
assert.NoError(t, wan.Stop())
|
||||
assert.NoError(t, aAgent.Close())
|
||||
assert.NoError(t, bAgent.Close())
|
||||
require.NoError(t, wan.Stop())
|
||||
require.NoError(t, aAgent.Close())
|
||||
require.NoError(t, bAgent.Close())
|
||||
}
|
||||
|
||||
func TestAcceptAggressiveNomination(t *testing.T) {
|
||||
@@ -1689,21 +1684,21 @@ func TestAcceptAggressiveNomination(t *testing.T) {
|
||||
CIDR: "0.0.0.0/0",
|
||||
LoggerFactory: logging.NewDefaultLoggerFactory(),
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
net0, err := vnet.NewNet(&vnet.NetConfig{
|
||||
StaticIPs: []string{"192.168.0.1"},
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
assert.NoError(t, wan.AddNet(net0))
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, wan.AddNet(net0))
|
||||
|
||||
net1, err := vnet.NewNet(&vnet.NetConfig{
|
||||
StaticIPs: []string{"192.168.0.2", "192.168.0.3", "192.168.0.4"},
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
assert.NoError(t, wan.AddNet(net1))
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, wan.AddNet(net1))
|
||||
|
||||
assert.NoError(t, wan.Start())
|
||||
require.NoError(t, wan.Start())
|
||||
|
||||
aNotifier, aConnected := onConnected()
|
||||
bNotifier, bConnected := onConnected()
|
||||
@@ -1791,13 +1786,11 @@ func TestAcceptAggressiveNomination(t *testing.T) {
|
||||
time.Sleep(1 * time.Second)
|
||||
select {
|
||||
case selected := <-selectedCh:
|
||||
assert.True(t, selected.Equal(expectNewSelectedCandidate))
|
||||
require.True(t, selected.Equal(expectNewSelectedCandidate))
|
||||
default:
|
||||
t.Fatal("No selected candidate pair")
|
||||
}
|
||||
|
||||
assert.NoError(t, wan.Stop())
|
||||
if !closePipe(t, aConn, bConn) {
|
||||
return
|
||||
}
|
||||
require.NoError(t, wan.Stop())
|
||||
closePipe(t, aConn, bConn)
|
||||
}
|
||||
|
@@ -15,7 +15,7 @@ import (
|
||||
"github.com/pion/stun/v2"
|
||||
"github.com/pion/transport/v3/test"
|
||||
"github.com/pion/turn/v3"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func optimisticAuthHandler(string, string, net.Addr) (key []byte, ok bool) {
|
||||
@@ -32,7 +32,7 @@ func TestRelayOnlyConnection(t *testing.T) {
|
||||
|
||||
serverPort := randomPort(t)
|
||||
serverListener, err := net.ListenPacket("udp", localhostIPStr+":"+strconv.Itoa(serverPort))
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
server, err := turn.NewServer(turn.ServerConfig{
|
||||
Realm: "pion.ly",
|
||||
@@ -44,7 +44,7 @@ func TestRelayOnlyConnection(t *testing.T) {
|
||||
},
|
||||
},
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
cfg := &AgentConfig{
|
||||
NetworkTypes: supportedNetworkTypes(),
|
||||
@@ -85,7 +85,7 @@ func TestRelayOnlyConnection(t *testing.T) {
|
||||
<-aConnected
|
||||
<-bConnected
|
||||
|
||||
assert.NoError(t, aAgent.Close())
|
||||
assert.NoError(t, bAgent.Close())
|
||||
assert.NoError(t, server.Close())
|
||||
require.NoError(t, aAgent.Close())
|
||||
require.NoError(t, bAgent.Close())
|
||||
require.NoError(t, server.Close())
|
||||
}
|
||||
|
@@ -15,7 +15,7 @@ import (
|
||||
"github.com/pion/stun/v2"
|
||||
"github.com/pion/transport/v3/test"
|
||||
"github.com/pion/turn/v3"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestServerReflexiveOnlyConnection(t *testing.T) {
|
||||
@@ -28,7 +28,7 @@ func TestServerReflexiveOnlyConnection(t *testing.T) {
|
||||
|
||||
serverPort := randomPort(t)
|
||||
serverListener, err := net.ListenPacket("udp4", "127.0.0.1:"+strconv.Itoa(serverPort))
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
server, err := turn.NewServer(turn.ServerConfig{
|
||||
Realm: "pion.ly",
|
||||
@@ -40,7 +40,7 @@ func TestServerReflexiveOnlyConnection(t *testing.T) {
|
||||
},
|
||||
},
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
cfg := &AgentConfig{
|
||||
NetworkTypes: []NetworkType{NetworkTypeUDP4},
|
||||
@@ -78,7 +78,7 @@ func TestServerReflexiveOnlyConnection(t *testing.T) {
|
||||
<-aConnected
|
||||
<-bConnected
|
||||
|
||||
assert.NoError(t, aAgent.Close())
|
||||
assert.NoError(t, bAgent.Close())
|
||||
assert.NoError(t, server.Close())
|
||||
require.NoError(t, aAgent.Close())
|
||||
require.NoError(t, bAgent.Close())
|
||||
require.NoError(t, server.Close())
|
||||
}
|
||||
|
@@ -9,7 +9,6 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/pion/logging"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
@@ -183,23 +182,23 @@ func TestCandidatePriority(t *testing.T) {
|
||||
|
||||
func TestCandidateLastSent(t *testing.T) {
|
||||
candidate := candidateBase{}
|
||||
assert.Equal(t, candidate.LastSent(), time.Time{})
|
||||
require.Equal(t, candidate.LastSent(), time.Time{})
|
||||
now := time.Now()
|
||||
candidate.setLastSent(now)
|
||||
assert.Equal(t, candidate.LastSent(), now)
|
||||
require.Equal(t, candidate.LastSent(), now)
|
||||
}
|
||||
|
||||
func TestCandidateLastReceived(t *testing.T) {
|
||||
candidate := candidateBase{}
|
||||
assert.Equal(t, candidate.LastReceived(), time.Time{})
|
||||
require.Equal(t, candidate.LastReceived(), time.Time{})
|
||||
now := time.Now()
|
||||
candidate.setLastReceived(now)
|
||||
assert.Equal(t, candidate.LastReceived(), now)
|
||||
require.Equal(t, candidate.LastReceived(), now)
|
||||
}
|
||||
|
||||
func TestCandidateFoundation(t *testing.T) {
|
||||
// All fields are the same
|
||||
assert.Equal(t,
|
||||
require.Equal(t,
|
||||
(&candidateBase{
|
||||
candidateType: CandidateTypeHost,
|
||||
networkType: NetworkTypeUDP4,
|
||||
@@ -212,7 +211,7 @@ func TestCandidateFoundation(t *testing.T) {
|
||||
}).Foundation())
|
||||
|
||||
// Different Address
|
||||
assert.NotEqual(t,
|
||||
require.NotEqual(t,
|
||||
(&candidateBase{
|
||||
candidateType: CandidateTypeHost,
|
||||
networkType: NetworkTypeUDP4,
|
||||
@@ -225,7 +224,7 @@ func TestCandidateFoundation(t *testing.T) {
|
||||
}).Foundation())
|
||||
|
||||
// Different networkType
|
||||
assert.NotEqual(t,
|
||||
require.NotEqual(t,
|
||||
(&candidateBase{
|
||||
candidateType: CandidateTypeHost,
|
||||
networkType: NetworkTypeUDP4,
|
||||
@@ -238,7 +237,7 @@ func TestCandidateFoundation(t *testing.T) {
|
||||
}).Foundation())
|
||||
|
||||
// Different candidateType
|
||||
assert.NotEqual(t,
|
||||
require.NotEqual(t,
|
||||
(&candidateBase{
|
||||
candidateType: CandidateTypeHost,
|
||||
networkType: NetworkTypeUDP4,
|
||||
@@ -251,7 +250,7 @@ func TestCandidateFoundation(t *testing.T) {
|
||||
}).Foundation())
|
||||
|
||||
// Port has no effect
|
||||
assert.Equal(t,
|
||||
require.Equal(t,
|
||||
(&candidateBase{
|
||||
candidateType: CandidateTypeHost,
|
||||
networkType: NetworkTypeUDP4,
|
||||
@@ -387,14 +386,14 @@ func TestCandidateMarshal(t *testing.T) {
|
||||
} {
|
||||
actualCandidate, err := UnmarshalCandidate(test.marshaled)
|
||||
if test.expectError {
|
||||
assert.Error(t, err)
|
||||
require.Error(t, err)
|
||||
continue
|
||||
}
|
||||
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.True(t, test.candidate.Equal(actualCandidate))
|
||||
assert.Equal(t, test.marshaled, actualCandidate.Marshal())
|
||||
require.True(t, test.candidate.Equal(actualCandidate))
|
||||
require.Equal(t, test.marshaled, actualCandidate.Marshal())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -429,11 +428,11 @@ func TestCandidateWriteTo(t *testing.T) {
|
||||
}
|
||||
|
||||
_, err = c1.writeTo([]byte("test"), c2)
|
||||
assert.NoError(t, err, "writing to open conn")
|
||||
require.NoError(t, err, "writing to open conn")
|
||||
|
||||
err = packetConn.Close()
|
||||
require.NoError(t, err, "error closing test TCP connection")
|
||||
|
||||
_, err = c1.writeTo([]byte("test"), c2)
|
||||
assert.Error(t, err, "writing to closed conn")
|
||||
require.Error(t, err, "writing to closed conn")
|
||||
}
|
||||
|
@@ -6,7 +6,7 @@ package ice
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func hostCandidate() *CandidateHost {
|
||||
@@ -132,5 +132,5 @@ func TestCandidatePairEquality(t *testing.T) {
|
||||
|
||||
func TestNilCandidatePairString(t *testing.T) {
|
||||
var nilCandidatePair *CandidatePair
|
||||
assert.Equal(t, nilCandidatePair.String(), "")
|
||||
require.Equal(t, nilCandidatePair.String(), "")
|
||||
}
|
||||
|
@@ -19,7 +19,7 @@ import (
|
||||
"github.com/pion/transport/v3/test"
|
||||
"github.com/pion/transport/v3/vnet"
|
||||
"github.com/pion/turn/v3"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -292,13 +292,9 @@ func pipeWithVNet(v *virtualNet, a0TestConfig, a1TestConfig *agentTestConfig) (*
|
||||
return aConn, bConn
|
||||
}
|
||||
|
||||
func closePipe(t *testing.T, ca *Conn, cb *Conn) bool {
|
||||
err := ca.Close()
|
||||
if !assert.NoError(t, err, "should succeed") {
|
||||
return false
|
||||
}
|
||||
err = cb.Close()
|
||||
return assert.NoError(t, err, "should succeed")
|
||||
func closePipe(t *testing.T, ca *Conn, cb *Conn) {
|
||||
require.NoError(t, ca.Close())
|
||||
require.NoError(t, cb.Close())
|
||||
}
|
||||
|
||||
func TestConnectivityVNet(t *testing.T) {
|
||||
@@ -332,9 +328,7 @@ func TestConnectivityVNet(t *testing.T) {
|
||||
}
|
||||
v, err := buildVNet(natType, natType)
|
||||
|
||||
if !assert.NoError(t, err, "should succeed") {
|
||||
return
|
||||
}
|
||||
require.NoError(t, err, "should succeed")
|
||||
defer v.close()
|
||||
|
||||
log.Debug("Connecting...")
|
||||
@@ -353,9 +347,7 @@ func TestConnectivityVNet(t *testing.T) {
|
||||
time.Sleep(1 * time.Second)
|
||||
|
||||
log.Debug("Closing...")
|
||||
if !closePipe(t, ca, cb) {
|
||||
return
|
||||
}
|
||||
closePipe(t, ca, cb)
|
||||
})
|
||||
|
||||
t.Run("Symmetric NATs on both ends", func(t *testing.T) {
|
||||
@@ -369,9 +361,7 @@ func TestConnectivityVNet(t *testing.T) {
|
||||
}
|
||||
v, err := buildVNet(natType, natType)
|
||||
|
||||
if !assert.NoError(t, err, "should succeed") {
|
||||
return
|
||||
}
|
||||
require.NoError(t, err, "should succeed")
|
||||
defer v.close()
|
||||
|
||||
log.Debug("Connecting...")
|
||||
@@ -389,9 +379,7 @@ func TestConnectivityVNet(t *testing.T) {
|
||||
ca, cb := pipeWithVNet(v, a0TestConfig, a1TestConfig)
|
||||
|
||||
log.Debug("Closing...")
|
||||
if !closePipe(t, ca, cb) {
|
||||
return
|
||||
}
|
||||
closePipe(t, ca, cb)
|
||||
})
|
||||
|
||||
t.Run("1:1 NAT with host candidate vs Symmetric NATs", func(t *testing.T) {
|
||||
@@ -409,9 +397,7 @@ func TestConnectivityVNet(t *testing.T) {
|
||||
}
|
||||
v, err := buildVNet(natType0, natType1)
|
||||
|
||||
if !assert.NoError(t, err, "should succeed") {
|
||||
return
|
||||
}
|
||||
require.NoError(t, err, "should succeed")
|
||||
defer v.close()
|
||||
|
||||
log.Debug("Connecting...")
|
||||
@@ -425,9 +411,7 @@ func TestConnectivityVNet(t *testing.T) {
|
||||
ca, cb := pipeWithVNet(v, a0TestConfig, a1TestConfig)
|
||||
|
||||
log.Debug("Closing...")
|
||||
if !closePipe(t, ca, cb) {
|
||||
return
|
||||
}
|
||||
closePipe(t, ca, cb)
|
||||
})
|
||||
|
||||
t.Run("1:1 NAT with srflx candidate vs Symmetric NATs", func(t *testing.T) {
|
||||
@@ -445,9 +429,7 @@ func TestConnectivityVNet(t *testing.T) {
|
||||
}
|
||||
v, err := buildVNet(natType0, natType1)
|
||||
|
||||
if !assert.NoError(t, err, "should succeed") {
|
||||
return
|
||||
}
|
||||
require.NoError(t, err, "should succeed")
|
||||
defer v.close()
|
||||
|
||||
log.Debug("Connecting...")
|
||||
@@ -461,13 +443,11 @@ func TestConnectivityVNet(t *testing.T) {
|
||||
ca, cb := pipeWithVNet(v, a0TestConfig, a1TestConfig)
|
||||
|
||||
log.Debug("Closing...")
|
||||
if !closePipe(t, ca, cb) {
|
||||
return
|
||||
}
|
||||
closePipe(t, ca, cb)
|
||||
})
|
||||
}
|
||||
|
||||
// TestDisconnectedToConnected asserts that an agent can go to disconnected, and then return to connected successfully
|
||||
// TestDisconnectedToConnected requires that an agent can go to disconnected, and then return to connected successfully
|
||||
func TestDisconnectedToConnected(t *testing.T) {
|
||||
report := test.CheckRoutines(t)
|
||||
defer report()
|
||||
@@ -482,7 +462,7 @@ func TestDisconnectedToConnected(t *testing.T) {
|
||||
CIDR: "0.0.0.0/0",
|
||||
LoggerFactory: loggerFactory,
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
var dropAllData uint64
|
||||
wan.AddChunkFilter(func(vnet.Chunk) bool {
|
||||
@@ -492,16 +472,16 @@ func TestDisconnectedToConnected(t *testing.T) {
|
||||
net0, err := vnet.NewNet(&vnet.NetConfig{
|
||||
StaticIPs: []string{"192.168.0.1"},
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
assert.NoError(t, wan.AddNet(net0))
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, wan.AddNet(net0))
|
||||
|
||||
net1, err := vnet.NewNet(&vnet.NetConfig{
|
||||
StaticIPs: []string{"192.168.0.2"},
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
assert.NoError(t, wan.AddNet(net1))
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, wan.AddNet(net1))
|
||||
|
||||
assert.NoError(t, wan.Start())
|
||||
require.NoError(t, wan.Start())
|
||||
|
||||
disconnectTimeout := time.Second
|
||||
keepaliveInterval := time.Millisecond * 20
|
||||
@@ -515,7 +495,7 @@ func TestDisconnectedToConnected(t *testing.T) {
|
||||
KeepaliveInterval: &keepaliveInterval,
|
||||
CheckInterval: &keepaliveInterval,
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
controlledAgent, err := NewAgent(&AgentConfig{
|
||||
NetworkTypes: supportedNetworkTypes(),
|
||||
@@ -525,15 +505,15 @@ func TestDisconnectedToConnected(t *testing.T) {
|
||||
KeepaliveInterval: &keepaliveInterval,
|
||||
CheckInterval: &keepaliveInterval,
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
controllingStateChanges := make(chan ConnectionState, 100)
|
||||
assert.NoError(t, controllingAgent.OnConnectionStateChange(func(c ConnectionState) {
|
||||
require.NoError(t, controllingAgent.OnConnectionStateChange(func(c ConnectionState) {
|
||||
controllingStateChanges <- c
|
||||
}))
|
||||
|
||||
controlledStateChanges := make(chan ConnectionState, 100)
|
||||
assert.NoError(t, controlledAgent.OnConnectionStateChange(func(c ConnectionState) {
|
||||
require.NoError(t, controlledAgent.OnConnectionStateChange(func(c ConnectionState) {
|
||||
controlledStateChanges <- c
|
||||
}))
|
||||
|
||||
@@ -560,9 +540,9 @@ func TestDisconnectedToConnected(t *testing.T) {
|
||||
blockUntilStateSeen(ConnectionStateConnected, controllingStateChanges)
|
||||
blockUntilStateSeen(ConnectionStateConnected, controlledStateChanges)
|
||||
|
||||
assert.NoError(t, wan.Stop())
|
||||
assert.NoError(t, controllingAgent.Close())
|
||||
assert.NoError(t, controlledAgent.Close())
|
||||
require.NoError(t, wan.Stop())
|
||||
require.NoError(t, controllingAgent.Close())
|
||||
require.NoError(t, controlledAgent.Close())
|
||||
}
|
||||
|
||||
// Agent.Write should use the best valid pair if a selected pair is not yet available
|
||||
@@ -580,7 +560,7 @@ func TestWriteUseValidPair(t *testing.T) {
|
||||
CIDR: "0.0.0.0/0",
|
||||
LoggerFactory: loggerFactory,
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
wan.AddChunkFilter(func(c vnet.Chunk) bool {
|
||||
if stun.IsMessage(c.UserData()) {
|
||||
@@ -600,16 +580,16 @@ func TestWriteUseValidPair(t *testing.T) {
|
||||
net0, err := vnet.NewNet(&vnet.NetConfig{
|
||||
StaticIPs: []string{"192.168.0.1"},
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
assert.NoError(t, wan.AddNet(net0))
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, wan.AddNet(net0))
|
||||
|
||||
net1, err := vnet.NewNet(&vnet.NetConfig{
|
||||
StaticIPs: []string{"192.168.0.2"},
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
assert.NoError(t, wan.AddNet(net1))
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, wan.AddNet(net1))
|
||||
|
||||
assert.NoError(t, wan.Start())
|
||||
require.NoError(t, wan.Start())
|
||||
|
||||
// Create two agents and connect them
|
||||
controllingAgent, err := NewAgent(&AgentConfig{
|
||||
@@ -617,25 +597,25 @@ func TestWriteUseValidPair(t *testing.T) {
|
||||
MulticastDNSMode: MulticastDNSModeDisabled,
|
||||
Net: net0,
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
controlledAgent, err := NewAgent(&AgentConfig{
|
||||
NetworkTypes: supportedNetworkTypes(),
|
||||
MulticastDNSMode: MulticastDNSModeDisabled,
|
||||
Net: net1,
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
gatherAndExchangeCandidates(controllingAgent, controlledAgent)
|
||||
|
||||
controllingUfrag, controllingPwd, err := controllingAgent.GetLocalUserCredentials()
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
controlledUfrag, controlledPwd, err := controlledAgent.GetLocalUserCredentials()
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.NoError(t, controllingAgent.startConnectivityChecks(true, controlledUfrag, controlledPwd))
|
||||
assert.NoError(t, controlledAgent.startConnectivityChecks(false, controllingUfrag, controllingPwd))
|
||||
require.NoError(t, controllingAgent.startConnectivityChecks(true, controlledUfrag, controlledPwd))
|
||||
require.NoError(t, controlledAgent.startConnectivityChecks(false, controllingUfrag, controllingPwd))
|
||||
|
||||
testMessage := []byte("Test Message")
|
||||
go func() {
|
||||
@@ -650,11 +630,11 @@ func TestWriteUseValidPair(t *testing.T) {
|
||||
|
||||
readBuf := make([]byte, len(testMessage))
|
||||
_, err = (&Conn{agent: controlledAgent}).Read(readBuf)
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, readBuf, testMessage)
|
||||
require.Equal(t, readBuf, testMessage)
|
||||
|
||||
assert.NoError(t, wan.Stop())
|
||||
assert.NoError(t, controllingAgent.Close())
|
||||
assert.NoError(t, controlledAgent.Close())
|
||||
require.NoError(t, wan.Stop())
|
||||
require.NoError(t, controllingAgent.Close())
|
||||
require.NoError(t, controlledAgent.Close())
|
||||
}
|
||||
|
@@ -7,7 +7,7 @@ import (
|
||||
"net"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestExternalIPMapper(t *testing.T) {
|
||||
@@ -17,17 +17,17 @@ func TestExternalIPMapper(t *testing.T) {
|
||||
var err error
|
||||
|
||||
ip, isIPv4, err = validateIPString("1.2.3.4")
|
||||
assert.NoError(t, err, "should succeed")
|
||||
assert.True(t, isIPv4, "should be true")
|
||||
assert.Equal(t, "1.2.3.4", ip.String(), "should be true")
|
||||
require.NoError(t, err, "should succeed")
|
||||
require.True(t, isIPv4, "should be true")
|
||||
require.Equal(t, "1.2.3.4", ip.String(), "should be true")
|
||||
|
||||
ip, isIPv4, err = validateIPString("2601:4567::5678")
|
||||
assert.NoError(t, err, "should succeed")
|
||||
assert.False(t, isIPv4, "should be false")
|
||||
assert.Equal(t, "2601:4567::5678", ip.String(), "should be true")
|
||||
require.NoError(t, err, "should succeed")
|
||||
require.False(t, isIPv4, "should be false")
|
||||
require.Equal(t, "2601:4567::5678", ip.String(), "should be true")
|
||||
|
||||
_, _, err = validateIPString("bad.6.6.6")
|
||||
assert.Error(t, err, "should fail")
|
||||
require.Error(t, err, "should fail")
|
||||
})
|
||||
|
||||
t.Run("newExternalIPMapper", func(t *testing.T) {
|
||||
@@ -36,106 +36,106 @@ func TestExternalIPMapper(t *testing.T) {
|
||||
|
||||
// ips being nil should succeed but mapper will be nil also
|
||||
m, err = newExternalIPMapper(CandidateTypeUnspecified, nil)
|
||||
assert.NoError(t, err, "should succeed")
|
||||
assert.Nil(t, m, "should be nil")
|
||||
require.NoError(t, err, "should succeed")
|
||||
require.Nil(t, m, "should be nil")
|
||||
|
||||
// ips being empty should succeed but mapper will still be nil
|
||||
m, err = newExternalIPMapper(CandidateTypeUnspecified, []string{})
|
||||
assert.NoError(t, err, "should succeed")
|
||||
assert.Nil(t, m, "should be nil")
|
||||
require.NoError(t, err, "should succeed")
|
||||
require.Nil(t, m, "should be nil")
|
||||
|
||||
// IPv4 with no explicit local IP, defaults to CandidateTypeHost
|
||||
m, err = newExternalIPMapper(CandidateTypeUnspecified, []string{
|
||||
"1.2.3.4",
|
||||
})
|
||||
assert.NoError(t, err, "should succeed")
|
||||
assert.NotNil(t, m, "should not be nil")
|
||||
assert.Equal(t, CandidateTypeHost, m.candidateType, "should match")
|
||||
assert.NotNil(t, m.ipv4Mapping.ipSole)
|
||||
assert.Nil(t, m.ipv6Mapping.ipSole)
|
||||
assert.Equal(t, 0, len(m.ipv4Mapping.ipMap), "should match")
|
||||
assert.Equal(t, 0, len(m.ipv6Mapping.ipMap), "should match")
|
||||
require.NoError(t, err, "should succeed")
|
||||
require.NotNil(t, m, "should not be nil")
|
||||
require.Equal(t, CandidateTypeHost, m.candidateType, "should match")
|
||||
require.NotNil(t, m.ipv4Mapping.ipSole)
|
||||
require.Nil(t, m.ipv6Mapping.ipSole)
|
||||
require.Equal(t, 0, len(m.ipv4Mapping.ipMap), "should match")
|
||||
require.Equal(t, 0, len(m.ipv6Mapping.ipMap), "should match")
|
||||
|
||||
// IPv4 with no explicit local IP, using CandidateTypeServerReflexive
|
||||
m, err = newExternalIPMapper(CandidateTypeServerReflexive, []string{
|
||||
"1.2.3.4",
|
||||
})
|
||||
assert.NoError(t, err, "should succeed")
|
||||
assert.NotNil(t, m, "should not be nil")
|
||||
assert.Equal(t, CandidateTypeServerReflexive, m.candidateType, "should match")
|
||||
assert.NotNil(t, m.ipv4Mapping.ipSole)
|
||||
assert.Nil(t, m.ipv6Mapping.ipSole)
|
||||
assert.Equal(t, 0, len(m.ipv4Mapping.ipMap), "should match")
|
||||
assert.Equal(t, 0, len(m.ipv6Mapping.ipMap), "should match")
|
||||
require.NoError(t, err, "should succeed")
|
||||
require.NotNil(t, m, "should not be nil")
|
||||
require.Equal(t, CandidateTypeServerReflexive, m.candidateType, "should match")
|
||||
require.NotNil(t, m.ipv4Mapping.ipSole)
|
||||
require.Nil(t, m.ipv6Mapping.ipSole)
|
||||
require.Equal(t, 0, len(m.ipv4Mapping.ipMap), "should match")
|
||||
require.Equal(t, 0, len(m.ipv6Mapping.ipMap), "should match")
|
||||
|
||||
// IPv4 with no explicit local IP, defaults to CandidateTypeHost
|
||||
m, err = newExternalIPMapper(CandidateTypeUnspecified, []string{
|
||||
"2601:4567::5678",
|
||||
})
|
||||
assert.NoError(t, err, "should succeed")
|
||||
assert.NotNil(t, m, "should not be nil")
|
||||
assert.Equal(t, CandidateTypeHost, m.candidateType, "should match")
|
||||
assert.Nil(t, m.ipv4Mapping.ipSole)
|
||||
assert.NotNil(t, m.ipv6Mapping.ipSole)
|
||||
assert.Equal(t, 0, len(m.ipv4Mapping.ipMap), "should match")
|
||||
assert.Equal(t, 0, len(m.ipv6Mapping.ipMap), "should match")
|
||||
require.NoError(t, err, "should succeed")
|
||||
require.NotNil(t, m, "should not be nil")
|
||||
require.Equal(t, CandidateTypeHost, m.candidateType, "should match")
|
||||
require.Nil(t, m.ipv4Mapping.ipSole)
|
||||
require.NotNil(t, m.ipv6Mapping.ipSole)
|
||||
require.Equal(t, 0, len(m.ipv4Mapping.ipMap), "should match")
|
||||
require.Equal(t, 0, len(m.ipv6Mapping.ipMap), "should match")
|
||||
|
||||
// IPv4 and IPv6 in the mix
|
||||
m, err = newExternalIPMapper(CandidateTypeUnspecified, []string{
|
||||
"1.2.3.4",
|
||||
"2601:4567::5678",
|
||||
})
|
||||
assert.NoError(t, err, "should succeed")
|
||||
assert.NotNil(t, m, "should not be nil")
|
||||
assert.Equal(t, CandidateTypeHost, m.candidateType, "should match")
|
||||
assert.NotNil(t, m.ipv4Mapping.ipSole)
|
||||
assert.NotNil(t, m.ipv6Mapping.ipSole)
|
||||
assert.Equal(t, 0, len(m.ipv4Mapping.ipMap), "should match")
|
||||
assert.Equal(t, 0, len(m.ipv6Mapping.ipMap), "should match")
|
||||
require.NoError(t, err, "should succeed")
|
||||
require.NotNil(t, m, "should not be nil")
|
||||
require.Equal(t, CandidateTypeHost, m.candidateType, "should match")
|
||||
require.NotNil(t, m.ipv4Mapping.ipSole)
|
||||
require.NotNil(t, m.ipv6Mapping.ipSole)
|
||||
require.Equal(t, 0, len(m.ipv4Mapping.ipMap), "should match")
|
||||
require.Equal(t, 0, len(m.ipv6Mapping.ipMap), "should match")
|
||||
|
||||
// Unsupported candidate type - CandidateTypePeerReflexive
|
||||
m, err = newExternalIPMapper(CandidateTypePeerReflexive, []string{
|
||||
"1.2.3.4",
|
||||
})
|
||||
assert.Error(t, err, "should fail")
|
||||
assert.Nil(t, m, "should be nil")
|
||||
require.Error(t, err, "should fail")
|
||||
require.Nil(t, m, "should be nil")
|
||||
|
||||
// Unsupported candidate type - CandidateTypeRelay
|
||||
m, err = newExternalIPMapper(CandidateTypePeerReflexive, []string{
|
||||
"1.2.3.4",
|
||||
})
|
||||
assert.Error(t, err, "should fail")
|
||||
assert.Nil(t, m, "should be nil")
|
||||
require.Error(t, err, "should fail")
|
||||
require.Nil(t, m, "should be nil")
|
||||
|
||||
// Cannot duplicate mapping IPv4 family
|
||||
m, err = newExternalIPMapper(CandidateTypeServerReflexive, []string{
|
||||
"1.2.3.4",
|
||||
"5.6.7.8",
|
||||
})
|
||||
assert.Error(t, err, "should fail")
|
||||
assert.Nil(t, m, "should be nil")
|
||||
require.Error(t, err, "should fail")
|
||||
require.Nil(t, m, "should be nil")
|
||||
|
||||
// Cannot duplicate mapping IPv6 family
|
||||
m, err = newExternalIPMapper(CandidateTypeServerReflexive, []string{
|
||||
"2201::1",
|
||||
"2201::0002",
|
||||
})
|
||||
assert.Error(t, err, "should fail")
|
||||
assert.Nil(t, m, "should be nil")
|
||||
require.Error(t, err, "should fail")
|
||||
require.Nil(t, m, "should be nil")
|
||||
|
||||
// Invalide external IP string
|
||||
m, err = newExternalIPMapper(CandidateTypeServerReflexive, []string{
|
||||
"bad.2.3.4",
|
||||
})
|
||||
assert.Error(t, err, "should fail")
|
||||
assert.Nil(t, m, "should be nil")
|
||||
require.Error(t, err, "should fail")
|
||||
require.Nil(t, m, "should be nil")
|
||||
|
||||
// Invalide local IP string
|
||||
m, err = newExternalIPMapper(CandidateTypeServerReflexive, []string{
|
||||
"1.2.3.4/10.0.0.bad",
|
||||
})
|
||||
assert.Error(t, err, "should fail")
|
||||
assert.Nil(t, m, "should be nil")
|
||||
require.Error(t, err, "should fail")
|
||||
require.Nil(t, m, "should be nil")
|
||||
})
|
||||
|
||||
t.Run("newExternalIPMapper with explicit local IP", func(t *testing.T) {
|
||||
@@ -146,50 +146,50 @@ func TestExternalIPMapper(t *testing.T) {
|
||||
m, err = newExternalIPMapper(CandidateTypeUnspecified, []string{
|
||||
"1.2.3.4/10.0.0.1",
|
||||
})
|
||||
assert.NoError(t, err, "should succeed")
|
||||
assert.NotNil(t, m, "should not be nil")
|
||||
assert.Equal(t, CandidateTypeHost, m.candidateType, "should match")
|
||||
assert.Nil(t, m.ipv4Mapping.ipSole)
|
||||
assert.Nil(t, m.ipv6Mapping.ipSole)
|
||||
assert.Equal(t, 1, len(m.ipv4Mapping.ipMap), "should match")
|
||||
assert.Equal(t, 0, len(m.ipv6Mapping.ipMap), "should match")
|
||||
require.NoError(t, err, "should succeed")
|
||||
require.NotNil(t, m, "should not be nil")
|
||||
require.Equal(t, CandidateTypeHost, m.candidateType, "should match")
|
||||
require.Nil(t, m.ipv4Mapping.ipSole)
|
||||
require.Nil(t, m.ipv6Mapping.ipSole)
|
||||
require.Equal(t, 1, len(m.ipv4Mapping.ipMap), "should match")
|
||||
require.Equal(t, 0, len(m.ipv6Mapping.ipMap), "should match")
|
||||
|
||||
// Cannot assign two ext IPs for one local IPv4
|
||||
m, err = newExternalIPMapper(CandidateTypeUnspecified, []string{
|
||||
"1.2.3.4/10.0.0.1",
|
||||
"1.2.3.5/10.0.0.1",
|
||||
})
|
||||
assert.Error(t, err, "should fail")
|
||||
assert.Nil(t, m, "should be nil")
|
||||
require.Error(t, err, "should fail")
|
||||
require.Nil(t, m, "should be nil")
|
||||
|
||||
// Cannot assign two ext IPs for one local IPv6
|
||||
m, err = newExternalIPMapper(CandidateTypeUnspecified, []string{
|
||||
"2200::1/fe80::1",
|
||||
"2200::0002/fe80::1",
|
||||
})
|
||||
assert.Error(t, err, "should fail")
|
||||
assert.Nil(t, m, "should be nil")
|
||||
require.Error(t, err, "should fail")
|
||||
require.Nil(t, m, "should be nil")
|
||||
|
||||
// Cannot mix different IP family in a pair (1)
|
||||
m, err = newExternalIPMapper(CandidateTypeUnspecified, []string{
|
||||
"2200::1/10.0.0.1",
|
||||
})
|
||||
assert.Error(t, err, "should fail")
|
||||
assert.Nil(t, m, "should be nil")
|
||||
require.Error(t, err, "should fail")
|
||||
require.Nil(t, m, "should be nil")
|
||||
|
||||
// Cannot mix different IP family in a pair (2)
|
||||
m, err = newExternalIPMapper(CandidateTypeUnspecified, []string{
|
||||
"1.2.3.4/fe80::1",
|
||||
})
|
||||
assert.Error(t, err, "should fail")
|
||||
assert.Nil(t, m, "should be nil")
|
||||
require.Error(t, err, "should fail")
|
||||
require.Nil(t, m, "should be nil")
|
||||
|
||||
// Invalid pair
|
||||
m, err = newExternalIPMapper(CandidateTypeUnspecified, []string{
|
||||
"1.2.3.4/192.168.0.2/10.0.0.1",
|
||||
})
|
||||
assert.Error(t, err, "should fail")
|
||||
assert.Nil(t, m, "should be nil")
|
||||
require.Error(t, err, "should fail")
|
||||
require.Nil(t, m, "should be nil")
|
||||
})
|
||||
|
||||
t.Run("newExternalIPMapper with implicit and explicit local IP", func(t *testing.T) {
|
||||
@@ -198,14 +198,14 @@ func TestExternalIPMapper(t *testing.T) {
|
||||
"1.2.3.4",
|
||||
"1.2.3.5/10.0.0.1",
|
||||
})
|
||||
assert.Error(t, err, "should fail")
|
||||
require.Error(t, err, "should fail")
|
||||
|
||||
// Mixing implicit and explicit local IPs not allowed
|
||||
_, err = newExternalIPMapper(CandidateTypeUnspecified, []string{
|
||||
"1.2.3.5/10.0.0.1",
|
||||
"1.2.3.4",
|
||||
})
|
||||
assert.Error(t, err, "should fail")
|
||||
require.Error(t, err, "should fail")
|
||||
})
|
||||
|
||||
t.Run("findExternalIP without explicit local IP", func(t *testing.T) {
|
||||
@@ -218,24 +218,24 @@ func TestExternalIPMapper(t *testing.T) {
|
||||
"1.2.3.4",
|
||||
"2200::1",
|
||||
})
|
||||
assert.NoError(t, err, "should succeed")
|
||||
assert.NotNil(t, m, "should not be nil")
|
||||
assert.NotNil(t, m.ipv4Mapping.ipSole)
|
||||
assert.NotNil(t, m.ipv6Mapping.ipSole)
|
||||
require.NoError(t, err, "should succeed")
|
||||
require.NotNil(t, m, "should not be nil")
|
||||
require.NotNil(t, m.ipv4Mapping.ipSole)
|
||||
require.NotNil(t, m.ipv6Mapping.ipSole)
|
||||
|
||||
// Find external IPv4
|
||||
extIP, err = m.findExternalIP("10.0.0.1")
|
||||
assert.NoError(t, err, "should succeed")
|
||||
assert.Equal(t, "1.2.3.4", extIP.String(), "should match")
|
||||
require.NoError(t, err, "should succeed")
|
||||
require.Equal(t, "1.2.3.4", extIP.String(), "should match")
|
||||
|
||||
// Find external IPv6
|
||||
extIP, err = m.findExternalIP("fe80::0001") // Use '0001' instead of '1' on purpose
|
||||
assert.NoError(t, err, "should succeed")
|
||||
assert.Equal(t, "2200::1", extIP.String(), "should match")
|
||||
require.NoError(t, err, "should succeed")
|
||||
require.Equal(t, "2200::1", extIP.String(), "should match")
|
||||
|
||||
// Bad local IP string
|
||||
_, err = m.findExternalIP("really.bad")
|
||||
assert.Error(t, err, "should fail")
|
||||
require.Error(t, err, "should fail")
|
||||
})
|
||||
|
||||
t.Run("findExternalIP with explicit local IP", func(t *testing.T) {
|
||||
@@ -250,36 +250,36 @@ func TestExternalIPMapper(t *testing.T) {
|
||||
"2200::1/fe80::1",
|
||||
"2200::2/fe80::2",
|
||||
})
|
||||
assert.NoError(t, err, "should succeed")
|
||||
assert.NotNil(t, m, "should not be nil")
|
||||
require.NoError(t, err, "should succeed")
|
||||
require.NotNil(t, m, "should not be nil")
|
||||
|
||||
// Find external IPv4
|
||||
extIP, err = m.findExternalIP("10.0.0.1")
|
||||
assert.NoError(t, err, "should succeed")
|
||||
assert.Equal(t, "1.2.3.4", extIP.String(), "should match")
|
||||
require.NoError(t, err, "should succeed")
|
||||
require.Equal(t, "1.2.3.4", extIP.String(), "should match")
|
||||
|
||||
extIP, err = m.findExternalIP("10.0.0.2")
|
||||
assert.NoError(t, err, "should succeed")
|
||||
assert.Equal(t, "1.2.3.5", extIP.String(), "should match")
|
||||
require.NoError(t, err, "should succeed")
|
||||
require.Equal(t, "1.2.3.5", extIP.String(), "should match")
|
||||
|
||||
_, err = m.findExternalIP("10.0.0.3")
|
||||
assert.Error(t, err, "should fail")
|
||||
require.Error(t, err, "should fail")
|
||||
|
||||
// Find external IPv6
|
||||
extIP, err = m.findExternalIP("fe80::0001") // Use '0001' instead of '1' on purpose
|
||||
assert.NoError(t, err, "should succeed")
|
||||
assert.Equal(t, "2200::1", extIP.String(), "should match")
|
||||
require.NoError(t, err, "should succeed")
|
||||
require.Equal(t, "2200::1", extIP.String(), "should match")
|
||||
|
||||
extIP, err = m.findExternalIP("fe80::0002") // Use '0002' instead of '2' on purpose
|
||||
assert.NoError(t, err, "should succeed")
|
||||
assert.Equal(t, "2200::2", extIP.String(), "should match")
|
||||
require.NoError(t, err, "should succeed")
|
||||
require.Equal(t, "2200::2", extIP.String(), "should match")
|
||||
|
||||
_, err = m.findExternalIP("fe80::3")
|
||||
assert.Error(t, err, "should fail")
|
||||
require.Error(t, err, "should fail")
|
||||
|
||||
// Bad local IP string
|
||||
_, err = m.findExternalIP("really.bad")
|
||||
assert.Error(t, err, "should fail")
|
||||
require.Error(t, err, "should fail")
|
||||
})
|
||||
|
||||
t.Run("findExternalIP with empty map", func(t *testing.T) {
|
||||
@@ -289,21 +289,21 @@ func TestExternalIPMapper(t *testing.T) {
|
||||
m, err = newExternalIPMapper(CandidateTypeUnspecified, []string{
|
||||
"1.2.3.4",
|
||||
})
|
||||
assert.NoError(t, err, "should succeed")
|
||||
require.NoError(t, err, "should succeed")
|
||||
|
||||
// Attempt to find IPv6 that does not exist in the map
|
||||
extIP, err := m.findExternalIP("fe80::1")
|
||||
assert.NoError(t, err, "should succeed")
|
||||
assert.Equal(t, "fe80::1", extIP.String(), "should match")
|
||||
require.NoError(t, err, "should succeed")
|
||||
require.Equal(t, "fe80::1", extIP.String(), "should match")
|
||||
|
||||
m, err = newExternalIPMapper(CandidateTypeUnspecified, []string{
|
||||
"2200::1",
|
||||
})
|
||||
assert.NoError(t, err, "should succeed")
|
||||
require.NoError(t, err, "should succeed")
|
||||
|
||||
// Attempt to find IPv4 that does not exist in the map
|
||||
extIP, err = m.findExternalIP("10.0.0.1")
|
||||
assert.NoError(t, err, "should succeed")
|
||||
assert.Equal(t, "10.0.0.1", extIP.String(), "should match")
|
||||
require.NoError(t, err, "should succeed")
|
||||
require.Equal(t, "10.0.0.1", extIP.String(), "should match")
|
||||
})
|
||||
}
|
||||
|
201
gather_test.go
201
gather_test.go
@@ -26,35 +26,34 @@ import (
|
||||
"github.com/pion/stun/v2"
|
||||
"github.com/pion/transport/v3/test"
|
||||
"github.com/pion/turn/v3"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
"golang.org/x/net/proxy"
|
||||
)
|
||||
|
||||
func TestListenUDP(t *testing.T) {
|
||||
a, err := NewAgent(&AgentConfig{})
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
localIPs, err := localInterfaces(a.net, a.interfaceFilter, a.ipFilter, []NetworkType{NetworkTypeUDP4}, false)
|
||||
assert.NotEqual(t, len(localIPs), 0, "localInterfaces found no interfaces, unable to test")
|
||||
assert.NoError(t, err)
|
||||
require.NotEqual(t, len(localIPs), 0, "localInterfaces found no interfaces, unable to test")
|
||||
require.NoError(t, err)
|
||||
|
||||
ip := localIPs[0]
|
||||
|
||||
conn, err := listenUDPInPortRange(a.net, a.log, 0, 0, udp, &net.UDPAddr{IP: ip, Port: 0})
|
||||
assert.NoError(t, err, "listenUDP error with no port restriction")
|
||||
assert.NotNil(t, conn, "listenUDP error with no port restriction return a nil conn")
|
||||
require.NoError(t, err, "listenUDP error with no port restriction")
|
||||
require.NotNil(t, conn, "listenUDP error with no port restriction return a nil conn")
|
||||
|
||||
_, err = listenUDPInPortRange(a.net, a.log, 4999, 5000, udp, &net.UDPAddr{IP: ip, Port: 0})
|
||||
assert.Equal(t, err, ErrPort, "listenUDP with invalid port range did not return ErrPort")
|
||||
require.Equal(t, err, ErrPort, "listenUDP with invalid port range did not return ErrPort")
|
||||
|
||||
conn, err = listenUDPInPortRange(a.net, a.log, 5000, 5000, udp, &net.UDPAddr{IP: ip, Port: 0})
|
||||
assert.NoError(t, err, "listenUDP error with no port restriction")
|
||||
assert.NotNil(t, conn, "listenUDP error with no port restriction return a nil conn")
|
||||
require.NoError(t, err, "listenUDP error with no port restriction")
|
||||
require.NotNil(t, conn, "listenUDP error with no port restriction return a nil conn")
|
||||
|
||||
_, port, err := net.SplitHostPort(conn.LocalAddr().String())
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, port, "5000", "listenUDP with port restriction of 5000 listened on incorrect port")
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, port, "5000", "listenUDP with port restriction of 5000 listened on incorrect port")
|
||||
|
||||
portMin := 5100
|
||||
portMax := 5109
|
||||
@@ -63,8 +62,8 @@ func TestListenUDP(t *testing.T) {
|
||||
portRange := make([]int, 0, total)
|
||||
for i := 0; i < total; i++ {
|
||||
conn, err = listenUDPInPortRange(a.net, a.log, portMax, portMin, udp, &net.UDPAddr{IP: ip, Port: 0})
|
||||
assert.NoError(t, err, "listenUDP error with no port restriction")
|
||||
assert.NotNil(t, conn, "listenUDP error with no port restriction return a nil conn")
|
||||
require.NoError(t, err, "listenUDP error with no port restriction")
|
||||
require.NotNil(t, conn, "listenUDP error with no port restriction return a nil conn")
|
||||
|
||||
_, port, err = net.SplitHostPort(conn.LocalAddr().String())
|
||||
if err != nil {
|
||||
@@ -85,9 +84,9 @@ func TestListenUDP(t *testing.T) {
|
||||
t.Fatalf("listenUDP with port restriction [%d, %d], got:%v, want:%v", portMin, portMax, result, portRange)
|
||||
}
|
||||
_, err = listenUDPInPortRange(a.net, a.log, portMax, portMin, udp, &net.UDPAddr{IP: ip, Port: 0})
|
||||
assert.Equal(t, err, ErrPort, "listenUDP with port restriction [%d, %d], did not return ErrPort", portMin, portMax)
|
||||
require.Equal(t, err, ErrPort, "listenUDP with port restriction [%d, %d], did not return ErrPort", portMin, portMax)
|
||||
|
||||
assert.NoError(t, a.Close())
|
||||
require.NoError(t, a.Close())
|
||||
}
|
||||
|
||||
func TestGatherConcurrency(t *testing.T) {
|
||||
@@ -101,10 +100,10 @@ func TestGatherConcurrency(t *testing.T) {
|
||||
NetworkTypes: []NetworkType{NetworkTypeUDP4, NetworkTypeUDP6},
|
||||
IncludeLoopback: true,
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
candidateGathered, candidateGatheredFunc := context.WithCancel(context.Background())
|
||||
assert.NoError(t, a.OnCandidate(func(Candidate) {
|
||||
require.NoError(t, a.OnCandidate(func(Candidate) {
|
||||
candidateGatheredFunc()
|
||||
}))
|
||||
|
||||
@@ -115,7 +114,7 @@ func TestGatherConcurrency(t *testing.T) {
|
||||
|
||||
<-candidateGathered.Done()
|
||||
|
||||
assert.NoError(t, a.Close())
|
||||
require.NoError(t, a.Close())
|
||||
}
|
||||
|
||||
func TestLoopbackCandidate(t *testing.T) {
|
||||
@@ -130,12 +129,12 @@ func TestLoopbackCandidate(t *testing.T) {
|
||||
loExpected bool
|
||||
}
|
||||
mux, err := NewMultiUDPMuxFromPort(12500)
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
muxWithLo, errlo := NewMultiUDPMuxFromPort(12501, UDPMuxFromPortWithLoopback())
|
||||
assert.NoError(t, errlo)
|
||||
require.NoError(t, errlo)
|
||||
|
||||
unspecConn, errconn := net.ListenPacket("udp", ":0")
|
||||
assert.NoError(t, errconn)
|
||||
require.NoError(t, errconn)
|
||||
defer func() {
|
||||
_ = unspecConn.Close()
|
||||
}()
|
||||
@@ -199,11 +198,11 @@ func TestLoopbackCandidate(t *testing.T) {
|
||||
tcase := tc
|
||||
t.Run(tcase.name, func(t *testing.T) {
|
||||
a, err := NewAgent(tc.agentConfig)
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
candidateGathered, candidateGatheredFunc := context.WithCancel(context.Background())
|
||||
var loopback int32
|
||||
assert.NoError(t, a.OnCandidate(func(c Candidate) {
|
||||
require.NoError(t, a.OnCandidate(func(c Candidate) {
|
||||
if c != nil {
|
||||
if net.ParseIP(c.Address()).IsLoopback() {
|
||||
atomic.StoreInt32(&loopback, 1)
|
||||
@@ -214,18 +213,18 @@ func TestLoopbackCandidate(t *testing.T) {
|
||||
}
|
||||
t.Log(c.NetworkType(), c.Priority(), c)
|
||||
}))
|
||||
assert.NoError(t, a.GatherCandidates())
|
||||
require.NoError(t, a.GatherCandidates())
|
||||
|
||||
<-candidateGathered.Done()
|
||||
|
||||
assert.NoError(t, a.Close())
|
||||
assert.Equal(t, tcase.loExpected, atomic.LoadInt32(&loopback) == 1)
|
||||
require.NoError(t, a.Close())
|
||||
require.Equal(t, tcase.loExpected, atomic.LoadInt32(&loopback) == 1)
|
||||
})
|
||||
}
|
||||
|
||||
assert.NoError(t, mux.Close())
|
||||
assert.NoError(t, muxWithLo.Close())
|
||||
assert.NoError(t, muxUnspecDefault.Close())
|
||||
require.NoError(t, mux.Close())
|
||||
require.NoError(t, muxWithLo.Close())
|
||||
require.NoError(t, muxUnspecDefault.Close())
|
||||
}
|
||||
|
||||
// Assert that STUN gathering is done concurrently
|
||||
@@ -238,7 +237,7 @@ func TestSTUNConcurrency(t *testing.T) {
|
||||
|
||||
serverPort := randomPort(t)
|
||||
serverListener, err := net.ListenPacket("udp4", localhostIPStr+":"+strconv.Itoa(serverPort))
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
server, err := turn.NewServer(turn.ServerConfig{
|
||||
Realm: "pion.ly",
|
||||
@@ -250,7 +249,7 @@ func TestSTUNConcurrency(t *testing.T) {
|
||||
},
|
||||
},
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
urls := []*stun.URI{}
|
||||
for i := 0; i <= 10; i++ {
|
||||
@@ -286,22 +285,22 @@ func TestSTUNConcurrency(t *testing.T) {
|
||||
},
|
||||
),
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
candidateGathered, candidateGatheredFunc := context.WithCancel(context.Background())
|
||||
assert.NoError(t, a.OnCandidate(func(c Candidate) {
|
||||
require.NoError(t, a.OnCandidate(func(c Candidate) {
|
||||
if c == nil {
|
||||
candidateGatheredFunc()
|
||||
return
|
||||
}
|
||||
t.Log(c.NetworkType(), c.Priority(), c)
|
||||
}))
|
||||
assert.NoError(t, a.GatherCandidates())
|
||||
require.NoError(t, a.GatherCandidates())
|
||||
|
||||
<-candidateGathered.Done()
|
||||
|
||||
assert.NoError(t, a.Close())
|
||||
assert.NoError(t, server.Close())
|
||||
require.NoError(t, a.Close())
|
||||
require.NoError(t, server.Close())
|
||||
}
|
||||
|
||||
// Assert that TURN gathering is done concurrently
|
||||
@@ -335,7 +334,7 @@ func TestTURNConcurrency(t *testing.T) {
|
||||
PacketConnConfigs: packetConnConfigs,
|
||||
ListenerConfigs: listenerConfigs,
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
urls := []*stun.URI{}
|
||||
for i := 0; i <= 10; i++ {
|
||||
@@ -363,26 +362,26 @@ func TestTURNConcurrency(t *testing.T) {
|
||||
NetworkTypes: supportedNetworkTypes(),
|
||||
Urls: urls,
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
candidateGathered, candidateGatheredFunc := context.WithCancel(context.Background())
|
||||
assert.NoError(t, a.OnCandidate(func(c Candidate) {
|
||||
require.NoError(t, a.OnCandidate(func(c Candidate) {
|
||||
if c != nil {
|
||||
candidateGatheredFunc()
|
||||
}
|
||||
}))
|
||||
assert.NoError(t, a.GatherCandidates())
|
||||
require.NoError(t, a.GatherCandidates())
|
||||
|
||||
<-candidateGathered.Done()
|
||||
|
||||
assert.NoError(t, a.Close())
|
||||
assert.NoError(t, server.Close())
|
||||
require.NoError(t, a.Close())
|
||||
require.NoError(t, server.Close())
|
||||
}
|
||||
|
||||
t.Run("UDP Relay", func(t *testing.T) {
|
||||
serverPort := randomPort(t)
|
||||
serverListener, err := net.ListenPacket("udp", localhostIPStr+":"+strconv.Itoa(serverPort))
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
runTest(stun.ProtoTypeUDP, stun.SchemeTypeTURN, serverListener, nil, serverPort)
|
||||
})
|
||||
@@ -390,33 +389,33 @@ func TestTURNConcurrency(t *testing.T) {
|
||||
t.Run("TCP Relay", func(t *testing.T) {
|
||||
serverPort := randomPort(t)
|
||||
serverListener, err := net.Listen("tcp", localhostIPStr+":"+strconv.Itoa(serverPort))
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
runTest(stun.ProtoTypeTCP, stun.SchemeTypeTURN, nil, serverListener, serverPort)
|
||||
})
|
||||
|
||||
t.Run("TLS Relay", func(t *testing.T) {
|
||||
certificate, genErr := selfsign.GenerateSelfSigned()
|
||||
assert.NoError(t, genErr)
|
||||
require.NoError(t, genErr)
|
||||
|
||||
serverPort := randomPort(t)
|
||||
serverListener, err := tls.Listen("tcp", localhostIPStr+":"+strconv.Itoa(serverPort), &tls.Config{ //nolint:gosec
|
||||
Certificates: []tls.Certificate{certificate},
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
runTest(stun.ProtoTypeTCP, stun.SchemeTypeTURNS, nil, serverListener, serverPort)
|
||||
})
|
||||
|
||||
t.Run("DTLS Relay", func(t *testing.T) {
|
||||
certificate, genErr := selfsign.GenerateSelfSigned()
|
||||
assert.NoError(t, genErr)
|
||||
require.NoError(t, genErr)
|
||||
|
||||
serverPort := randomPort(t)
|
||||
serverListener, err := dtls.Listen("udp", &net.UDPAddr{IP: net.ParseIP(localhostIPStr), Port: serverPort}, &dtls.Config{
|
||||
Certificates: []tls.Certificate{certificate},
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
runTest(stun.ProtoTypeUDP, stun.SchemeTypeTURNS, nil, serverListener, serverPort)
|
||||
})
|
||||
@@ -432,7 +431,7 @@ func TestSTUNTURNConcurrency(t *testing.T) {
|
||||
|
||||
serverPort := randomPort(t)
|
||||
serverListener, err := net.ListenPacket("udp4", localhostIPStr+":"+strconv.Itoa(serverPort))
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
server, err := turn.NewServer(turn.ServerConfig{
|
||||
Realm: "pion.ly",
|
||||
@@ -444,7 +443,7 @@ func TestSTUNTURNConcurrency(t *testing.T) {
|
||||
},
|
||||
},
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
urls := []*stun.URI{}
|
||||
for i := 0; i <= 10; i++ {
|
||||
@@ -468,25 +467,25 @@ func TestSTUNTURNConcurrency(t *testing.T) {
|
||||
Urls: urls,
|
||||
CandidateTypes: []CandidateType{CandidateTypeServerReflexive, CandidateTypeRelay},
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
{
|
||||
gatherLim := test.TimeOut(time.Second * 3) // As TURN and STUN should be checked in parallel, this should complete before the default STUN timeout (5s)
|
||||
candidateGathered, candidateGatheredFunc := context.WithCancel(context.Background())
|
||||
assert.NoError(t, a.OnCandidate(func(c Candidate) {
|
||||
require.NoError(t, a.OnCandidate(func(c Candidate) {
|
||||
if c != nil {
|
||||
candidateGatheredFunc()
|
||||
}
|
||||
}))
|
||||
assert.NoError(t, a.GatherCandidates())
|
||||
require.NoError(t, a.GatherCandidates())
|
||||
|
||||
<-candidateGathered.Done()
|
||||
|
||||
gatherLim.Stop()
|
||||
}
|
||||
|
||||
assert.NoError(t, a.Close())
|
||||
assert.NoError(t, server.Close())
|
||||
require.NoError(t, a.Close())
|
||||
require.NoError(t, server.Close())
|
||||
}
|
||||
|
||||
// Assert that srflx candidates can be gathered from TURN servers
|
||||
@@ -504,7 +503,7 @@ func TestTURNSrflx(t *testing.T) {
|
||||
|
||||
serverPort := randomPort(t)
|
||||
serverListener, err := net.ListenPacket("udp4", localhostIPStr+":"+strconv.Itoa(serverPort))
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
server, err := turn.NewServer(turn.ServerConfig{
|
||||
Realm: "pion.ly",
|
||||
@@ -516,7 +515,7 @@ func TestTURNSrflx(t *testing.T) {
|
||||
},
|
||||
},
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
urls := []*stun.URI{{
|
||||
Scheme: stun.SchemeTypeTURN,
|
||||
@@ -532,33 +531,33 @@ func TestTURNSrflx(t *testing.T) {
|
||||
Urls: urls,
|
||||
CandidateTypes: []CandidateType{CandidateTypeServerReflexive, CandidateTypeRelay},
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
candidateGathered, candidateGatheredFunc := context.WithCancel(context.Background())
|
||||
assert.NoError(t, a.OnCandidate(func(c Candidate) {
|
||||
require.NoError(t, a.OnCandidate(func(c Candidate) {
|
||||
if c != nil && c.Type() == CandidateTypeServerReflexive {
|
||||
candidateGatheredFunc()
|
||||
}
|
||||
}))
|
||||
|
||||
assert.NoError(t, a.GatherCandidates())
|
||||
require.NoError(t, a.GatherCandidates())
|
||||
|
||||
<-candidateGathered.Done()
|
||||
|
||||
assert.NoError(t, a.Close())
|
||||
assert.NoError(t, server.Close())
|
||||
require.NoError(t, a.Close())
|
||||
require.NoError(t, server.Close())
|
||||
}
|
||||
|
||||
func TestCloseConnLog(t *testing.T) {
|
||||
a, err := NewAgent(&AgentConfig{})
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
closeConnAndLog(nil, a.log, "normal nil")
|
||||
|
||||
var nc *net.UDPConn
|
||||
closeConnAndLog(nc, a.log, "nil ptr")
|
||||
|
||||
assert.NoError(t, a.Close())
|
||||
require.NoError(t, a.Close())
|
||||
}
|
||||
|
||||
type mockProxy struct {
|
||||
@@ -594,10 +593,10 @@ func TestTURNProxyDialer(t *testing.T) {
|
||||
})
|
||||
|
||||
tcpProxyURI, err := url.Parse("tcp://fakeproxy:3128")
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
proxyDialer, err := proxy.FromURL(tcpProxyURI, proxy.Direct)
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
a, err := NewAgent(&AgentConfig{
|
||||
CandidateTypes: []CandidateType{CandidateTypeRelay},
|
||||
@@ -614,23 +613,23 @@ func TestTURNProxyDialer(t *testing.T) {
|
||||
},
|
||||
ProxyDialer: proxyDialer,
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
candidateGatherFinish, candidateGatherFinishFunc := context.WithCancel(context.Background())
|
||||
assert.NoError(t, a.OnCandidate(func(c Candidate) {
|
||||
require.NoError(t, a.OnCandidate(func(c Candidate) {
|
||||
if c == nil {
|
||||
candidateGatherFinishFunc()
|
||||
}
|
||||
}))
|
||||
|
||||
assert.NoError(t, a.GatherCandidates())
|
||||
require.NoError(t, a.GatherCandidates())
|
||||
<-candidateGatherFinish.Done()
|
||||
<-proxyWasDialed.Done()
|
||||
|
||||
assert.NoError(t, a.Close())
|
||||
require.NoError(t, a.Close())
|
||||
}
|
||||
|
||||
// TestUDPMuxDefaultWithNAT1To1IPsUsage asserts that candidates
|
||||
// TestUDPMuxDefaultWithNAT1To1IPsUsage requires that candidates
|
||||
// are given and connections are valid when using UDPMuxDefault and NAT1To1IPs.
|
||||
func TestUDPMuxDefaultWithNAT1To1IPsUsage(t *testing.T) {
|
||||
report := test.CheckRoutines(t)
|
||||
@@ -640,7 +639,7 @@ func TestUDPMuxDefaultWithNAT1To1IPsUsage(t *testing.T) {
|
||||
defer lim.Stop()
|
||||
|
||||
conn, err := net.ListenPacket("udp4", ":0")
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
defer func() {
|
||||
_ = conn.Close()
|
||||
}()
|
||||
@@ -657,22 +656,22 @@ func TestUDPMuxDefaultWithNAT1To1IPsUsage(t *testing.T) {
|
||||
NAT1To1IPCandidateType: CandidateTypeHost,
|
||||
UDPMux: mux,
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
gatherCandidateDone := make(chan struct{})
|
||||
assert.NoError(t, a.OnCandidate(func(c Candidate) {
|
||||
require.NoError(t, a.OnCandidate(func(c Candidate) {
|
||||
if c == nil {
|
||||
close(gatherCandidateDone)
|
||||
} else {
|
||||
assert.Equal(t, "1.2.3.4", c.Address())
|
||||
require.Equal(t, "1.2.3.4", c.Address())
|
||||
}
|
||||
}))
|
||||
assert.NoError(t, a.GatherCandidates())
|
||||
require.NoError(t, a.GatherCandidates())
|
||||
<-gatherCandidateDone
|
||||
|
||||
assert.NotEqual(t, 0, len(mux.connsIPv4))
|
||||
require.NotEqual(t, 0, len(mux.connsIPv4))
|
||||
|
||||
assert.NoError(t, a.Close())
|
||||
require.NoError(t, a.Close())
|
||||
}
|
||||
|
||||
// Assert that candidates are given for each mux in a MultiUDPMux
|
||||
@@ -688,7 +687,7 @@ func TestMultiUDPMuxUsage(t *testing.T) {
|
||||
for i := 0; i < 3; i++ {
|
||||
port := randomPort(t)
|
||||
conn, err := net.ListenUDP("udp4", &net.UDPAddr{IP: net.IP{127, 0, 0, 1}, Port: port})
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
defer func() {
|
||||
_ = conn.Close()
|
||||
}()
|
||||
@@ -707,29 +706,29 @@ func TestMultiUDPMuxUsage(t *testing.T) {
|
||||
CandidateTypes: []CandidateType{CandidateTypeHost},
|
||||
UDPMux: NewMultiUDPMuxDefault(udpMuxInstances...),
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
candidateCh := make(chan Candidate)
|
||||
assert.NoError(t, a.OnCandidate(func(c Candidate) {
|
||||
require.NoError(t, a.OnCandidate(func(c Candidate) {
|
||||
if c == nil {
|
||||
close(candidateCh)
|
||||
return
|
||||
}
|
||||
candidateCh <- c
|
||||
}))
|
||||
assert.NoError(t, a.GatherCandidates())
|
||||
require.NoError(t, a.GatherCandidates())
|
||||
|
||||
portFound := make(map[int]bool)
|
||||
for c := range candidateCh {
|
||||
portFound[c.Port()] = true
|
||||
assert.True(t, c.NetworkType().IsUDP(), "All candidates should be UDP")
|
||||
require.True(t, c.NetworkType().IsUDP(), "All candidates should be UDP")
|
||||
}
|
||||
assert.Len(t, portFound, len(expectedPorts))
|
||||
require.Len(t, portFound, len(expectedPorts))
|
||||
for _, port := range expectedPorts {
|
||||
assert.True(t, portFound[port], "There should be a candidate for each UDP mux port")
|
||||
require.True(t, portFound[port], "There should be a candidate for each UDP mux port")
|
||||
}
|
||||
|
||||
assert.NoError(t, a.Close())
|
||||
require.NoError(t, a.Close())
|
||||
}
|
||||
|
||||
// Assert that candidates are given for each mux in a MultiTCPMux
|
||||
@@ -748,7 +747,7 @@ func TestMultiTCPMuxUsage(t *testing.T) {
|
||||
IP: net.IP{127, 0, 0, 1},
|
||||
Port: port,
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
defer func() {
|
||||
_ = listener.Close()
|
||||
}()
|
||||
@@ -765,17 +764,17 @@ func TestMultiTCPMuxUsage(t *testing.T) {
|
||||
CandidateTypes: []CandidateType{CandidateTypeHost},
|
||||
TCPMux: NewMultiTCPMuxDefault(tcpMuxInstances...),
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
candidateCh := make(chan Candidate)
|
||||
assert.NoError(t, a.OnCandidate(func(c Candidate) {
|
||||
require.NoError(t, a.OnCandidate(func(c Candidate) {
|
||||
if c == nil {
|
||||
close(candidateCh)
|
||||
return
|
||||
}
|
||||
candidateCh <- c
|
||||
}))
|
||||
assert.NoError(t, a.GatherCandidates())
|
||||
require.NoError(t, a.GatherCandidates())
|
||||
|
||||
portFound := make(map[int]bool)
|
||||
for c := range candidateCh {
|
||||
@@ -784,12 +783,12 @@ func TestMultiTCPMuxUsage(t *testing.T) {
|
||||
portFound[c.Port()] = true
|
||||
}
|
||||
}
|
||||
assert.Len(t, portFound, len(expectedPorts))
|
||||
require.Len(t, portFound, len(expectedPorts))
|
||||
for _, port := range expectedPorts {
|
||||
assert.True(t, portFound[port], "There should be a candidate for each TCP mux port")
|
||||
require.True(t, portFound[port], "There should be a candidate for each TCP mux port")
|
||||
}
|
||||
|
||||
assert.NoError(t, a.Close())
|
||||
require.NoError(t, a.Close())
|
||||
}
|
||||
|
||||
// Assert that UniversalUDPMux is used while gathering when configured in the Agent
|
||||
@@ -801,7 +800,7 @@ func TestUniversalUDPMuxUsage(t *testing.T) {
|
||||
defer lim.Stop()
|
||||
|
||||
conn, err := net.ListenUDP("udp4", &net.UDPAddr{IP: net.IP{127, 0, 0, 1}, Port: randomPort(t)})
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
defer func() {
|
||||
_ = conn.Close()
|
||||
}()
|
||||
@@ -826,27 +825,27 @@ func TestUniversalUDPMuxUsage(t *testing.T) {
|
||||
CandidateTypes: []CandidateType{CandidateTypeServerReflexive},
|
||||
UDPMuxSrflx: udpMuxSrflx,
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
candidateGathered, candidateGatheredFunc := context.WithCancel(context.Background())
|
||||
assert.NoError(t, a.OnCandidate(func(c Candidate) {
|
||||
require.NoError(t, a.OnCandidate(func(c Candidate) {
|
||||
if c == nil {
|
||||
candidateGatheredFunc()
|
||||
return
|
||||
}
|
||||
t.Log(c.NetworkType(), c.Priority(), c)
|
||||
}))
|
||||
assert.NoError(t, a.GatherCandidates())
|
||||
require.NoError(t, a.GatherCandidates())
|
||||
|
||||
<-candidateGathered.Done()
|
||||
|
||||
assert.NoError(t, a.Close())
|
||||
require.NoError(t, a.Close())
|
||||
// Twice because of 2 STUN servers configured
|
||||
assert.Equal(t, numSTUNS, udpMuxSrflx.getXORMappedAddrUsedTimes, "expected times that GetXORMappedAddr should be called")
|
||||
require.Equal(t, numSTUNS, udpMuxSrflx.getXORMappedAddrUsedTimes, "expected times that GetXORMappedAddr should be called")
|
||||
// One for Restart() when agent has been initialized and one time when Close() the agent
|
||||
assert.Equal(t, 2, udpMuxSrflx.removeConnByUfragTimes, "expected times that RemoveConnByUfrag should be called")
|
||||
require.Equal(t, 2, udpMuxSrflx.removeConnByUfragTimes, "expected times that RemoveConnByUfrag should be called")
|
||||
// Twice because of 2 STUN servers configured
|
||||
assert.Equal(t, numSTUNS, udpMuxSrflx.getConnForURLTimes, "expected times that GetConnForURL should be called")
|
||||
require.Equal(t, numSTUNS, udpMuxSrflx.getConnForURLTimes, "expected times that GetConnForURL should be called")
|
||||
}
|
||||
|
||||
type universalUDPMuxMock struct {
|
||||
|
@@ -17,7 +17,7 @@ import (
|
||||
"github.com/pion/stun/v2"
|
||||
"github.com/pion/transport/v3/test"
|
||||
"github.com/pion/transport/v3/vnet"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestVNetGather(t *testing.T) {
|
||||
@@ -28,12 +28,12 @@ func TestVNetGather(t *testing.T) {
|
||||
|
||||
t.Run("No local IP address", func(t *testing.T) {
|
||||
n, err := vnet.NewNet(&vnet.NetConfig{})
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
a, err := NewAgent(&AgentConfig{
|
||||
Net: n,
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
localIPs, err := localInterfaces(a.net, a.interfaceFilter, a.ipFilter, []NetworkType{NetworkTypeUDP4}, false)
|
||||
if len(localIPs) > 0 {
|
||||
@@ -42,7 +42,7 @@ func TestVNetGather(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
assert.NoError(t, a.Close())
|
||||
require.NoError(t, a.Close())
|
||||
})
|
||||
|
||||
t.Run("Gather a dynamic IP address", func(t *testing.T) {
|
||||
@@ -73,7 +73,7 @@ func TestVNetGather(t *testing.T) {
|
||||
a, err := NewAgent(&AgentConfig{
|
||||
Net: nw,
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
localIPs, err := localInterfaces(a.net, a.interfaceFilter, a.ipFilter, []NetworkType{NetworkTypeUDP4}, false)
|
||||
if len(localIPs) == 0 {
|
||||
@@ -91,7 +91,7 @@ func TestVNetGather(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
assert.NoError(t, a.Close())
|
||||
require.NoError(t, a.Close())
|
||||
})
|
||||
|
||||
t.Run("listenUDP", func(t *testing.T) {
|
||||
@@ -157,8 +157,8 @@ func TestVNetGather(t *testing.T) {
|
||||
t.Fatalf("listenUDP with port restriction of 5000 listened on incorrect port (%s)", port)
|
||||
}
|
||||
|
||||
assert.NoError(t, conn.Close())
|
||||
assert.NoError(t, a.Close())
|
||||
require.NoError(t, conn.Close())
|
||||
require.NoError(t, a.Close())
|
||||
})
|
||||
}
|
||||
|
||||
@@ -181,7 +181,7 @@ func TestVNetGatherWithNAT1To1(t *testing.T) {
|
||||
CIDR: "1.2.3.0/24",
|
||||
LoggerFactory: loggerFactory,
|
||||
})
|
||||
assert.NoError(t, err, "should succeed")
|
||||
require.NoError(t, err, "should succeed")
|
||||
|
||||
lan, err := vnet.NewRouter(&vnet.RouterConfig{
|
||||
CIDR: "10.0.0.0/24",
|
||||
@@ -191,10 +191,10 @@ func TestVNetGatherWithNAT1To1(t *testing.T) {
|
||||
},
|
||||
LoggerFactory: loggerFactory,
|
||||
})
|
||||
assert.NoError(t, err, "should succeed")
|
||||
require.NoError(t, err, "should succeed")
|
||||
|
||||
err = wan.AddRouter(lan)
|
||||
assert.NoError(t, err, "should succeed")
|
||||
require.NoError(t, err, "should succeed")
|
||||
|
||||
nw, err := vnet.NewNet(&vnet.NetConfig{
|
||||
StaticIPs: []string{localIP0, localIP1},
|
||||
@@ -204,7 +204,7 @@ func TestVNetGatherWithNAT1To1(t *testing.T) {
|
||||
}
|
||||
|
||||
err = lan.AddNet(nw)
|
||||
assert.NoError(t, err, "should succeed")
|
||||
require.NoError(t, err, "should succeed")
|
||||
|
||||
a, err := NewAgent(&AgentConfig{
|
||||
NetworkTypes: []NetworkType{
|
||||
@@ -213,7 +213,7 @@ func TestVNetGatherWithNAT1To1(t *testing.T) {
|
||||
NAT1To1IPs: []string{map0, map1},
|
||||
Net: nw,
|
||||
})
|
||||
assert.NoError(t, err, "should succeed")
|
||||
require.NoError(t, err, "should succeed")
|
||||
defer a.Close() //nolint:errcheck
|
||||
|
||||
done := make(chan struct{})
|
||||
@@ -222,17 +222,17 @@ func TestVNetGatherWithNAT1To1(t *testing.T) {
|
||||
close(done)
|
||||
}
|
||||
})
|
||||
assert.NoError(t, err, "should succeed")
|
||||
require.NoError(t, err, "should succeed")
|
||||
|
||||
err = a.GatherCandidates()
|
||||
assert.NoError(t, err, "should succeed")
|
||||
require.NoError(t, err, "should succeed")
|
||||
|
||||
log.Debug("Wait until gathering is complete...")
|
||||
<-done
|
||||
log.Debug("Gathering is done")
|
||||
|
||||
candidates, err := a.GetLocalCandidates()
|
||||
assert.NoError(t, err, "should succeed")
|
||||
require.NoError(t, err, "should succeed")
|
||||
|
||||
if len(candidates) != 2 {
|
||||
t.Fatal("There must be two candidates")
|
||||
@@ -274,7 +274,7 @@ func TestVNetGatherWithNAT1To1(t *testing.T) {
|
||||
CIDR: "1.2.3.0/24",
|
||||
LoggerFactory: loggerFactory,
|
||||
})
|
||||
assert.NoError(t, err, "should succeed")
|
||||
require.NoError(t, err, "should succeed")
|
||||
|
||||
lan, err := vnet.NewRouter(&vnet.RouterConfig{
|
||||
CIDR: "10.0.0.0/24",
|
||||
@@ -286,10 +286,10 @@ func TestVNetGatherWithNAT1To1(t *testing.T) {
|
||||
},
|
||||
LoggerFactory: loggerFactory,
|
||||
})
|
||||
assert.NoError(t, err, "should succeed")
|
||||
require.NoError(t, err, "should succeed")
|
||||
|
||||
err = wan.AddRouter(lan)
|
||||
assert.NoError(t, err, "should succeed")
|
||||
require.NoError(t, err, "should succeed")
|
||||
|
||||
nw, err := vnet.NewNet(&vnet.NetConfig{
|
||||
StaticIPs: []string{
|
||||
@@ -301,7 +301,7 @@ func TestVNetGatherWithNAT1To1(t *testing.T) {
|
||||
}
|
||||
|
||||
err = lan.AddNet(nw)
|
||||
assert.NoError(t, err, "should succeed")
|
||||
require.NoError(t, err, "should succeed")
|
||||
|
||||
a, err := NewAgent(&AgentConfig{
|
||||
NetworkTypes: []NetworkType{
|
||||
@@ -313,7 +313,7 @@ func TestVNetGatherWithNAT1To1(t *testing.T) {
|
||||
NAT1To1IPCandidateType: CandidateTypeServerReflexive,
|
||||
Net: nw,
|
||||
})
|
||||
assert.NoError(t, err, "should succeed")
|
||||
require.NoError(t, err, "should succeed")
|
||||
defer a.Close() //nolint:errcheck
|
||||
|
||||
done := make(chan struct{})
|
||||
@@ -322,17 +322,17 @@ func TestVNetGatherWithNAT1To1(t *testing.T) {
|
||||
close(done)
|
||||
}
|
||||
})
|
||||
assert.NoError(t, err, "should succeed")
|
||||
require.NoError(t, err, "should succeed")
|
||||
|
||||
err = a.GatherCandidates()
|
||||
assert.NoError(t, err, "should succeed")
|
||||
require.NoError(t, err, "should succeed")
|
||||
|
||||
log.Debug("Wait until gathering is complete...")
|
||||
<-done
|
||||
log.Debug("Gathering is done")
|
||||
|
||||
candidates, err := a.GetLocalCandidates()
|
||||
assert.NoError(t, err, "should succeed")
|
||||
require.NoError(t, err, "should succeed")
|
||||
|
||||
if len(candidates) != 2 {
|
||||
t.Fatalf("Expected two candidates. actually %d", len(candidates))
|
||||
@@ -352,10 +352,10 @@ func TestVNetGatherWithNAT1To1(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
assert.NotNil(t, candiHost, "should not be nil")
|
||||
assert.Equal(t, "10.0.0.1", candiHost.Address(), "should match")
|
||||
assert.NotNil(t, candiSrflx, "should not be nil")
|
||||
assert.Equal(t, "1.2.3.4", candiSrflx.Address(), "should match")
|
||||
require.NotNil(t, candiHost, "should not be nil")
|
||||
require.Equal(t, "10.0.0.1", candiHost.Address(), "should match")
|
||||
require.NotNil(t, candiSrflx, "should not be nil")
|
||||
require.Equal(t, "1.2.3.4", candiSrflx.Address(), "should match")
|
||||
})
|
||||
}
|
||||
|
||||
@@ -385,11 +385,11 @@ func TestVNetGatherWithInterfaceFilter(t *testing.T) {
|
||||
a, err := NewAgent(&AgentConfig{
|
||||
Net: nw,
|
||||
InterfaceFilter: func(interfaceName string) bool {
|
||||
assert.Equal(t, "eth0", interfaceName)
|
||||
require.Equal(t, "eth0", interfaceName)
|
||||
return false
|
||||
},
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
localIPs, err := localInterfaces(a.net, a.interfaceFilter, a.ipFilter, []NetworkType{NetworkTypeUDP4}, false)
|
||||
if err != nil {
|
||||
@@ -398,18 +398,18 @@ func TestVNetGatherWithInterfaceFilter(t *testing.T) {
|
||||
t.Fatal("InterfaceFilter should have excluded everything")
|
||||
}
|
||||
|
||||
assert.NoError(t, a.Close())
|
||||
require.NoError(t, a.Close())
|
||||
})
|
||||
|
||||
t.Run("IPFilter should exclude the IP", func(t *testing.T) {
|
||||
a, err := NewAgent(&AgentConfig{
|
||||
Net: nw,
|
||||
IPFilter: func(ip net.IP) bool {
|
||||
assert.Equal(t, net.IP{1, 2, 3, 1}, ip)
|
||||
require.Equal(t, net.IP{1, 2, 3, 1}, ip)
|
||||
return false
|
||||
},
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
localIPs, err := localInterfaces(a.net, a.interfaceFilter, a.ipFilter, []NetworkType{NetworkTypeUDP4}, false)
|
||||
if err != nil {
|
||||
@@ -418,18 +418,18 @@ func TestVNetGatherWithInterfaceFilter(t *testing.T) {
|
||||
t.Fatal("IPFilter should have excluded everything")
|
||||
}
|
||||
|
||||
assert.NoError(t, a.Close())
|
||||
require.NoError(t, a.Close())
|
||||
})
|
||||
|
||||
t.Run("InterfaceFilter should not exclude the interface", func(t *testing.T) {
|
||||
a, err := NewAgent(&AgentConfig{
|
||||
Net: nw,
|
||||
InterfaceFilter: func(interfaceName string) bool {
|
||||
assert.Equal(t, "eth0", interfaceName)
|
||||
require.Equal(t, "eth0", interfaceName)
|
||||
return true
|
||||
},
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
localIPs, err := localInterfaces(a.net, a.interfaceFilter, a.ipFilter, []NetworkType{NetworkTypeUDP4}, false)
|
||||
if err != nil {
|
||||
@@ -438,7 +438,7 @@ func TestVNetGatherWithInterfaceFilter(t *testing.T) {
|
||||
t.Fatal("InterfaceFilter should not have excluded anything")
|
||||
}
|
||||
|
||||
assert.NoError(t, a.Close())
|
||||
require.NoError(t, a.Close())
|
||||
})
|
||||
}
|
||||
|
||||
@@ -462,9 +462,7 @@ func TestVNetGather_TURNConnectionLeak(t *testing.T) {
|
||||
}
|
||||
v, err := buildVNet(natType, natType)
|
||||
|
||||
if !assert.NoError(t, err, "should succeed") {
|
||||
return
|
||||
}
|
||||
require.NoError(t, err, "should succeed")
|
||||
defer v.close()
|
||||
|
||||
cfg0 := &AgentConfig{
|
||||
@@ -477,11 +475,9 @@ func TestVNetGather_TURNConnectionLeak(t *testing.T) {
|
||||
Net: v.net0,
|
||||
}
|
||||
aAgent, err := NewAgent(cfg0)
|
||||
if !assert.NoError(t, err, "should succeed") {
|
||||
return
|
||||
}
|
||||
require.NoError(t, err, "should succeed")
|
||||
|
||||
aAgent.gatherCandidatesRelay(context.Background(), []*stun.URI{turnServerURL})
|
||||
// Assert relay conn leak on close.
|
||||
assert.NoError(t, aAgent.Close())
|
||||
require.NoError(t, aAgent.Close())
|
||||
}
|
||||
|
@@ -6,7 +6,7 @@ package ice
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestConnectedState_String(t *testing.T) {
|
||||
@@ -25,7 +25,7 @@ func TestConnectedState_String(t *testing.T) {
|
||||
}
|
||||
|
||||
for i, testCase := range testCases {
|
||||
assert.Equal(t,
|
||||
require.Equal(t,
|
||||
testCase.expectedString,
|
||||
testCase.connectionState.String(),
|
||||
"testCase: %d %v", i, testCase,
|
||||
@@ -45,7 +45,7 @@ func TestGatheringState_String(t *testing.T) {
|
||||
}
|
||||
|
||||
for i, testCase := range testCases {
|
||||
assert.Equal(t,
|
||||
require.Equal(t,
|
||||
testCase.expectedString,
|
||||
testCase.gatheringState.String(),
|
||||
"testCase: %d %v", i, testCase,
|
||||
|
20
mdns_test.go
20
mdns_test.go
@@ -13,7 +13,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/pion/transport/v3/test"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestMulticastDNSOnlyConnection(t *testing.T) {
|
||||
@@ -54,8 +54,8 @@ func TestMulticastDNSOnlyConnection(t *testing.T) {
|
||||
<-aConnected
|
||||
<-bConnected
|
||||
|
||||
assert.NoError(t, aAgent.Close())
|
||||
assert.NoError(t, bAgent.Close())
|
||||
require.NoError(t, aAgent.Close())
|
||||
require.NoError(t, bAgent.Close())
|
||||
}
|
||||
|
||||
func TestMulticastDNSMixedConnection(t *testing.T) {
|
||||
@@ -98,8 +98,8 @@ func TestMulticastDNSMixedConnection(t *testing.T) {
|
||||
<-aConnected
|
||||
<-bConnected
|
||||
|
||||
assert.NoError(t, aAgent.Close())
|
||||
assert.NoError(t, bAgent.Close())
|
||||
require.NoError(t, aAgent.Close())
|
||||
require.NoError(t, bAgent.Close())
|
||||
}
|
||||
|
||||
func TestMulticastDNSStaticHostName(t *testing.T) {
|
||||
@@ -115,7 +115,7 @@ func TestMulticastDNSStaticHostName(t *testing.T) {
|
||||
MulticastDNSMode: MulticastDNSModeQueryAndGather,
|
||||
MulticastDNSHostName: "invalidHostName",
|
||||
})
|
||||
assert.Equal(t, err, ErrInvalidMulticastDNSHostName)
|
||||
require.Equal(t, err, ErrInvalidMulticastDNSHostName)
|
||||
|
||||
agent, err := NewAgent(&AgentConfig{
|
||||
NetworkTypes: []NetworkType{NetworkTypeUDP4},
|
||||
@@ -123,18 +123,18 @@ func TestMulticastDNSStaticHostName(t *testing.T) {
|
||||
MulticastDNSMode: MulticastDNSModeQueryAndGather,
|
||||
MulticastDNSHostName: "validName.local",
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
correctHostName, resolveFunc := context.WithCancel(context.Background())
|
||||
assert.NoError(t, agent.OnCandidate(func(c Candidate) {
|
||||
require.NoError(t, agent.OnCandidate(func(c Candidate) {
|
||||
if c != nil && c.Address() == "validName.local" {
|
||||
resolveFunc()
|
||||
}
|
||||
}))
|
||||
|
||||
assert.NoError(t, agent.GatherCandidates())
|
||||
require.NoError(t, agent.GatherCandidates())
|
||||
<-correctHostName.Done()
|
||||
assert.NoError(t, agent.Close())
|
||||
require.NoError(t, agent.Close())
|
||||
}
|
||||
|
||||
func TestGenerateMulticastDNSName(t *testing.T) {
|
||||
|
10
net_test.go
10
net_test.go
@@ -7,7 +7,7 @@ import (
|
||||
"net"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestIsSupportedIPv6(t *testing.T) {
|
||||
@@ -37,8 +37,8 @@ func TestCreateAddr(t *testing.T) {
|
||||
ipv6 := net.IP{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}
|
||||
port := 9000
|
||||
|
||||
assert.Equal(t, &net.UDPAddr{IP: ipv4, Port: port}, createAddr(NetworkTypeUDP4, ipv4, port))
|
||||
assert.Equal(t, &net.UDPAddr{IP: ipv6, Port: port}, createAddr(NetworkTypeUDP6, ipv6, port))
|
||||
assert.Equal(t, &net.TCPAddr{IP: ipv4, Port: port}, createAddr(NetworkTypeTCP4, ipv4, port))
|
||||
assert.Equal(t, &net.TCPAddr{IP: ipv6, Port: port}, createAddr(NetworkTypeTCP6, ipv6, port))
|
||||
require.Equal(t, &net.UDPAddr{IP: ipv4, Port: port}, createAddr(NetworkTypeUDP4, ipv4, port))
|
||||
require.Equal(t, &net.UDPAddr{IP: ipv6, Port: port}, createAddr(NetworkTypeUDP6, ipv6, port))
|
||||
require.Equal(t, &net.TCPAddr{IP: ipv4, Port: port}, createAddr(NetworkTypeTCP4, ipv4, port))
|
||||
require.Equal(t, &net.TCPAddr{IP: ipv6, Port: port}, createAddr(NetworkTypeTCP6, ipv6, port))
|
||||
}
|
||||
|
@@ -7,7 +7,7 @@ import (
|
||||
"net"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestNetworkTypeParsing_Success(t *testing.T) {
|
||||
@@ -79,15 +79,15 @@ func TestNetworkTypeParsing_Failure(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestNetworkTypeIsUDP(t *testing.T) {
|
||||
assert.True(t, NetworkTypeUDP4.IsUDP())
|
||||
assert.True(t, NetworkTypeUDP6.IsUDP())
|
||||
assert.False(t, NetworkTypeUDP4.IsTCP())
|
||||
assert.False(t, NetworkTypeUDP6.IsTCP())
|
||||
require.True(t, NetworkTypeUDP4.IsUDP())
|
||||
require.True(t, NetworkTypeUDP6.IsUDP())
|
||||
require.False(t, NetworkTypeUDP4.IsTCP())
|
||||
require.False(t, NetworkTypeUDP6.IsTCP())
|
||||
}
|
||||
|
||||
func TestNetworkTypeIsTCP(t *testing.T) {
|
||||
assert.True(t, NetworkTypeTCP4.IsTCP())
|
||||
assert.True(t, NetworkTypeTCP6.IsTCP())
|
||||
assert.False(t, NetworkTypeTCP4.IsUDP())
|
||||
assert.False(t, NetworkTypeTCP6.IsUDP())
|
||||
require.True(t, NetworkTypeTCP4.IsTCP())
|
||||
require.True(t, NetworkTypeTCP6.IsTCP())
|
||||
require.False(t, NetworkTypeTCP4.IsUDP())
|
||||
require.False(t, NetworkTypeTCP6.IsUDP())
|
||||
}
|
||||
|
@@ -14,7 +14,6 @@ import (
|
||||
"github.com/pion/logging"
|
||||
"github.com/pion/stun/v2"
|
||||
"github.com/pion/transport/v3/test"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
@@ -77,9 +76,9 @@ func TestMultiTCPMux_Recv(t *testing.T) {
|
||||
recv := make([]byte, n)
|
||||
n2, rAddr, err := pktConn.ReadFrom(recv)
|
||||
require.NoError(t, err, "error receiving data")
|
||||
assert.Equal(t, conn.LocalAddr(), rAddr, "remote TCP address mismatch")
|
||||
assert.Equal(t, n, n2, "received byte size mismatch")
|
||||
assert.Equal(t, msg.Raw, recv, "received bytes mismatch")
|
||||
require.Equal(t, conn.LocalAddr(), rAddr, "remote TCP address mismatch")
|
||||
require.Equal(t, n, n2, "received byte size mismatch")
|
||||
require.Equal(t, msg.Raw, recv, "received bytes mismatch")
|
||||
|
||||
// Check echo response
|
||||
n, err = pktConn.WriteTo(recv, conn.LocalAddr())
|
||||
@@ -87,8 +86,8 @@ func TestMultiTCPMux_Recv(t *testing.T) {
|
||||
recvEcho := make([]byte, n)
|
||||
n3, err := readStreamingPacket(conn, recvEcho)
|
||||
require.NoError(t, err, "error receiving echo data")
|
||||
assert.Equal(t, n2, n3, "received byte size mismatch")
|
||||
assert.Equal(t, msg.Raw, recvEcho, "received bytes mismatch")
|
||||
require.Equal(t, n2, n3, "received byte size mismatch")
|
||||
require.Equal(t, msg.Raw, recvEcho, "received bytes mismatch")
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -126,6 +125,6 @@ func TestMultiTCPMux_NoDeadlockWhenClosingUnusedPacketConn(t *testing.T) {
|
||||
require.NoError(t, muxMulti.Close(), "error closing tcpMux")
|
||||
|
||||
conn, err := muxMulti.GetAllConns("test", false, net.IP{127, 0, 0, 1})
|
||||
assert.Nil(t, conn, "should receive nil because mux is closed")
|
||||
assert.Equal(t, io.ErrClosedPipe, err, "should receive error because mux is closed")
|
||||
require.Nil(t, conn, "should receive nil because mux is closed")
|
||||
require.Equal(t, io.ErrClosedPipe, err, "should receive error because mux is closed")
|
||||
}
|
||||
|
@@ -13,7 +13,6 @@ import (
|
||||
"github.com/pion/logging"
|
||||
"github.com/pion/stun/v2"
|
||||
"github.com/pion/transport/v3/test"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
@@ -73,9 +72,9 @@ func TestTCPMux_Recv(t *testing.T) {
|
||||
recv := make([]byte, n)
|
||||
n2, rAddr, err := pktConn.ReadFrom(recv)
|
||||
require.NoError(t, err, "error receiving data")
|
||||
assert.Equal(t, conn.LocalAddr(), rAddr, "remote tcp address mismatch")
|
||||
assert.Equal(t, n, n2, "received byte size mismatch")
|
||||
assert.Equal(t, msg.Raw, recv, "received bytes mismatch")
|
||||
require.Equal(t, conn.LocalAddr(), rAddr, "remote tcp address mismatch")
|
||||
require.Equal(t, n, n2, "received byte size mismatch")
|
||||
require.Equal(t, msg.Raw, recv, "received bytes mismatch")
|
||||
|
||||
// Check echo response
|
||||
n, err = pktConn.WriteTo(recv, conn.LocalAddr())
|
||||
@@ -83,8 +82,8 @@ func TestTCPMux_Recv(t *testing.T) {
|
||||
recvEcho := make([]byte, n)
|
||||
n3, err := readStreamingPacket(conn, recvEcho)
|
||||
require.NoError(t, err, "error receiving echo data")
|
||||
assert.Equal(t, n2, n3, "received byte size mismatch")
|
||||
assert.Equal(t, msg.Raw, recvEcho, "received bytes mismatch")
|
||||
require.Equal(t, n2, n3, "received byte size mismatch")
|
||||
require.Equal(t, msg.Raw, recvEcho, "received bytes mismatch")
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -120,8 +119,8 @@ func TestTCPMux_NoDeadlockWhenClosingUnusedPacketConn(t *testing.T) {
|
||||
require.NoError(t, tcpMux.Close(), "error closing tcpMux")
|
||||
|
||||
conn, err := tcpMux.GetConnByUfrag("test", false, listener.Addr().(*net.TCPAddr).IP)
|
||||
assert.Nil(t, conn, "should receive nil because mux is closed")
|
||||
assert.Equal(t, io.ErrClosedPipe, err, "should receive error because mux is closed")
|
||||
require.Nil(t, conn, "should receive nil because mux is closed")
|
||||
require.Equal(t, io.ErrClosedPipe, err, "should receive error because mux is closed")
|
||||
}
|
||||
|
||||
func TestTCPMux_FirstPacketTimeout(t *testing.T) {
|
||||
@@ -253,8 +252,8 @@ func TestTCPMux_NoLeakForConnectionFromStun(t *testing.T) {
|
||||
recv := make([]byte, n)
|
||||
n2, rAddr, err := pktConn.ReadFrom(recv)
|
||||
require.NoError(t, err, "error receiving data")
|
||||
assert.Equal(t, conn.LocalAddr(), rAddr, "remote tcp address mismatch")
|
||||
assert.Equal(t, n, n2, "received byte size mismatch")
|
||||
assert.Equal(t, msg.Raw, recv, "received bytes mismatch")
|
||||
require.Equal(t, conn.LocalAddr(), rAddr, "remote tcp address mismatch")
|
||||
require.Equal(t, n, n2, "received byte size mismatch")
|
||||
require.Equal(t, msg.Raw, recv, "received bytes mismatch")
|
||||
})
|
||||
}
|
||||
|
@@ -6,21 +6,21 @@ package ice
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestTCPType(t *testing.T) {
|
||||
var tcpType TCPType
|
||||
|
||||
assert.Equal(t, TCPTypeUnspecified, tcpType)
|
||||
assert.Equal(t, TCPTypeActive, NewTCPType("active"))
|
||||
assert.Equal(t, TCPTypePassive, NewTCPType("passive"))
|
||||
assert.Equal(t, TCPTypeSimultaneousOpen, NewTCPType("so"))
|
||||
assert.Equal(t, TCPTypeUnspecified, NewTCPType("something else"))
|
||||
require.Equal(t, TCPTypeUnspecified, tcpType)
|
||||
require.Equal(t, TCPTypeActive, NewTCPType("active"))
|
||||
require.Equal(t, TCPTypePassive, NewTCPType("passive"))
|
||||
require.Equal(t, TCPTypeSimultaneousOpen, NewTCPType("so"))
|
||||
require.Equal(t, TCPTypeUnspecified, NewTCPType("something else"))
|
||||
|
||||
assert.Equal(t, "", TCPTypeUnspecified.String())
|
||||
assert.Equal(t, "active", TCPTypeActive.String())
|
||||
assert.Equal(t, "passive", TCPTypePassive.String())
|
||||
assert.Equal(t, "so", TCPTypeSimultaneousOpen.String())
|
||||
assert.Equal(t, "Unknown", TCPType(-1).String())
|
||||
require.Equal(t, "", TCPTypeUnspecified.String())
|
||||
require.Equal(t, "active", TCPTypeActive.String())
|
||||
require.Equal(t, "passive", TCPTypePassive.String())
|
||||
require.Equal(t, "so", TCPTypeSimultaneousOpen.String())
|
||||
require.Equal(t, "Unknown", TCPType(-1).String())
|
||||
}
|
||||
|
@@ -15,7 +15,7 @@ import (
|
||||
"github.com/pion/stun/v2"
|
||||
"github.com/pion/transport/v3/test"
|
||||
"github.com/pion/transport/v3/vnet"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestRemoteLocalAddr(t *testing.T) {
|
||||
@@ -33,9 +33,7 @@ func TestRemoteLocalAddr(t *testing.T) {
|
||||
natType1 := &vnet.NATType{Mode: vnet.NATModeNAT1To1}
|
||||
|
||||
v, errVnet := buildVNet(natType0, natType1)
|
||||
if !assert.NoError(t, errVnet, "should succeed") {
|
||||
return
|
||||
}
|
||||
require.NoError(t, errVnet, "should succeed")
|
||||
defer v.close()
|
||||
|
||||
stunServerURL := &stun.URI{
|
||||
@@ -47,13 +45,13 @@ func TestRemoteLocalAddr(t *testing.T) {
|
||||
|
||||
t.Run("Disconnected Returns nil", func(t *testing.T) {
|
||||
disconnectedAgent, err := NewAgent(&AgentConfig{})
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
disconnectedConn := Conn{agent: disconnectedAgent}
|
||||
assert.Nil(t, disconnectedConn.RemoteAddr())
|
||||
assert.Nil(t, disconnectedConn.LocalAddr())
|
||||
require.Nil(t, disconnectedConn.RemoteAddr())
|
||||
require.Nil(t, disconnectedConn.LocalAddr())
|
||||
|
||||
assert.NoError(t, disconnectedConn.Close())
|
||||
require.NoError(t, disconnectedConn.Close())
|
||||
})
|
||||
|
||||
t.Run("Remote/Local Pair Match between Agents", func(t *testing.T) {
|
||||
@@ -72,27 +70,27 @@ func TestRemoteLocalAddr(t *testing.T) {
|
||||
bLAddr := cb.LocalAddr()
|
||||
|
||||
// Assert that nothing is nil
|
||||
assert.NotNil(t, aRAddr)
|
||||
assert.NotNil(t, aLAddr)
|
||||
assert.NotNil(t, bRAddr)
|
||||
assert.NotNil(t, bLAddr)
|
||||
require.NotNil(t, aRAddr)
|
||||
require.NotNil(t, aLAddr)
|
||||
require.NotNil(t, bRAddr)
|
||||
require.NotNil(t, bLAddr)
|
||||
|
||||
// Assert addresses
|
||||
assert.Equal(t, aLAddr.String(),
|
||||
require.Equal(t, aLAddr.String(),
|
||||
fmt.Sprintf("%s:%d", vnetLocalIPA, bRAddr.(*net.UDPAddr).Port), //nolint:forcetypeassert
|
||||
)
|
||||
assert.Equal(t, bLAddr.String(),
|
||||
require.Equal(t, bLAddr.String(),
|
||||
fmt.Sprintf("%s:%d", vnetLocalIPB, aRAddr.(*net.UDPAddr).Port), //nolint:forcetypeassert
|
||||
)
|
||||
assert.Equal(t, aRAddr.String(),
|
||||
require.Equal(t, aRAddr.String(),
|
||||
fmt.Sprintf("%s:%d", vnetGlobalIPB, bLAddr.(*net.UDPAddr).Port), //nolint:forcetypeassert
|
||||
)
|
||||
assert.Equal(t, bRAddr.String(),
|
||||
require.Equal(t, bRAddr.String(),
|
||||
fmt.Sprintf("%s:%d", vnetGlobalIPA, aLAddr.(*net.UDPAddr).Port), //nolint:forcetypeassert
|
||||
)
|
||||
|
||||
// Close
|
||||
assert.NoError(t, ca.Close())
|
||||
assert.NoError(t, cb.Close())
|
||||
require.NoError(t, ca.Close())
|
||||
require.NoError(t, cb.Close())
|
||||
})
|
||||
}
|
||||
|
Reference in New Issue
Block a user