mirror of
				https://github.com/pion/webrtc.git
				synced 2025-10-31 18:52:55 +08:00 
			
		
		
		
	 2838b1a836
			
		
	
	2838b1a836
	
	
	
		
			
			Users are unable to use the callbacks inside `internal/ice`. Even though we alias things like OnSelectedCandidatePairChange are unusable since in the package they use `ice.Candidate` instead of `ICECandidate`
		
			
				
	
	
		
			54 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			54 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
| package webrtc
 | |
| 
 | |
| import (
 | |
| 	"encoding/json"
 | |
| 	"testing"
 | |
| 
 | |
| 	"github.com/stretchr/testify/assert"
 | |
| )
 | |
| 
 | |
| func TestICECandidateInit_Serialization(t *testing.T) {
 | |
| 	tt := []struct {
 | |
| 		candidate  ICECandidateInit
 | |
| 		serialized string
 | |
| 	}{
 | |
| 		{ICECandidateInit{
 | |
| 			Candidate:        "candidate:abc123",
 | |
| 			SDPMid:           refString("0"),
 | |
| 			SDPMLineIndex:    refUint16(0),
 | |
| 			UsernameFragment: "def",
 | |
| 		}, `{"candidate":"candidate:abc123","sdpMid":"0","sdpMLineIndex":0,"usernameFragment":"def"}`},
 | |
| 		{ICECandidateInit{
 | |
| 			Candidate:        "candidate:abc123",
 | |
| 			UsernameFragment: "def",
 | |
| 		}, `{"candidate":"candidate:abc123","usernameFragment":"def"}`},
 | |
| 	}
 | |
| 
 | |
| 	for i, tc := range tt {
 | |
| 		b, err := json.Marshal(tc.candidate)
 | |
| 		if err != nil {
 | |
| 			t.Errorf("Failed to marshal %d: %v", i, err)
 | |
| 		}
 | |
| 		actualSerialized := string(b)
 | |
| 		if actualSerialized != tc.serialized {
 | |
| 			t.Errorf("%d expected %s got %s", i, tc.serialized, actualSerialized)
 | |
| 		}
 | |
| 
 | |
| 		var actual ICECandidateInit
 | |
| 		err = json.Unmarshal(b, &actual)
 | |
| 		if err != nil {
 | |
| 			t.Errorf("Failed to unmarshal %d: %v", i, err)
 | |
| 		}
 | |
| 
 | |
| 		assert.Equal(t, tc.candidate, actual, "should match")
 | |
| 	}
 | |
| }
 | |
| 
 | |
| func refString(s string) *string {
 | |
| 	return &s
 | |
| }
 | |
| 
 | |
| func refUint16(i uint16) *uint16 {
 | |
| 	return &i
 | |
| }
 |