iceconnectionstate_test.go 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. // SPDX-FileCopyrightText: 2023 The Pion community <https://pion.ly>
  2. // SPDX-License-Identifier: MIT
  3. package webrtc
  4. import (
  5. "testing"
  6. "github.com/stretchr/testify/assert"
  7. )
  8. func TestNewICEConnectionState(t *testing.T) {
  9. testCases := []struct {
  10. stateString string
  11. expectedState ICEConnectionState
  12. }{
  13. {unknownStr, ICEConnectionState(Unknown)},
  14. {"new", ICEConnectionStateNew},
  15. {"checking", ICEConnectionStateChecking},
  16. {"connected", ICEConnectionStateConnected},
  17. {"completed", ICEConnectionStateCompleted},
  18. {"disconnected", ICEConnectionStateDisconnected},
  19. {"failed", ICEConnectionStateFailed},
  20. {"closed", ICEConnectionStateClosed},
  21. }
  22. for i, testCase := range testCases {
  23. assert.Equal(t,
  24. testCase.expectedState,
  25. NewICEConnectionState(testCase.stateString),
  26. "testCase: %d %v", i, testCase,
  27. )
  28. }
  29. }
  30. func TestICEConnectionState_String(t *testing.T) {
  31. testCases := []struct {
  32. state ICEConnectionState
  33. expectedString string
  34. }{
  35. {ICEConnectionState(Unknown), unknownStr},
  36. {ICEConnectionStateNew, "new"},
  37. {ICEConnectionStateChecking, "checking"},
  38. {ICEConnectionStateConnected, "connected"},
  39. {ICEConnectionStateCompleted, "completed"},
  40. {ICEConnectionStateDisconnected, "disconnected"},
  41. {ICEConnectionStateFailed, "failed"},
  42. {ICEConnectionStateClosed, "closed"},
  43. }
  44. for i, testCase := range testCases {
  45. assert.Equal(t,
  46. testCase.expectedString,
  47. testCase.state.String(),
  48. "testCase: %d %v", i, testCase,
  49. )
  50. }
  51. }