diff --git a/dispatchers/attributes_it_test.go b/dispatchers/attributes_it_test.go index 63ee7e462..7c1260bdd 100644 --- a/dispatchers/attributes_it_test.go +++ b/dispatchers/attributes_it_test.go @@ -23,6 +23,7 @@ package dispatchers import ( "reflect" "testing" + "time" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" @@ -702,3 +703,75 @@ func TestDspAttributeSv1PingErrorAttributeSConns(t *testing.T) { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, err) } } + +func TestDspAttributeSv1GetAttributeForEventError(t *testing.T) { + cgrCfg := config.NewDefaultCGRConfig() + cgrCfg.DispatcherSCfg().AttributeSConns = []string{"test"} + dspSrv := NewDispatcherService(nil, cgrCfg, nil, nil) + processEvent := &engine.AttrArgsProcessEvent{ + AttributeIDs: nil, + Context: nil, + ProcessRuns: nil, + CGREvent: &utils.CGREvent{ + Tenant: "", + ID: "", + Time: &time.Time{}, + Event: nil, + APIOpts: nil, + }, + } + var reply *engine.AttributeProfile + err := dspSrv.AttributeSv1GetAttributeForEvent(processEvent, reply) + expected := "MANDATORY_IE_MISSING: [ApiKey]" + if err == nil || err.Error() != expected { + t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, err) + } +} + +func TestDspAttributeSv1GetAttributeForEventErrorTenant(t *testing.T) { + cgrCfg := config.NewDefaultCGRConfig() + cgrCfg.DispatcherSCfg().AttributeSConns = []string{"test"} + dspSrv := NewDispatcherService(nil, cgrCfg, nil, nil) + processEvent := &engine.AttrArgsProcessEvent{ + AttributeIDs: nil, + Context: nil, + ProcessRuns: nil, + CGREvent: &utils.CGREvent{ + Tenant: "tenant", + ID: "", + Time: &time.Time{}, + Event: nil, + APIOpts: nil, + }, + } + var reply *engine.AttributeProfile + err := dspSrv.AttributeSv1GetAttributeForEvent(processEvent, reply) + expected := "MANDATORY_IE_MISSING: [ApiKey]" + if err == nil || err.Error() != expected { + t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, err) + } +} + +func TestDspAttributeSv1GetAttributeForEventErrorAttributeS(t *testing.T) { + cgrCfg := config.NewDefaultCGRConfig() + dspSrv := NewDispatcherService(nil, cgrCfg, nil, nil) + processEvent := &engine.AttrArgsProcessEvent{ + AttributeIDs: nil, + Context: nil, + ProcessRuns: nil, + CGREvent: &utils.CGREvent{ + Tenant: "tenant", + ID: "", + Time: &time.Time{}, + Event: nil, + APIOpts: nil, + }, + } + + var reply *engine.AttributeProfile + err := dspSrv.AttributeSv1GetAttributeForEvent(processEvent, reply) + expected := "DISPATCHER_ERROR:NOT_FOUND" + if err == nil || err.Error() != expected { + t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, err) + } +}