iceprotocol_test.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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 TestNewICEProtocol(t *testing.T) {
  9. testCases := []struct {
  10. protoString string
  11. shouldFail bool
  12. expectedProto ICEProtocol
  13. }{
  14. {unknownStr, true, ICEProtocol(Unknown)},
  15. {"udp", false, ICEProtocolUDP},
  16. {"tcp", false, ICEProtocolTCP},
  17. {"UDP", false, ICEProtocolUDP},
  18. {"TCP", false, ICEProtocolTCP},
  19. }
  20. for i, testCase := range testCases {
  21. actual, err := NewICEProtocol(testCase.protoString)
  22. if (err != nil) != testCase.shouldFail {
  23. t.Error(err)
  24. }
  25. assert.Equal(t,
  26. testCase.expectedProto,
  27. actual,
  28. "testCase: %d %v", i, testCase,
  29. )
  30. }
  31. }
  32. func TestICEProtocol_String(t *testing.T) {
  33. testCases := []struct {
  34. proto ICEProtocol
  35. expectedString string
  36. }{
  37. {ICEProtocol(Unknown), unknownStr},
  38. {ICEProtocolUDP, "udp"},
  39. {ICEProtocolTCP, "tcp"},
  40. }
  41. for i, testCase := range testCases {
  42. assert.Equal(t,
  43. testCase.expectedString,
  44. testCase.proto.String(),
  45. "testCase: %d %v", i, testCase,
  46. )
  47. }
  48. }