Improve API nil handling

Create struct with default values in NewAPI instead of doing nil checks
later.
This commit is contained in:
Roman Romanenko
2022-01-31 00:00:17 +03:00
committed by Sean DuBois
parent 6ddddd8cea
commit 82b3ab583c
2 changed files with 28 additions and 18 deletions

View File

@@ -19,6 +19,10 @@ func TestNewAPI(t *testing.T) {
if api.mediaEngine == nil {
t.Error("Failed to init media engine")
}
if api.interceptorRegistry == nil {
t.Error("Failed to init interceptor registry")
}
}
func TestNewAPI_Options(t *testing.T) {
@@ -40,3 +44,14 @@ func TestNewAPI_Options(t *testing.T) {
t.Error("Failed to set media engine")
}
}
func TestNewAPI_OptionsDefaultize(t *testing.T) {
api := NewAPI(
WithMediaEngine(nil),
WithInterceptorRegistry(nil),
)
assert.NotNil(t, api.settingEngine)
assert.NotNil(t, api.mediaEngine)
assert.NotNil(t, api.interceptorRegistry)
}