mirror of
				https://github.com/pion/webrtc.git
				synced 2025-10-31 18:52:55 +08:00 
			
		
		
		
	 7584762124
			
		
	
	7584762124
	
	
	
		
			
			User can now control what DTLSRole the local client takes when answering via the SettingEngine. Relates to #880
		
			
				
	
	
		
			92 lines
		
	
	
		
			2.3 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			92 lines
		
	
	
		
			2.3 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
| // +build !js
 | |
| 
 | |
| package webrtc
 | |
| 
 | |
| import (
 | |
| 	"testing"
 | |
| 	"time"
 | |
| 
 | |
| 	"github.com/stretchr/testify/assert"
 | |
| )
 | |
| 
 | |
| func TestSetEphemeralUDPPortRange(t *testing.T) {
 | |
| 	s := SettingEngine{}
 | |
| 
 | |
| 	if s.ephemeralUDP.PortMin != 0 ||
 | |
| 		s.ephemeralUDP.PortMax != 0 {
 | |
| 		t.Fatalf("SettingEngine defaults aren't as expected.")
 | |
| 	}
 | |
| 
 | |
| 	// set bad ephemeral ports
 | |
| 	if err := s.SetEphemeralUDPPortRange(3000, 2999); err == nil {
 | |
| 		t.Fatalf("Setting engine should fail bad ephemeral ports.")
 | |
| 	}
 | |
| 
 | |
| 	if err := s.SetEphemeralUDPPortRange(3000, 4000); err != nil {
 | |
| 		t.Fatalf("Setting engine failed valid port range: %s", err)
 | |
| 	}
 | |
| 
 | |
| 	if s.ephemeralUDP.PortMin != 3000 ||
 | |
| 		s.ephemeralUDP.PortMax != 4000 {
 | |
| 		t.Fatalf("Setting engine ports do not reflect expected range")
 | |
| 	}
 | |
| }
 | |
| 
 | |
| func TestSetConnectionTimeout(t *testing.T) {
 | |
| 	s := SettingEngine{}
 | |
| 
 | |
| 	if s.timeout.ICEConnection != nil ||
 | |
| 		s.timeout.ICEKeepalive != nil {
 | |
| 		t.Fatalf("SettingEngine defaults aren't as expected.")
 | |
| 	}
 | |
| 
 | |
| 	s.SetConnectionTimeout(5*time.Second, 1*time.Second)
 | |
| 
 | |
| 	if s.timeout.ICEConnection == nil ||
 | |
| 		*s.timeout.ICEConnection != 5*time.Second ||
 | |
| 		s.timeout.ICEKeepalive == nil ||
 | |
| 		*s.timeout.ICEKeepalive != 1*time.Second {
 | |
| 		t.Fatalf("ICE Timeouts do not reflect requested values.")
 | |
| 	}
 | |
| }
 | |
| 
 | |
| func TestDetachDataChannels(t *testing.T) {
 | |
| 	s := SettingEngine{}
 | |
| 
 | |
| 	if s.detach.DataChannels {
 | |
| 		t.Fatalf("SettingEngine defaults aren't as expected.")
 | |
| 	}
 | |
| 
 | |
| 	s.DetachDataChannels()
 | |
| 
 | |
| 	if !s.detach.DataChannels {
 | |
| 		t.Fatalf("Failed to enable detached data channels.")
 | |
| 	}
 | |
| }
 | |
| 
 | |
| func TestSetNAT1To1IPs(t *testing.T) {
 | |
| 	s := SettingEngine{}
 | |
| 	if s.candidates.NAT1To1IPs != nil {
 | |
| 		t.Errorf("Invalid default value")
 | |
| 	}
 | |
| 	if s.candidates.NAT1To1IPCandidateType != 0 {
 | |
| 		t.Errorf("Invalid default value")
 | |
| 	}
 | |
| 
 | |
| 	ips := []string{"1.2.3.4"}
 | |
| 	typ := ICECandidateTypeHost
 | |
| 	s.SetNAT1To1IPs(ips, typ)
 | |
| 	if len(s.candidates.NAT1To1IPs) != 1 || s.candidates.NAT1To1IPs[0] != "1.2.3.4" {
 | |
| 		t.Fatalf("Failed to set NAT1To1IPs")
 | |
| 	}
 | |
| 	if s.candidates.NAT1To1IPCandidateType != typ {
 | |
| 		t.Fatalf("Failed to set NAT1To1IPCandidateType")
 | |
| 	}
 | |
| }
 | |
| 
 | |
| func TestSetAnsweringDTLSRole(t *testing.T) {
 | |
| 	s := SettingEngine{}
 | |
| 	assert.Error(t, s.SetAnsweringDTLSRole(DTLSRoleAuto), "SetAnsweringDTLSRole can only be called with DTLSRoleClient or DTLSRoleServer")
 | |
| 	assert.Error(t, s.SetAnsweringDTLSRole(DTLSRole(0)), "SetAnsweringDTLSRole can only be called with DTLSRoleClient or DTLSRoleServer")
 | |
| }
 |