From bb0f2602d286bc82034b8a3c6906436158ade5ce Mon Sep 17 00:00:00 2001 From: TeoV Date: Fri, 24 Jul 2020 16:13:20 +0300 Subject: [PATCH] Make Attributes optional in case of Chargers --- apier/v1/chargers_it_test.go | 54 ++++++++++++++++++++++++++++++++++++ engine/chargers.go | 5 +++- 2 files changed, 58 insertions(+), 1 deletion(-) diff --git a/apier/v1/chargers_it_test.go b/apier/v1/chargers_it_test.go index adc97912f..f323777ee 100755 --- a/apier/v1/chargers_it_test.go +++ b/apier/v1/chargers_it_test.go @@ -87,6 +87,7 @@ var ( testChargerSUpdateChargerProfile, testChargerSRemChargerProfile, testChargerSPing, + testChargerSProcessWithNotFoundAttribute, testChargerSKillEngine, } ) @@ -400,6 +401,59 @@ func testChargerSPing(t *testing.T) { } } +func testChargerSProcessWithNotFoundAttribute(t *testing.T) { + var result string + chargerProfile = &ChargerWithCache{ + ChargerProfile: &engine.ChargerProfile{ + Tenant: "cgrates.org", + ID: "ChargerWithoutAttribute", + FilterIDs: []string{"*string:~*req.CustomField:WithoutAttributes"}, + ActivationInterval: &utils.ActivationInterval{ + ActivationTime: time.Date(2014, 7, 29, 15, 0, 0, 0, time.UTC), + }, + RunID: "CustomRun", + Weight: 20, + }, + } + + if err := chargerRPC.Call(utils.APIerSv1SetChargerProfile, chargerProfile, &result); err != nil { + t.Error(err) + } else if result != utils.OK { + t.Error("Unexpected reply returned", result) + } + + ev := &utils.CGREvent{ + Tenant: "cgrates.org", + ID: "CustomEvent", + Event: map[string]interface{}{ + utils.Account: "Random", + "CustomField": "WithoutAttributes", + }, + } + processedEv := []*engine.ChrgSProcessEventReply{ + { + ChargerSProfile: "ChargerWithoutAttribute", + AttributeSProfiles: []string{}, + AlteredFields: []string{utils.MetaReqRunID}, + CGREvent: &utils.CGREvent{ // matching ChargerWithoutAttribute + Tenant: "cgrates.org", + ID: "CustomEvent", + Event: map[string]interface{}{ + utils.Account: "Random", + "CustomField": "WithoutAttributes", + "RunID": "CustomRun", + }, + }, + }, + } + var rply []*engine.ChrgSProcessEventReply + if err := chargerRPC.Call(utils.ChargerSv1ProcessEvent, ev, &rply); err != nil { + t.Error(err) + } else if !reflect.DeepEqual(rply, processedEv) { + t.Errorf("Expecting : %+v, received: %+v", processedEv, rply) + } + +} func testChargerSKillEngine(t *testing.T) { if err := engine.KillEngine(100); err != nil { t.Error(err) diff --git a/engine/chargers.go b/engine/chargers.go index f564a658d..8b38ce4f0 100644 --- a/engine/chargers.go +++ b/engine/chargers.go @@ -148,7 +148,10 @@ func (cS *ChargerService) processEvent(cgrEv *utils.CGREventWithOpts) (rply []*C var evReply AttrSProcessEventReply if err = cS.connMgr.Call(cS.cfg.ChargerSCfg().AttributeSConns, nil, utils.AttributeSv1ProcessEvent, args, &evReply); err != nil { - return nil, err + if err.Error() != utils.ErrNotFound.Error() { + return nil, err + } + err = nil } rply[i].AttributeSProfiles = evReply.MatchedProfiles if len(evReply.AlteredFields) != 0 {