100% coverage for config.go in Dispatchers

This commit is contained in:
andronache
2021-04-07 15:20:07 +03:00
committed by Dan Christian Bogos
parent ca3a3888fb
commit 989137b438

View File

@@ -84,3 +84,138 @@ func testDspConfigSv1GetJSONSection(t *testing.T) {
t.Errorf("Expected: %+v, received: %+v", utils.ToJSON(expected), utils.ToJSON(reply))
}
}
func TestDspConfigSv1GetConfigNil(t *testing.T) {
cgrCfg := config.NewDefaultCGRConfig()
dspSrv := NewDispatcherService(nil, cgrCfg, nil, nil)
CGREvent := &config.SectionWithAPIOpts{
Tenant: "tenant",
}
var reply *map[string]interface{}
result := dspSrv.ConfigSv1GetConfig(CGREvent, reply)
expected := "DISPATCHER_ERROR:NOT_FOUND"
if result == nil || result.Error() != expected {
t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result)
}
}
func TestDspConfigSv1GetConfigErrorNil(t *testing.T) {
cgrCfg := config.NewDefaultCGRConfig()
dspSrv := NewDispatcherService(nil, cgrCfg, nil, nil)
cgrCfg.DispatcherSCfg().AttributeSConns = []string{"test"}
CGREvent := &config.SectionWithAPIOpts{}
var reply *map[string]interface{}
result := dspSrv.ConfigSv1GetConfig(CGREvent, reply)
expected := "MANDATORY_IE_MISSING: [ApiKey]"
if result == nil || result.Error() != expected {
t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result)
}
}
func TestDspConfigSv1ReloadConfigNil(t *testing.T) {
cgrCfg := config.NewDefaultCGRConfig()
dspSrv := NewDispatcherService(nil, cgrCfg, nil, nil)
CGREvent := &config.ReloadArgs{
Tenant: "tenant",
}
var reply *string
result := dspSrv.ConfigSv1ReloadConfig(CGREvent, reply)
expected := "DISPATCHER_ERROR:NOT_FOUND"
if result == nil || result.Error() != expected {
t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result)
}
}
func TestDspConfigSv1ReloadConfigErrorNil(t *testing.T) {
cgrCfg := config.NewDefaultCGRConfig()
dspSrv := NewDispatcherService(nil, cgrCfg, nil, nil)
cgrCfg.DispatcherSCfg().AttributeSConns = []string{"test"}
CGREvent := &config.ReloadArgs{}
var reply *string
result := dspSrv.ConfigSv1ReloadConfig(CGREvent, reply)
expected := "MANDATORY_IE_MISSING: [ApiKey]"
if result == nil || result.Error() != expected {
t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result)
}
}
func TestDspConfigSv1SetConfigNil(t *testing.T) {
cgrCfg := config.NewDefaultCGRConfig()
dspSrv := NewDispatcherService(nil, cgrCfg, nil, nil)
CGREvent := &config.SetConfigArgs{
Tenant: "tenant",
}
var reply *string
result := dspSrv.ConfigSv1SetConfig(CGREvent, reply)
expected := "DISPATCHER_ERROR:NOT_FOUND"
if result == nil || result.Error() != expected {
t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result)
}
}
func TestDspConfigSv1SetConfigErrorNil(t *testing.T) {
cgrCfg := config.NewDefaultCGRConfig()
dspSrv := NewDispatcherService(nil, cgrCfg, nil, nil)
cgrCfg.DispatcherSCfg().AttributeSConns = []string{"test"}
CGREvent := &config.SetConfigArgs{}
var reply *string
result := dspSrv.ConfigSv1SetConfig(CGREvent, reply)
expected := "MANDATORY_IE_MISSING: [ApiKey]"
if result == nil || result.Error() != expected {
t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result)
}
}
func TestDspConfigSv1SetConfigFromJSONNil(t *testing.T) {
cgrCfg := config.NewDefaultCGRConfig()
dspSrv := NewDispatcherService(nil, cgrCfg, nil, nil)
CGREvent := &config.SetConfigFromJSONArgs{
Tenant: "tenant",
}
var reply *string
result := dspSrv.ConfigSv1SetConfigFromJSON(CGREvent, reply)
expected := "DISPATCHER_ERROR:NOT_FOUND"
if result == nil || result.Error() != expected {
t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result)
}
}
func TestDspConfigSv1SetConfigFromJSONErrorNil(t *testing.T) {
cgrCfg := config.NewDefaultCGRConfig()
dspSrv := NewDispatcherService(nil, cgrCfg, nil, nil)
cgrCfg.DispatcherSCfg().AttributeSConns = []string{"test"}
CGREvent := &config.SetConfigFromJSONArgs{}
var reply *string
result := dspSrv.ConfigSv1SetConfigFromJSON(CGREvent, reply)
expected := "MANDATORY_IE_MISSING: [ApiKey]"
if result == nil || result.Error() != expected {
t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result)
}
}
func TestDspConfigSv1GetConfigAsJSONNil(t *testing.T) {
cgrCfg := config.NewDefaultCGRConfig()
dspSrv := NewDispatcherService(nil, cgrCfg, nil, nil)
CGREvent := &config.SectionWithAPIOpts{
Tenant: "tenant",
}
var reply *string
result := dspSrv.ConfigSv1GetConfigAsJSON(CGREvent, reply)
expected := "DISPATCHER_ERROR:NOT_FOUND"
if result == nil || result.Error() != expected {
t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result)
}
}
func TestDspConfigSv1GetConfigAsJSONErrorNil(t *testing.T) {
cgrCfg := config.NewDefaultCGRConfig()
dspSrv := NewDispatcherService(nil, cgrCfg, nil, nil)
cgrCfg.DispatcherSCfg().AttributeSConns = []string{"test"}
CGREvent := &config.SectionWithAPIOpts{}
var reply *string
result := dspSrv.ConfigSv1GetConfigAsJSON(CGREvent, reply)
expected := "MANDATORY_IE_MISSING: [ApiKey]"
if result == nil || result.Error() != expected {
t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result)
}
}