mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-16 13:49:53 +05:00
Fix failing tests
This commit is contained in:
committed by
Dan Christian Bogos
parent
c0fbac32fc
commit
6062cdda21
@@ -387,7 +387,7 @@ func testAttributeSetAttributeProfileBrokenReference(t *testing.T) {
|
||||
func testAttributeSGetAttributeForEventMissingEvent(t *testing.T) {
|
||||
var rplyEv engine.AttrSProcessEventReply
|
||||
if err := attrSRPC.Call(context.Background(), utils.AttributeSv1ProcessEvent,
|
||||
&utils.CGREvent{}, &rplyEv); err == nil ||
|
||||
nil, &rplyEv); err == nil ||
|
||||
err.Error() != "MANDATORY_IE_MISSING: [CGREvent]" {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
@@ -154,7 +154,9 @@ func testCfgGetConfig(t *testing.T) {
|
||||
"stats_conns": []string{"*localhost"},
|
||||
"suffix_indexed_fields": []string{},
|
||||
utils.OptsCfg: map[string]interface{}{
|
||||
utils.MetaProcessRunsCfg: 1,
|
||||
utils.MetaAttributeIDsCfg: []string(nil),
|
||||
utils.MetaProcessRunsCfg: 1,
|
||||
utils.MetaProfileRunsCfg: 0,
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -213,7 +215,9 @@ func testCfgSetGetConfig(t *testing.T) {
|
||||
"stats_conns": []string{"*internal"},
|
||||
"suffix_indexed_fields": []string{},
|
||||
utils.OptsCfg: map[string]interface{}{
|
||||
utils.MetaProcessRunsCfg: 2,
|
||||
utils.MetaAttributeIDsCfg: []string(nil),
|
||||
utils.MetaProcessRunsCfg: 2,
|
||||
utils.MetaProfileRunsCfg: 0,
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -311,7 +315,7 @@ func testCfgSetJSONGetJSONConfig(t *testing.T) {
|
||||
if !reflect.DeepEqual(`"OK"`, utils.ToJSON(reply)) {
|
||||
t.Errorf("\nExpected <%+v>, \nReceived <%+v>", "OK", utils.ToJSON(reply))
|
||||
}
|
||||
expectedGet := "{\"attributes\":{\"accounts_conns\":[\"*internal\"],\"opts\":{\"*processRuns\":2},\"enabled\":true,\"indexed_selects\":false,\"nested_fields\":false,\"prefix_indexed_fields\":[],\"resources_conns\":[\"*internal\"],\"stats_conns\":[\"*localhost\"],\"suffix_indexed_fields\":[]}}"
|
||||
expectedGet := "{\"attributes\":{\"accounts_conns\":[\"*internal\"],\"enabled\":true,\"indexed_selects\":false,\"nested_fields\":false,\"opts\":{\"*attributeIDs\":null,\"*processRuns\":2,\"*profileRuns\":0},\"prefix_indexed_fields\":[],\"resources_conns\":[\"*internal\"],\"stats_conns\":[\"*localhost\"],\"suffix_indexed_fields\":[]}}"
|
||||
var replyGet string
|
||||
if err := cfgRPC.Call(context.Background(), utils.ConfigSv1GetConfigAsJSON,
|
||||
&config.SectionWithAPIOpts{
|
||||
@@ -478,7 +482,9 @@ func testCfgSetGetConfigStore(t *testing.T) {
|
||||
"stats_conns": []string{"*internal"},
|
||||
"suffix_indexed_fields": []string{},
|
||||
utils.OptsCfg: map[string]interface{}{
|
||||
utils.MetaProcessRunsCfg: 2,
|
||||
utils.MetaAttributeIDsCfg: []string(nil),
|
||||
utils.MetaProcessRunsCfg: 2,
|
||||
utils.MetaProfileRunsCfg: 0,
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -572,7 +578,9 @@ func testCfgGetAfterReloadStore(t *testing.T) {
|
||||
"stats_conns": []string{"*internal"},
|
||||
"suffix_indexed_fields": []string{},
|
||||
utils.OptsCfg: map[string]interface{}{
|
||||
utils.MetaProcessRunsCfg: 2,
|
||||
utils.MetaAttributeIDsCfg: []string(nil),
|
||||
utils.MetaProcessRunsCfg: 2,
|
||||
utils.MetaProfileRunsCfg: 0,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
@@ -98,8 +98,7 @@ func TestConfigSetGetReloadConfig(t *testing.T) {
|
||||
}
|
||||
rlcCfg := NewConfigSv1(cfg)
|
||||
args := &config.SetConfigArgs{
|
||||
APIOpts: nil,
|
||||
Tenant: utils.CGRateSorg,
|
||||
Tenant: utils.CGRateSorg,
|
||||
Config: map[string]interface{}{
|
||||
"attributes": map[string]interface{}{
|
||||
"accounts_conns": []string{"*internal"},
|
||||
@@ -123,7 +122,7 @@ func TestConfigSetGetReloadConfig(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Errorf("Expected <%+v>, \nReceived <%+v>", nil, err)
|
||||
}
|
||||
if !reflect.DeepEqual(expected, reply) {
|
||||
if expected != reply {
|
||||
t.Errorf("Expected <%+v>, \nReceived <%+v>", expected, reply)
|
||||
}
|
||||
argsGet := &config.SectionWithAPIOpts{
|
||||
@@ -143,7 +142,7 @@ func TestConfigSetGetReloadConfig(t *testing.T) {
|
||||
"suffix_indexed_fields": []string{},
|
||||
utils.OptsCfg: map[string]interface{}{
|
||||
utils.MetaAttributeIDsCfg: []string(nil),
|
||||
utils.MetaProcessRunsCfg: 2,
|
||||
utils.MetaProcessRunsCfg: 1,
|
||||
utils.MetaProfileRunsCfg: 0,
|
||||
},
|
||||
},
|
||||
@@ -186,7 +185,7 @@ func TestConfigSetGetReloadConfig(t *testing.T) {
|
||||
"suffix_indexed_fields": []string{},
|
||||
utils.OptsCfg: map[string]interface{}{
|
||||
utils.MetaAttributeIDsCfg: []string(nil),
|
||||
utils.MetaProcessRunsCfg: 2,
|
||||
utils.MetaProcessRunsCfg: 1,
|
||||
utils.MetaProfileRunsCfg: 0,
|
||||
},
|
||||
},
|
||||
@@ -231,7 +230,7 @@ func TestConfigGetSetConfigFromJSONErr(t *testing.T) {
|
||||
}
|
||||
var replyGet string
|
||||
errGet := rlcCfg.GetConfigAsJSON(context.Background(), argsGet, &replyGet)
|
||||
expectedGet := `{"attributes":{"accounts_conns":["*localhost"],"enabled":true,"indexed_selects":true,"nested_fields":false,"opts":{"*processRuns":2},"prefix_indexed_fields":[],"profile_runs":0,"resources_conns":["*localhost"],"stats_conns":["*localhost"],"suffix_indexed_fields":[]}}`
|
||||
expectedGet := `{"attributes":{"accounts_conns":["*localhost"],"enabled":true,"indexed_selects":true,"nested_fields":false,"opts":{"*attributeIDs":null,"*processRuns":1,"*profileRuns":0},"prefix_indexed_fields":[],"resources_conns":["*localhost"],"stats_conns":["*localhost"],"suffix_indexed_fields":[]}}`
|
||||
if err != nil {
|
||||
t.Errorf("Expected <%+v>, \nReceived <%+v>", nil, errGet)
|
||||
}
|
||||
|
||||
@@ -234,8 +234,9 @@ func TestChargersprocessEventCallErr(t *testing.T) {
|
||||
"RunID": utils.MetaDefault,
|
||||
},
|
||||
APIOpts: map[string]interface{}{
|
||||
utils.Subsys: utils.MetaChargers,
|
||||
utils.OptsContext: utils.MetaChargers,
|
||||
utils.OptsAttributesAttributeIDs: []string(nil),
|
||||
utils.Subsys: utils.MetaChargers,
|
||||
utils.OptsContext: utils.MetaChargers,
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
@@ -1563,14 +1563,13 @@ func (sS *SessionS) BiRPCv1AuthorizeEvent(ctx *context.Context,
|
||||
|
||||
if args.GetAttributes ||
|
||||
utils.OptAsBool(args.APIOpts, utils.OptsSesAttributeS) {
|
||||
var atrsIDs []string
|
||||
if atrsIDs, err = utils.OptAsStringSlice(args.APIOpts, utils.OptsSesAttributeIDs); err != nil {
|
||||
return
|
||||
if args.APIOpts == nil {
|
||||
args.APIOpts = make(map[string]interface{})
|
||||
}
|
||||
if atrsIDs == nil {
|
||||
atrsIDs = args.AttributeIDs
|
||||
if args.AttributeIDs != nil {
|
||||
args.APIOpts[utils.OptsAttributesAttributeIDs] = args.AttributeIDs
|
||||
}
|
||||
rplyAttr, err := sS.processAttributes(ctx, args.CGREvent, atrsIDs)
|
||||
rplyAttr, err := sS.processAttributes(ctx, args.CGREvent)
|
||||
if err == nil {
|
||||
args.CGREvent = rplyAttr.CGREvent
|
||||
authReply.Attributes = &rplyAttr
|
||||
@@ -1752,11 +1751,7 @@ func (sS *SessionS) BiRPCv1InitiateSession(ctx *context.Context,
|
||||
}
|
||||
originID, _ := args.FieldAsString(utils.OriginID)
|
||||
if attrS {
|
||||
var atrsIDs []string
|
||||
if atrsIDs, err = utils.OptAsStringSlice(args.APIOpts, utils.OptsSesAttributeIDs); err != nil {
|
||||
return
|
||||
}
|
||||
rplyAttr, err := sS.processAttributes(ctx, args, atrsIDs)
|
||||
rplyAttr, err := sS.processAttributes(ctx, args)
|
||||
if err == nil {
|
||||
args = rplyAttr.CGREvent
|
||||
rply.Attributes = &rplyAttr
|
||||
@@ -1923,11 +1918,7 @@ func (sS *SessionS) BiRPCv1UpdateSession(ctx *context.Context,
|
||||
}
|
||||
|
||||
if attrS {
|
||||
var atrsIDs []string
|
||||
if atrsIDs, err = utils.OptAsStringSlice(args.APIOpts, utils.OptsSesAttributeIDs); err != nil {
|
||||
return
|
||||
}
|
||||
rplyAttr, err := sS.processAttributes(ctx, args, atrsIDs)
|
||||
rplyAttr, err := sS.processAttributes(ctx, args)
|
||||
if err == nil {
|
||||
args = rplyAttr.CGREvent
|
||||
rply.Attributes = &rplyAttr
|
||||
@@ -2190,11 +2181,7 @@ func (sS *SessionS) BiRPCv1ProcessMessage(ctx *context.Context,
|
||||
originID := me.GetStringIgnoreErrors(utils.OriginID)
|
||||
|
||||
if utils.OptAsBool(args.APIOpts, utils.OptsSesAttributeS) {
|
||||
var atrsIDs []string
|
||||
if atrsIDs, err = utils.OptAsStringSlice(args.APIOpts, utils.OptsSesAttributeIDs); err != nil {
|
||||
return
|
||||
}
|
||||
rplyAttr, err := sS.processAttributes(ctx, args, atrsIDs)
|
||||
rplyAttr, err := sS.processAttributes(ctx, args)
|
||||
if err == nil {
|
||||
args = rplyAttr.CGREvent
|
||||
rply.Attributes = &rplyAttr
|
||||
@@ -2324,14 +2311,10 @@ func (sS *SessionS) BiRPCv1ProcessEvent(ctx *context.Context,
|
||||
|
||||
// check for *attribute
|
||||
if utils.OptAsBool(args.APIOpts, utils.OptsSesAttributeS) {
|
||||
var attrIDs []string
|
||||
if attrIDs, err = utils.OptAsStringSlice(args.APIOpts, utils.OptsSesAttributeIDs); err != nil {
|
||||
return
|
||||
}
|
||||
rply.Attributes = make(map[string]*engine.AttrSProcessEventReply)
|
||||
|
||||
for runID, cgrEv := range getDerivedEvents(events, utils.OptAsBool(args.APIOpts, utils.OptsSesAttributeSDerivedReply)) {
|
||||
rplyAttr, err := sS.processAttributes(ctx, cgrEv, attrIDs)
|
||||
rplyAttr, err := sS.processAttributes(ctx, cgrEv)
|
||||
if err != nil {
|
||||
if err.Error() != utils.ErrNotFound.Error() {
|
||||
return utils.NewErrAttributeS(err)
|
||||
@@ -2883,15 +2866,13 @@ func (sS *SessionS) getRoutes(ctx *context.Context, cgrEv *utils.CGREvent) (rout
|
||||
}
|
||||
|
||||
// processAttributes will receive the event and send it to AttributeS to be processed
|
||||
func (sS *SessionS) processAttributes(ctx *context.Context, cgrEv *utils.CGREvent,
|
||||
attrIDs []string) (rplyEv engine.AttrSProcessEventReply, err error) {
|
||||
func (sS *SessionS) processAttributes(ctx *context.Context, cgrEv *utils.CGREvent) (rplyEv engine.AttrSProcessEventReply, err error) {
|
||||
if len(sS.cgrCfg.SessionSCfg().AttrSConns) == 0 {
|
||||
return rplyEv, utils.NewErrNotConnected(utils.AttributeS)
|
||||
}
|
||||
if cgrEv.APIOpts == nil {
|
||||
cgrEv.APIOpts = make(engine.MapEvent)
|
||||
}
|
||||
cgrEv.APIOpts[utils.OptsAttributesAttributeIDs] = attrIDs
|
||||
cgrEv.APIOpts[utils.Subsys] = utils.MetaSessionS
|
||||
cgrEv.APIOpts[utils.OptsContext] = utils.FirstNonEmpty(
|
||||
utils.IfaceAsString(cgrEv.APIOpts[utils.OptsContext]),
|
||||
|
||||
Reference in New Issue
Block a user