mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Added tests for in-line attributes
This commit is contained in:
@@ -1821,3 +1821,33 @@ func BenchmarkAttributeProcessEventVariable(b *testing.B) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetAttributeProfileFromInline(t *testing.T) {
|
||||
//refresh the DM
|
||||
if err := dmAtr.DataDB().Flush(""); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
Cache.Clear(nil)
|
||||
if test, err := dmAtr.DataDB().IsDBEmpty(); err != nil {
|
||||
t.Error(err)
|
||||
} else if test != true {
|
||||
t.Errorf("\nExpecting: true got :%+v", test)
|
||||
}
|
||||
attrID := "*sum:Field2:10;~NumField;20"
|
||||
expAttrPrf1 := &AttributeProfile{
|
||||
Tenant: config.CgrConfig().GeneralCfg().DefaultTenant,
|
||||
ID: attrID,
|
||||
Contexts: []string{utils.META_ANY},
|
||||
Attributes: []*Attribute{&Attribute{
|
||||
FieldName: "Field2",
|
||||
Type: utils.MetaSum,
|
||||
Value: config.NewRSRParsersMustCompile("10;~NumField;20", true, utils.INFIELD_SEP),
|
||||
}},
|
||||
}
|
||||
attr, err := dm.GetAttributeProfile(config.CgrConfig().GeneralCfg().DefaultTenant, attrID, false, false, "")
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(expAttrPrf1, attr) {
|
||||
t.Errorf("Expecting %+v, received: %+v", utils.ToJSON(expAttrPrf1), utils.ToJSON(attr))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -120,3 +120,23 @@ func TestConvertExternalToProfileMissing2(t *testing.T) {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestNewAttributeFromInline(t *testing.T) {
|
||||
attrID := "*sum:Field2:10;~NumField;20"
|
||||
expAttrPrf1 := &AttributeProfile{
|
||||
Tenant: config.CgrConfig().GeneralCfg().DefaultTenant,
|
||||
ID: attrID,
|
||||
Contexts: []string{utils.META_ANY},
|
||||
Attributes: []*Attribute{&Attribute{
|
||||
FieldName: "Field2",
|
||||
Type: utils.MetaSum,
|
||||
Value: config.NewRSRParsersMustCompile("10;~NumField;20", true, utils.INFIELD_SEP),
|
||||
}},
|
||||
}
|
||||
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))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user