Fix attributes tests

This commit is contained in:
ionutboangiu
2021-07-19 16:49:11 +03:00
committed by Dan Christian Bogos
parent 1db0390b16
commit 7a5396b2cc
2 changed files with 28 additions and 24 deletions

View File

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

View File

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