github.com/pion/webrtc/v4@v4.0.1/iceprotocol_test.go (about)

     1  // SPDX-FileCopyrightText: 2023 The Pion community <https://pion.ly>
     2  // SPDX-License-Identifier: MIT
     3  
     4  package webrtc
     5  
     6  import (
     7  	"testing"
     8  
     9  	"github.com/stretchr/testify/assert"
    10  )
    11  
    12  func TestNewICEProtocol(t *testing.T) {
    13  	testCases := []struct {
    14  		protoString   string
    15  		shouldFail    bool
    16  		expectedProto ICEProtocol
    17  	}{
    18  		{ErrUnknownType.Error(), true, ICEProtocolUnknown},
    19  		{"udp", false, ICEProtocolUDP},
    20  		{"tcp", false, ICEProtocolTCP},
    21  		{"UDP", false, ICEProtocolUDP},
    22  		{"TCP", false, ICEProtocolTCP},
    23  	}
    24  
    25  	for i, testCase := range testCases {
    26  		actual, err := NewICEProtocol(testCase.protoString)
    27  		if (err != nil) != testCase.shouldFail {
    28  			t.Error(err)
    29  		}
    30  		assert.Equal(t,
    31  			testCase.expectedProto,
    32  			actual,
    33  			"testCase: %d %v", i, testCase,
    34  		)
    35  	}
    36  }
    37  
    38  func TestICEProtocol_String(t *testing.T) {
    39  	testCases := []struct {
    40  		proto          ICEProtocol
    41  		expectedString string
    42  	}{
    43  		{ICEProtocolUnknown, ErrUnknownType.Error()},
    44  		{ICEProtocolUDP, "udp"},
    45  		{ICEProtocolTCP, "tcp"},
    46  	}
    47  
    48  	for i, testCase := range testCases {
    49  		assert.Equal(t,
    50  			testCase.expectedString,
    51  			testCase.proto.String(),
    52  			"testCase: %d %v", i, testCase,
    53  		)
    54  	}
    55  }