github.com/pion/webrtc/v3@v3.2.24/datachannelstate_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 TestNewDataChannelState(t *testing.T) {
    13  	testCases := []struct {
    14  		stateString   string
    15  		expectedState DataChannelState
    16  	}{
    17  		{unknownStr, DataChannelState(Unknown)},
    18  		{"connecting", DataChannelStateConnecting},
    19  		{"open", DataChannelStateOpen},
    20  		{"closing", DataChannelStateClosing},
    21  		{"closed", DataChannelStateClosed},
    22  	}
    23  
    24  	for i, testCase := range testCases {
    25  		assert.Equal(t,
    26  			testCase.expectedState,
    27  			newDataChannelState(testCase.stateString),
    28  			"testCase: %d %v", i, testCase,
    29  		)
    30  	}
    31  }
    32  
    33  func TestDataChannelState_String(t *testing.T) {
    34  	testCases := []struct {
    35  		state          DataChannelState
    36  		expectedString string
    37  	}{
    38  		{DataChannelState(Unknown), unknownStr},
    39  		{DataChannelStateConnecting, "connecting"},
    40  		{DataChannelStateOpen, "open"},
    41  		{DataChannelStateClosing, "closing"},
    42  		{DataChannelStateClosed, "closed"},
    43  	}
    44  
    45  	for i, testCase := range testCases {
    46  		assert.Equal(t,
    47  			testCase.expectedString,
    48  			testCase.state.String(),
    49  			"testCase: %d %v", i, testCase,
    50  		)
    51  	}
    52  }