github.com/pion/webrtc/v3@v3.2.24/networktype_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 TestNetworkType_String(t *testing.T) { 13 testCases := []struct { 14 cType NetworkType 15 expectedString string 16 }{ 17 {NetworkType(Unknown), unknownStr}, 18 {NetworkTypeUDP4, "udp4"}, 19 {NetworkTypeUDP6, "udp6"}, 20 {NetworkTypeTCP4, "tcp4"}, 21 {NetworkTypeTCP6, "tcp6"}, 22 } 23 24 for i, testCase := range testCases { 25 assert.Equal(t, 26 testCase.expectedString, 27 testCase.cType.String(), 28 "testCase: %d %v", i, testCase, 29 ) 30 } 31 } 32 33 func TestNetworkType(t *testing.T) { 34 testCases := []struct { 35 typeString string 36 shouldFail bool 37 expectedType NetworkType 38 }{ 39 {unknownStr, true, NetworkType(Unknown)}, 40 {"udp4", false, NetworkTypeUDP4}, 41 {"udp6", false, NetworkTypeUDP6}, 42 {"tcp4", false, NetworkTypeTCP4}, 43 {"tcp6", false, NetworkTypeTCP6}, 44 } 45 46 for i, testCase := range testCases { 47 actual, err := NewNetworkType(testCase.typeString) 48 if (err != nil) != testCase.shouldFail { 49 t.Error(err) 50 } 51 assert.Equal(t, 52 testCase.expectedType, 53 actual, 54 "testCase: %d %v", i, testCase, 55 ) 56 } 57 }