Make Attributes optional in case of Chargers

This commit is contained in:
TeoV
2020-07-24 16:13:20 +03:00
committed by Dan Christian Bogos
parent 76aa0c8371
commit bb0f2602d2
2 changed files with 58 additions and 1 deletions

View File

@@ -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)

View File

@@ -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 {