github.com/pion/webrtc/v3@v3.2.24/icetransportstate_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/pion/ice/v2"
    10  	"github.com/stretchr/testify/assert"
    11  )
    12  
    13  func TestICETransportState_String(t *testing.T) {
    14  	testCases := []struct {
    15  		state          ICETransportState
    16  		expectedString string
    17  	}{
    18  		{ICETransportState(Unknown), unknownStr},
    19  		{ICETransportStateNew, "new"},
    20  		{ICETransportStateChecking, "checking"},
    21  		{ICETransportStateConnected, "connected"},
    22  		{ICETransportStateCompleted, "completed"},
    23  		{ICETransportStateFailed, "failed"},
    24  		{ICETransportStateDisconnected, "disconnected"},
    25  		{ICETransportStateClosed, "closed"},
    26  	}
    27  
    28  	for i, testCase := range testCases {
    29  		assert.Equal(t,
    30  			testCase.expectedString,
    31  			testCase.state.String(),
    32  			"testCase: %d %v", i, testCase,
    33  		)
    34  	}
    35  }
    36  
    37  func TestICETransportState_Convert(t *testing.T) {
    38  	testCases := []struct {
    39  		native ICETransportState
    40  		ice    ice.ConnectionState
    41  	}{
    42  		{ICETransportState(Unknown), ice.ConnectionState(Unknown)},
    43  		{ICETransportStateNew, ice.ConnectionStateNew},
    44  		{ICETransportStateChecking, ice.ConnectionStateChecking},
    45  		{ICETransportStateConnected, ice.ConnectionStateConnected},
    46  		{ICETransportStateCompleted, ice.ConnectionStateCompleted},
    47  		{ICETransportStateFailed, ice.ConnectionStateFailed},
    48  		{ICETransportStateDisconnected, ice.ConnectionStateDisconnected},
    49  		{ICETransportStateClosed, ice.ConnectionStateClosed},
    50  	}
    51  
    52  	for i, testCase := range testCases {
    53  		assert.Equal(t,
    54  			testCase.native.toICE(),
    55  			testCase.ice,
    56  			"testCase: %d %v", i, testCase,
    57  		)
    58  		assert.Equal(t,
    59  			testCase.native,
    60  			newICETransportStateFromICE(testCase.ice),
    61  			"testCase: %d %v", i, testCase,
    62  		)
    63  	}
    64  }