api_test.go 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. // SPDX-FileCopyrightText: 2023 The Pion community <https://pion.ly>
  2. // SPDX-License-Identifier: MIT
  3. //go:build !js
  4. // +build !js
  5. package webrtc
  6. import (
  7. "testing"
  8. "github.com/stretchr/testify/assert"
  9. )
  10. func TestNewAPI(t *testing.T) {
  11. api := NewAPI()
  12. if api.settingEngine == nil {
  13. t.Error("Failed to init settings engine")
  14. }
  15. if api.mediaEngine == nil {
  16. t.Error("Failed to init media engine")
  17. }
  18. if api.interceptorRegistry == nil {
  19. t.Error("Failed to init interceptor registry")
  20. }
  21. }
  22. func TestNewAPI_Options(t *testing.T) {
  23. s := SettingEngine{}
  24. s.DetachDataChannels()
  25. m := MediaEngine{}
  26. assert.NoError(t, m.RegisterDefaultCodecs())
  27. api := NewAPI(
  28. WithSettingEngine(s),
  29. WithMediaEngine(&m),
  30. )
  31. if !api.settingEngine.detach.DataChannels {
  32. t.Error("Failed to set settings engine")
  33. }
  34. if len(api.mediaEngine.audioCodecs) == 0 || len(api.mediaEngine.videoCodecs) == 0 {
  35. t.Error("Failed to set media engine")
  36. }
  37. }
  38. func TestNewAPI_OptionsDefaultize(t *testing.T) {
  39. api := NewAPI(
  40. WithMediaEngine(nil),
  41. WithInterceptorRegistry(nil),
  42. )
  43. assert.NotNil(t, api.settingEngine)
  44. assert.NotNil(t, api.mediaEngine)
  45. assert.NotNil(t, api.interceptorRegistry)
  46. }