mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Added more tests for inline attributes
This commit is contained in:
committed by
Dan Christian Bogos
parent
328d6d1fcb
commit
fe6153a230
@@ -666,17 +666,16 @@ func (fltr *FilterRule) passActivationInterval(dDp utils.DataProvider) (bool, er
|
||||
return false, err
|
||||
}
|
||||
return startTime.Before(timeStrVal) && timeStrVal.Before(endTime), nil
|
||||
} else {
|
||||
val1, err := fltr.rsrValues[0].CompileDynRule(dDp)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
startTime, err := utils.ParseTimeDetectLayout(val1, config.CgrConfig().GeneralCfg().DefaultTimezone)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
return startTime.Before(timeStrVal), nil
|
||||
}
|
||||
val1, err := fltr.rsrValues[0].CompileDynRule(dDp)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
startTime, err := utils.ParseTimeDetectLayout(val1, config.CgrConfig().GeneralCfg().DefaultTimezone)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
return startTime.Before(timeStrVal), nil
|
||||
}
|
||||
|
||||
func verifyInlineFilterS(fltrs []string) (err error) {
|
||||
|
||||
@@ -189,3 +189,30 @@ func TestNewAttributeFromInlineWithMultipleRuns2(t *testing.T) {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNewAttributeFromInlineWithMultipleVaslues(t *testing.T) {
|
||||
attrID := "*variable:*req.Category:call_&*req.OriginID;*constant:*req.RequestType:*rated"
|
||||
expAttrPrf1 := &AttributeProfile{
|
||||
Tenant: config.CgrConfig().GeneralCfg().DefaultTenant,
|
||||
ID: attrID,
|
||||
Contexts: []string{utils.MetaAny},
|
||||
Attributes: []*Attribute{
|
||||
{
|
||||
Path: utils.MetaReq + utils.NestingSep + "Category",
|
||||
Type: utils.MetaVariable,
|
||||
Value: config.NewRSRParsersMustCompile("call_;*req.OriginID", utils.InfieldSep),
|
||||
},
|
||||
{
|
||||
Path: utils.MetaReq + utils.NestingSep + "RequestType",
|
||||
Type: utils.MetaConstant,
|
||||
Value: config.NewRSRParsersMustCompile("*rated", utils.InfieldSep),
|
||||
},
|
||||
},
|
||||
}
|
||||
attr, err := NewAttributeFromInline(config.CgrConfig().GeneralCfg().DefaultTenant, attrID)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(expAttrPrf1, attr) {
|
||||
t.Errorf("Expecting %+v, received: %+v", utils.ToJSON(expAttrPrf1), utils.ToJSON(attr))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2340,8 +2340,9 @@ func (tps ChargerMdls) AsTPChargers() (result []*utils.TPChargerProfile) {
|
||||
if tp.AttributeIDs != utils.EmptyString {
|
||||
attributeSplit := strings.Split(tp.AttributeIDs, utils.InfieldSep)
|
||||
var inlineAttribute string
|
||||
var dynam bool
|
||||
for _, attribute := range attributeSplit {
|
||||
if !strings.HasPrefix(attribute, utils.Meta) {
|
||||
if !dynam && !strings.HasPrefix(attribute, utils.Meta) {
|
||||
if inlineAttribute != utils.EmptyString {
|
||||
attributeMap[tntID] = append(attributeMap[tntID], inlineAttribute[1:])
|
||||
inlineAttribute = utils.EmptyString
|
||||
@@ -2349,6 +2350,11 @@ func (tps ChargerMdls) AsTPChargers() (result []*utils.TPChargerProfile) {
|
||||
attributeMap[tntID] = append(attributeMap[tntID], attribute)
|
||||
continue
|
||||
}
|
||||
if dynam {
|
||||
dynam = !strings.Contains(attribute, string(utils.RSRDynEndChar))
|
||||
} else {
|
||||
dynam = strings.Contains(attribute, string(utils.RSRDynStartChar))
|
||||
}
|
||||
inlineAttribute += utils.InfieldSep + attribute
|
||||
}
|
||||
if inlineAttribute != utils.EmptyString {
|
||||
|
||||
@@ -3550,7 +3550,7 @@ func TestModelAsTPChargers3(t *testing.T) {
|
||||
ID: "Charger1",
|
||||
FilterIDs: "FLTR_ACNT_dan;FLTR_DST_DE",
|
||||
RunID: "*rated",
|
||||
AttributeIDs: "*constant:*req.RequestType:*rated;*constant:*req.Category:call;ATTR1;*constant:*req.Category:call",
|
||||
AttributeIDs: "*constant:*req.RequestType:*rated;*constant:*req.Category:call;ATTR1;*constant:*req.Category:call&<~*req.OriginID;_suf>",
|
||||
ActivationInterval: "2014-07-14T14:35:00Z;2014-07-15T14:35:00Z",
|
||||
Weight: 20,
|
||||
},
|
||||
@@ -3565,7 +3565,7 @@ func TestModelAsTPChargers3(t *testing.T) {
|
||||
ActivationTime: "2014-07-14T14:35:00Z",
|
||||
ExpiryTime: "2014-07-15T14:35:00Z",
|
||||
},
|
||||
AttributeIDs: []string{"*constant:*req.RequestType:*rated;*constant:*req.Category:call", "ATTR1", "*constant:*req.Category:call"},
|
||||
AttributeIDs: []string{"*constant:*req.RequestType:*rated;*constant:*req.Category:call", "ATTR1", "*constant:*req.Category:call&<~*req.OriginID;_suf>"},
|
||||
Weight: 20,
|
||||
}
|
||||
rcv := models.AsTPChargers()
|
||||
|
||||
Reference in New Issue
Block a user