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