From 88fe1db5aa045585bc06c709076428b0982fec3b Mon Sep 17 00:00:00 2001 From: andronache Date: Thu, 8 Apr 2021 16:32:57 +0300 Subject: [PATCH] Cover tests in Dispatchers for resources.go and replicator.go --- dispatchers/replicator_it_test.go | 120 ++++++++++++++++++++++++++++++ 1 file changed, 120 insertions(+) diff --git a/dispatchers/replicator_it_test.go b/dispatchers/replicator_it_test.go index a7a25747e..dbac43772 100644 --- a/dispatchers/replicator_it_test.go +++ b/dispatchers/replicator_it_test.go @@ -2374,3 +2374,123 @@ func TestDspReplicatorSv1GetDispatcherProfileErrorNil(t *testing.T) { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) } } + +func TestDspReplicatorSv1GetDispatcherHostNil(t *testing.T) { + cgrCfg := config.NewDefaultCGRConfig() + dspSrv := NewDispatcherService(nil, cgrCfg, nil, nil) + cgrCfg.DispatcherSCfg().AttributeSConns = []string{"test"} + CGREvent := &utils.TenantIDWithAPIOpts{ + TenantID: &utils.TenantID{ + Tenant: "tenant", + }, + } + var reply *engine.DispatcherHost + result := dspSrv.ReplicatorSv1GetDispatcherHost(CGREvent, reply) + expected := "MANDATORY_IE_MISSING: [ApiKey]" + if result == nil || result.Error() != expected { + t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) + } +} + +func TestDspReplicatorSv1GetDispatcherHostErrorNil(t *testing.T) { + cgrCfg := config.NewDefaultCGRConfig() + dspSrv := NewDispatcherService(nil, cgrCfg, nil, nil) + CGREvent := &utils.TenantIDWithAPIOpts{ + TenantID: &utils.TenantID{ + Tenant: "tenant", + }, + } + var reply *engine.DispatcherHost + result := dspSrv.ReplicatorSv1GetDispatcherHost(CGREvent, reply) + expected := "DISPATCHER_ERROR:NOT_FOUND" + if result == nil || result.Error() != expected { + t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) + } +} + +func TestDspReplicatorSv1GetItemLoadIDsNilEvent(t *testing.T) { + cgrCfg := config.NewDefaultCGRConfig() + dspSrv := NewDispatcherService(nil, cgrCfg, nil, nil) + cgrCfg.DispatcherSCfg().AttributeSConns = []string{"test"} + var reply *map[string]int64 + result := dspSrv.ReplicatorSv1GetItemLoadIDs(nil, reply) + expected := "MANDATORY_IE_MISSING: [ApiKey]" + if result == nil || result.Error() != expected { + t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) + } +} + +func TestDspReplicatorSv1GetItemLoadIDsNil(t *testing.T) { + cgrCfg := config.NewDefaultCGRConfig() + dspSrv := NewDispatcherService(nil, cgrCfg, nil, nil) + cgrCfg.DispatcherSCfg().AttributeSConns = []string{"test"} + CGREvent := &utils.StringWithAPIOpts{ + Tenant: "tenant", + } + var reply *map[string]int64 + result := dspSrv.ReplicatorSv1GetItemLoadIDs(CGREvent, reply) + expected := "MANDATORY_IE_MISSING: [ApiKey]" + if result == nil || result.Error() != expected { + t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) + } +} + +func TestDspReplicatorSv1GetItemLoadIDsErrorNil(t *testing.T) { + cgrCfg := config.NewDefaultCGRConfig() + dspSrv := NewDispatcherService(nil, cgrCfg, nil, nil) + CGREvent := &utils.StringWithAPIOpts{ + Tenant: "tenant", + } + var reply *map[string]int64 + result := dspSrv.ReplicatorSv1GetItemLoadIDs(CGREvent, reply) + expected := "DISPATCHER_ERROR:NOT_FOUND" + if result == nil || result.Error() != expected { + t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) + } +} + +func TestDspReplicatorSv1SetThresholdProfileNil(t *testing.T) { + cgrCfg := config.NewDefaultCGRConfig() + dspSrv := NewDispatcherService(nil, cgrCfg, nil, nil) + cgrCfg.DispatcherSCfg().AttributeSConns = []string{"test"} + CGREvent := &engine.ThresholdProfileWithAPIOpts{ + ThresholdProfile: &engine.ThresholdProfile{ + Tenant: "tenant", + }, + } + var reply *string + result := dspSrv.ReplicatorSv1SetThresholdProfile(CGREvent, reply) + expected := "MANDATORY_IE_MISSING: [ApiKey]" + if result == nil || result.Error() != expected { + t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) + } +} + +func TestDspReplicatorSv1SetThresholdProfileErrorNil(t *testing.T) { + cgrCfg := config.NewDefaultCGRConfig() + dspSrv := NewDispatcherService(nil, cgrCfg, nil, nil) + CGREvent := &engine.ThresholdProfileWithAPIOpts{ + ThresholdProfile: &engine.ThresholdProfile{ + Tenant: "tenant", + }, + } + var reply *string + result := dspSrv.ReplicatorSv1SetThresholdProfile(CGREvent, reply) + expected := "DISPATCHER_ERROR:NOT_FOUND" + if result == nil || result.Error() != expected { + t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) + } +} + +func TestDspReplicatorSv1SetThresholdProfileNilEvent(t *testing.T) { + cgrCfg := config.NewDefaultCGRConfig() + dspSrv := NewDispatcherService(nil, cgrCfg, nil, nil) + cgrCfg.DispatcherSCfg().AttributeSConns = []string{"test"} + var CGREvent *engine.ThresholdProfileWithAPIOpts + var reply *string + result := dspSrv.ReplicatorSv1SetThresholdProfile(CGREvent, reply) + expected := "MANDATORY_IE_MISSING: [ApiKey]" + if result == nil || result.Error() != expected { + t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) + } +}