mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Add tests for attributes
This commit is contained in:
committed by
Dan Christian Bogos
parent
cb2d998e5b
commit
06b73f378d
@@ -1297,3 +1297,168 @@ func TestAttributesParseAttributeSIPCIDInvalidArguments(t *testing.T) {
|
||||
t.Errorf("expected: <%+v>, \nreceived: <%+v>", experr, err)
|
||||
}
|
||||
}
|
||||
|
||||
// func TestAttributesV1ProcessEventMultipleRuns1(t *testing.T) {
|
||||
// tmp := Cache
|
||||
// defer func() {
|
||||
// Cache = tmp
|
||||
// }()
|
||||
|
||||
// cfg := config.NewDefaultCGRConfig()
|
||||
// cfg.AttributeSCfg().IndexedSelects = false
|
||||
// data := NewInternalDB(nil, nil, true)
|
||||
// dm := NewDataManager(data, cfg.CacheCfg(), nil)
|
||||
// filterS := NewFilterS(cfg, nil, dm)
|
||||
// Cache = NewCacheS(cfg, dm, nil)
|
||||
// alS := NewAttributeService(dm, filterS, cfg)
|
||||
|
||||
// postpaid := config.NewRSRParsersMustCompile(utils.MetaPostpaid, utils.InfieldSep)
|
||||
// pw := config.NewRSRParsersMustCompile("CGRateS.org", utils.InfieldSep)
|
||||
|
||||
// ap1 := &AttributeProfile{
|
||||
// Tenant: "cgrates.org",
|
||||
// ID: "ATTR1",
|
||||
// FilterIDs: []string{"*notexists:~*vars.*processedProfileIDs[<~*vars.apTenantID>]:"},
|
||||
// Contexts: []string{utils.MetaSessionS},
|
||||
// Attributes: []*Attribute{
|
||||
// {
|
||||
// Path: "*req.Password",
|
||||
// Type: utils.MetaConstant,
|
||||
// Value: pw,
|
||||
// },
|
||||
// },
|
||||
// Weight: 10,
|
||||
// }
|
||||
// err = alS.dm.SetAttributeProfile(ap1, true)
|
||||
// if err != nil {
|
||||
// t.Error(err)
|
||||
// }
|
||||
|
||||
// ap2 := &AttributeProfile{
|
||||
// Tenant: "cgrates.org",
|
||||
// ID: "ATTR2",
|
||||
// Contexts: []string{utils.MetaAny},
|
||||
// Attributes: []*Attribute{
|
||||
// {
|
||||
// Path: "*req.RequestType",
|
||||
// Type: utils.MetaConstant,
|
||||
// Value: postpaid,
|
||||
// },
|
||||
// },
|
||||
// Weight: 20,
|
||||
// }
|
||||
// err = alS.dm.SetAttributeProfile(ap2, true)
|
||||
// if err != nil {
|
||||
// t.Error(err)
|
||||
// }
|
||||
|
||||
// args := &AttrArgsProcessEvent{
|
||||
// AttributeIDs: []string{"ATTR1", "ATTR2"},
|
||||
// Context: utils.StringPointer(utils.MetaAny),
|
||||
// ProcessRuns: utils.IntPointer(3),
|
||||
// CGREvent: &utils.CGREvent{
|
||||
// Tenant: "cgrates.org",
|
||||
// ID: "AttrProcessEventMultipleRuns",
|
||||
// Event: map[string]interface{}{
|
||||
// utils.Password: "passwd",
|
||||
// },
|
||||
// },
|
||||
// }
|
||||
// reply := &AttrSProcessEventReply{}
|
||||
|
||||
// if err := alS.V1ProcessEvent(args, reply); err != nil {
|
||||
// t.Error(err)
|
||||
// }
|
||||
// fmt.Println(utils.ToJSON(reply))
|
||||
// }
|
||||
|
||||
// func TestAttributesV1ProcessEventMultipleRuns2(t *testing.T) {
|
||||
// tmp := Cache
|
||||
// defer func() {
|
||||
// Cache = tmp
|
||||
// }()
|
||||
|
||||
// cfg := config.NewDefaultCGRConfig()
|
||||
// cfg.AttributeSCfg().IndexedSelects = false
|
||||
// data := NewInternalDB(nil, nil, true)
|
||||
// dm := NewDataManager(data, cfg.CacheCfg(), nil)
|
||||
// filterS := NewFilterS(cfg, nil, dm)
|
||||
// Cache = NewCacheS(cfg, dm, nil)
|
||||
// alS := NewAttributeService(dm, filterS, cfg)
|
||||
|
||||
// postpaid := config.NewRSRParsersMustCompile(utils.MetaPostpaid, utils.InfieldSep)
|
||||
// pw := config.NewRSRParsersMustCompile("CGRateS.org", utils.InfieldSep)
|
||||
// paypal := config.NewRSRParsersMustCompile("cgrates@paypal.com", utils.InfieldSep)
|
||||
|
||||
// ap1 := &AttributeProfile{
|
||||
// Tenant: "cgrates.org",
|
||||
// ID: "ATTR1",
|
||||
// Contexts: []string{utils.MetaAny},
|
||||
// Attributes: []*Attribute{
|
||||
// {
|
||||
// Path: "*req.Password",
|
||||
// Type: utils.MetaConstant,
|
||||
// Value: pw,
|
||||
// },
|
||||
// },
|
||||
// Weight: 10,
|
||||
// }
|
||||
// err = alS.dm.SetAttributeProfile(ap1, true)
|
||||
// if err != nil {
|
||||
// t.Error(err)
|
||||
// }
|
||||
|
||||
// ap2 := &AttributeProfile{
|
||||
// Tenant: "cgrates.org",
|
||||
// ID: "ATTR2",
|
||||
// FilterIDs: []string{"*exists:~*vars.*processedProfileIDs[cgrates.org:ATTR1]:"},
|
||||
// Contexts: []string{utils.MetaAny},
|
||||
// Attributes: []*Attribute{
|
||||
// {
|
||||
// Path: "*req.RequestType",
|
||||
// Type: utils.MetaConstant,
|
||||
// Value: postpaid,
|
||||
// },
|
||||
// },
|
||||
// Weight: 20,
|
||||
// }
|
||||
// err = alS.dm.SetAttributeProfile(ap2, true)
|
||||
// if err != nil {
|
||||
// t.Error(err)
|
||||
// }
|
||||
|
||||
// ap3 := &AttributeProfile{
|
||||
// Tenant: "cgrates.org",
|
||||
// ID: "ATTR3",
|
||||
// FilterIDs: []string{"*exists:~*vars.*processedProfileIDs[cgrates.org:ATTR2]:"},
|
||||
// Contexts: []string{utils.MetaAny},
|
||||
// Attributes: []*Attribute{
|
||||
// {
|
||||
// Path: "*req.PaypalAccount",
|
||||
// Type: utils.MetaConstant,
|
||||
// Value: paypal,
|
||||
// },
|
||||
// },
|
||||
// Weight: 30,
|
||||
// }
|
||||
// err = alS.dm.SetAttributeProfile(ap3, true)
|
||||
// if err != nil {
|
||||
// t.Error(err)
|
||||
// }
|
||||
|
||||
// args := &AttrArgsProcessEvent{
|
||||
// Context: utils.StringPointer(utils.MetaAny),
|
||||
// ProcessRuns: utils.IntPointer(3),
|
||||
// CGREvent: &utils.CGREvent{
|
||||
// Tenant: "cgrates.org",
|
||||
// ID: "AttrProcessEventMultipleRuns",
|
||||
// Event: map[string]interface{}{},
|
||||
// },
|
||||
// }
|
||||
// reply := &AttrSProcessEventReply{}
|
||||
|
||||
// if err := alS.V1ProcessEvent(args, reply); err != nil {
|
||||
// t.Error(err)
|
||||
// }
|
||||
// fmt.Println(utils.ToJSON(reply))
|
||||
// }
|
||||
|
||||
@@ -216,3 +216,31 @@ func TestNewAttributeFromInlineWithMultipleVaslues(t *testing.T) {
|
||||
t.Errorf("Expecting %+v, received: %+v", utils.ToJSON(expAttrPrf1), utils.ToJSON(attr))
|
||||
}
|
||||
}
|
||||
|
||||
func TestLibAttributesTenantIDInLine(t *testing.T) {
|
||||
ap := &AttributeProfile{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "AttrPrf",
|
||||
Contexts: []string{utils.MetaAny},
|
||||
Weight: 10,
|
||||
}
|
||||
|
||||
exp := "cgrates.org:AttrPrf"
|
||||
if rcv := ap.TenantIDInline(); rcv != exp {
|
||||
t.Errorf("expected: <%+v>, \nreceived: <%+v>", exp, rcv)
|
||||
}
|
||||
}
|
||||
|
||||
func TestLibAttributesTenantIDMetaPrefix(t *testing.T) {
|
||||
ap := &AttributeProfile{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "*default",
|
||||
Contexts: []string{utils.MetaAny},
|
||||
Weight: 10,
|
||||
}
|
||||
|
||||
exp := "*default"
|
||||
if rcv := ap.TenantIDInline(); rcv != exp {
|
||||
t.Errorf("expected: <%+v>, \nreceived: <%+v>", exp, rcv)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user