From 7a5396b2cce28b89f1f47459b44ed9a8413ffdb3 Mon Sep 17 00:00:00 2001 From: ionutboangiu Date: Mon, 19 Jul 2021 16:49:11 +0300 Subject: [PATCH] Fix attributes tests --- engine/attributes.go | 2 -- engine/attributes_test.go | 50 ++++++++++++++++++++++----------------- 2 files changed, 28 insertions(+), 24 deletions(-) diff --git a/engine/attributes.go b/engine/attributes.go index a54177c9f..58d6487f2 100644 --- a/engine/attributes.go +++ b/engine/attributes.go @@ -86,7 +86,6 @@ func (alS *AttributeService) attributeProfileForEvent(tnt string, ctx *string, a utils.ConcatenatedKey(tnt, utils.MetaAny), alS.cgrcfg.AttributeSCfg().IndexedSelects, alS.cgrcfg.AttributeSCfg().NestedFields) - if aPrflIDs.Size() == 0 { if err != nil { // return the error if no attribute matched the needed context return nil, err @@ -335,7 +334,6 @@ func (alS *AttributeService) V1ProcessEvent(args *AttrArgsProcessEvent, (eNV[utils.MetaVars].(utils.MapStorage))[utils.OptsAttributesProcessRuns] = i + 1 var evRply *AttrSProcessEventReply evRply, err = alS.processEvent(tnt, args, eNV, dynDP, lastID) - if err != nil { if err != utils.ErrNotFound { err = utils.NewErrServerError(err) diff --git a/engine/attributes_test.go b/engine/attributes_test.go index 3d4aa7541..7b1961669 100644 --- a/engine/attributes_test.go +++ b/engine/attributes_test.go @@ -1318,8 +1318,8 @@ func TestAttributesV1ProcessEventMultipleRuns1(t *testing.T) { ap1 := &AttributeProfile{ Tenant: "cgrates.org", ID: "ATTR1", - FilterIDs: []string{"*notexists:~*vars.*processedProfileIDs[<~*vars.apTenantID>]:"}, - Contexts: []string{utils.MetaSessionS}, + FilterIDs: []string{"*notexists:~*vars.*processedProfileIDs[<~*vars.*apTenantID>]:"}, + Contexts: []string{utils.MetaAny}, Attributes: []*Attribute{ { Path: "*req.Password", @@ -1360,30 +1360,33 @@ func TestAttributesV1ProcessEventMultipleRuns1(t *testing.T) { Tenant: "cgrates.org", ID: "AttrProcessEventMultipleRuns", Event: map[string]interface{}{ - utils.Password: "passwd", + "Password": "passwd", }, }, } reply := &AttrSProcessEventReply{} - // exp := &AttrSProcessEventReply{ - // MatchedProfiles: []string{"cgrates.org:ATTR1", "cgrates.org:ATTR2"}, - // AlteredFields: []string{"*req.Password", "*req.RequestType"}, - // CGREvent: &utils.CGREvent{ - // Tenant: "cgrates.org", - // ID: "AttrProcessEventMultipleRuns", - // Event: map[string]interface{}{ - // utils.Password: "CGRateS.org", - // utils.RequestType: utils.MetaPostpaid, - // }, - // }, - // } + exp := &AttrSProcessEventReply{ + MatchedProfiles: []string{"cgrates.org:ATTR2", "cgrates.org:ATTR1", "cgrates.org:ATTR2"}, + AlteredFields: []string{"*req.Password", "*req.RequestType"}, + CGREvent: &utils.CGREvent{ + Tenant: "cgrates.org", + ID: "AttrProcessEventMultipleRuns", + Event: map[string]interface{}{ + "Password": "CGRateS.org", + utils.RequestType: utils.MetaPostpaid, + }, + APIOpts: make(map[string]interface{}), + }, + } if err := alS.V1ProcessEvent(args, reply); err != nil { t.Error(err) + } else { + sort.Strings(reply.AlteredFields) + if !reflect.DeepEqual(reply, exp) { + t.Errorf("expected: <%+v>, \nreceived: <%+v>", utils.ToJSON(exp), utils.ToJSON(reply)) + } } - // else if !reflect.DeepEqual(reply, exp) { - // t.Errorf("expected: <%+v>, \nreceived: <%+v>", utils.ToJSON(exp), utils.ToJSON(reply)) - // } } func TestAttributesV1ProcessEventMultipleRuns2(t *testing.T) { @@ -1473,7 +1476,7 @@ func TestAttributesV1ProcessEventMultipleRuns2(t *testing.T) { reply := &AttrSProcessEventReply{} exp := &AttrSProcessEventReply{ MatchedProfiles: []string{"cgrates.org:ATTR1", "cgrates.org:ATTR2", "cgrates.org:ATTR3"}, - AlteredFields: []string{"*req.Password", "*req.RequestType", "*req.PaypalAccount"}, + AlteredFields: []string{"*req.Password", "*req.PaypalAccount", "*req.RequestType"}, CGREvent: &utils.CGREvent{ Tenant: "cgrates.org", ID: "AttrProcessEventMultipleRuns", @@ -1487,8 +1490,11 @@ func TestAttributesV1ProcessEventMultipleRuns2(t *testing.T) { } if err := alS.V1ProcessEvent(args, reply); err != nil { t.Error(err) - } else if !reflect.DeepEqual(reply, exp) { - t.Errorf("expected: <%+v>, \nreceived: <%+v>", - utils.ToJSON(exp), utils.ToJSON(reply)) + } else { + sort.Strings(reply.AlteredFields) + if !reflect.DeepEqual(reply, exp) { + t.Errorf("expected: <%+v>, \nreceived: <%+v>", + utils.ToJSON(exp), utils.ToJSON(reply)) + } } }