github.com/pion/webrtc/v4@v4.0.1/peerconnectionstate_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 TestNewPeerConnectionState(t *testing.T) {
    13  	testCases := []struct {
    14  		stateString   string
    15  		expectedState PeerConnectionState
    16  	}{
    17  		{ErrUnknownType.Error(), PeerConnectionStateUnknown},
    18  		{"new", PeerConnectionStateNew},
    19  		{"connecting", PeerConnectionStateConnecting},
    20  		{"connected", PeerConnectionStateConnected},
    21  		{"disconnected", PeerConnectionStateDisconnected},
    22  		{"failed", PeerConnectionStateFailed},
    23  		{"closed", PeerConnectionStateClosed},
    24  	}
    25  
    26  	for i, testCase := range testCases {
    27  		assert.Equal(t,
    28  			testCase.expectedState,
    29  			newPeerConnectionState(testCase.stateString),
    30  			"testCase: %d %v", i, testCase,
    31  		)
    32  	}
    33  }
    34  
    35  func TestPeerConnectionState_String(t *testing.T) {
    36  	testCases := []struct {
    37  		state          PeerConnectionState
    38  		expectedString string
    39  	}{
    40  		{PeerConnectionStateUnknown, ErrUnknownType.Error()},
    41  		{PeerConnectionStateNew, "new"},
    42  		{PeerConnectionStateConnecting, "connecting"},
    43  		{PeerConnectionStateConnected, "connected"},
    44  		{PeerConnectionStateDisconnected, "disconnected"},
    45  		{PeerConnectionStateFailed, "failed"},
    46  		{PeerConnectionStateClosed, "closed"},
    47  	}
    48  
    49  	for i, testCase := range testCases {
    50  		assert.Equal(t,
    51  			testCase.expectedString,
    52  			testCase.state.String(),
    53  			"testCase: %d %v", i, testCase,
    54  		)
    55  	}
    56  }