github.com/pion/webrtc/v4@v4.0.1/icecandidatetype_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 TestICECandidateType(t *testing.T) {
    13  	testCases := []struct {
    14  		typeString   string
    15  		shouldFail   bool
    16  		expectedType ICECandidateType
    17  	}{
    18  		{ErrUnknownType.Error(), true, ICECandidateTypeUnknown},
    19  		{"host", false, ICECandidateTypeHost},
    20  		{"srflx", false, ICECandidateTypeSrflx},
    21  		{"prflx", false, ICECandidateTypePrflx},
    22  		{"relay", false, ICECandidateTypeRelay},
    23  	}
    24  
    25  	for i, testCase := range testCases {
    26  		actual, err := NewICECandidateType(testCase.typeString)
    27  		if (err != nil) != testCase.shouldFail {
    28  			t.Error(err)
    29  		}
    30  		assert.Equal(t,
    31  			testCase.expectedType,
    32  			actual,
    33  			"testCase: %d %v", i, testCase,
    34  		)
    35  	}
    36  }
    37  
    38  func TestICECandidateType_String(t *testing.T) {
    39  	testCases := []struct {
    40  		cType          ICECandidateType
    41  		expectedString string
    42  	}{
    43  		{ICECandidateTypeUnknown, ErrUnknownType.Error()},
    44  		{ICECandidateTypeHost, "host"},
    45  		{ICECandidateTypeSrflx, "srflx"},
    46  		{ICECandidateTypePrflx, "prflx"},
    47  		{ICECandidateTypeRelay, "relay"},
    48  	}
    49  
    50  	for i, testCase := range testCases {
    51  		assert.Equal(t,
    52  			testCase.expectedString,
    53  			testCase.cType.String(),
    54  			"testCase: %d %v", i, testCase,
    55  		)
    56  	}
    57  }