github.com/pion/webrtc/v4@v4.0.1/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 35 api := NewAPI( 36 WithSettingEngine(s), 37 ) 38 39 if !api.settingEngine.detach.DataChannels { 40 t.Error("Failed to set settings engine") 41 } 42 43 if len(api.mediaEngine.audioCodecs) == 0 || len(api.mediaEngine.videoCodecs) == 0 { 44 t.Error("Failed to set media engine") 45 } 46 } 47 48 func TestNewAPI_OptionsDefaultize(t *testing.T) { 49 api := NewAPI( 50 WithMediaEngine(nil), 51 WithInterceptorRegistry(nil), 52 ) 53 54 assert.NotNil(t, api.settingEngine) 55 assert.NotNil(t, api.mediaEngine) 56 assert.NotNil(t, api.interceptorRegistry) 57 }