mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-16 21:59:53 +05:00
Test for cdrs Processevent
This commit is contained in:
committed by
Dan Christian Bogos
parent
4236ace70d
commit
9ed3888fd2
@@ -1206,3 +1206,147 @@ func TestCDRsEESProcessEventMock(t *testing.T) {
|
||||
t.Errorf("\nExpected <%+v> \n,received <%+v>", expected, cgrEv)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCDRsProcessEventMock(t *testing.T) {
|
||||
testCache := Cache
|
||||
tmpC := config.CgrConfig()
|
||||
tmpCM := connMgr
|
||||
defer func() {
|
||||
Cache = testCache
|
||||
config.SetCgrConfig(tmpC)
|
||||
connMgr = tmpCM
|
||||
}()
|
||||
|
||||
var sent StorDB
|
||||
cfg := config.NewDefaultCGRConfig()
|
||||
cfg.CdrsCfg().EEsConns = []string{utils.ConcatenatedKey(utils.MetaInternal,
|
||||
utils.MetaEEs)}
|
||||
storDBChan := make(chan StorDB, 1)
|
||||
storDBChan <- sent
|
||||
data := NewInternalDB(nil, nil, true)
|
||||
connMng := NewConnManager(cfg)
|
||||
dm := NewDataManager(data, cfg.CacheCfg(), nil)
|
||||
fltrs := NewFilterS(cfg, nil, dm)
|
||||
Cache = NewCacheS(cfg, dm, nil)
|
||||
newCDRSrv := NewCDRServer(cfg, storDBChan, dm, fltrs, connMng)
|
||||
ccM := &ccMock{
|
||||
calls: map[string]func(ctx *context.Context, args interface{}, reply interface{}) error{
|
||||
utils.EeSv1ProcessEvent: func(ctx *context.Context, args, reply interface{}) error {
|
||||
*reply.(*map[string]map[string]interface{}) = map[string]map[string]interface{}{}
|
||||
return utils.ErrNotFound
|
||||
},
|
||||
},
|
||||
}
|
||||
rpcInternal := make(chan birpc.ClientConnector, 1)
|
||||
rpcInternal <- ccM
|
||||
newCDRSrv.connMgr.AddInternalConn(utils.ConcatenatedKey(utils.MetaInternal,
|
||||
utils.MetaEEs), utils.ThresholdSv1, rpcInternal)
|
||||
|
||||
cgrEv := &utils.CGREvent{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "testID",
|
||||
Event: map[string]interface{}{
|
||||
"Resources": "ResourceProfile1",
|
||||
utils.AnswerTime: time.Date(2014, 7, 14, 14, 30, 0, 0, time.UTC),
|
||||
"UsageInterval": "1s",
|
||||
"PddInterval": "1s",
|
||||
utils.Weight: "20.0",
|
||||
utils.Usage: 135 * time.Second,
|
||||
utils.Cost: 123.0,
|
||||
},
|
||||
APIOpts: nil,
|
||||
}
|
||||
_, err := newCDRSrv.processEvent(context.Background(), cgrEv)
|
||||
if err != nil {
|
||||
t.Errorf("\nExpected <%+v> \n, received <%+v>", nil, err)
|
||||
}
|
||||
expected := &utils.CGREvent{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "testID",
|
||||
Event: map[string]interface{}{
|
||||
"Resources": "ResourceProfile1",
|
||||
utils.AnswerTime: time.Date(2014, 7, 14, 14, 30, 0, 0, time.UTC),
|
||||
"UsageInterval": "1s",
|
||||
"PddInterval": "1s",
|
||||
utils.Weight: "20.0",
|
||||
utils.Usage: 135 * time.Second,
|
||||
utils.Cost: 123.0,
|
||||
},
|
||||
APIOpts: nil,
|
||||
}
|
||||
if !reflect.DeepEqual(expected, cgrEv) {
|
||||
t.Errorf("\nExpected <%+v> \n,received <%+v>", expected, cgrEv)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCDRsProcessEventMockStats(t *testing.T) {
|
||||
testCache := Cache
|
||||
tmpC := config.CgrConfig()
|
||||
tmpCM := connMgr
|
||||
defer func() {
|
||||
Cache = testCache
|
||||
config.SetCgrConfig(tmpC)
|
||||
connMgr = tmpCM
|
||||
}()
|
||||
|
||||
var sent StorDB
|
||||
cfg := config.NewDefaultCGRConfig()
|
||||
cfg.CdrsCfg().EEsConns = []string{utils.ConcatenatedKey(utils.MetaInternal,
|
||||
utils.MetaEEs)}
|
||||
storDBChan := make(chan StorDB, 1)
|
||||
storDBChan <- sent
|
||||
data := NewInternalDB(nil, nil, true)
|
||||
connMng := NewConnManager(cfg)
|
||||
dm := NewDataManager(data, cfg.CacheCfg(), nil)
|
||||
fltrs := NewFilterS(cfg, nil, dm)
|
||||
Cache = NewCacheS(cfg, dm, nil)
|
||||
newCDRSrv := NewCDRServer(cfg, storDBChan, dm, fltrs, connMng)
|
||||
ccM := &ccMock{
|
||||
calls: map[string]func(ctx *context.Context, args interface{}, reply interface{}) error{
|
||||
utils.EeSv1ProcessEvent: func(ctx *context.Context, args, reply interface{}) error {
|
||||
*reply.(*map[string]map[string]interface{}) = map[string]map[string]interface{}{}
|
||||
return utils.ErrNotFound
|
||||
},
|
||||
},
|
||||
}
|
||||
rpcInternal := make(chan birpc.ClientConnector, 1)
|
||||
rpcInternal <- ccM
|
||||
newCDRSrv.connMgr.AddInternalConn(utils.ConcatenatedKey(utils.MetaInternal,
|
||||
utils.MetaEEs), utils.ThresholdSv1, rpcInternal)
|
||||
|
||||
cgrEv := &utils.CGREvent{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "testID",
|
||||
Event: map[string]interface{}{
|
||||
"Resources": "ResourceProfile1",
|
||||
utils.AnswerTime: time.Date(2014, 7, 14, 14, 30, 0, 0, time.UTC),
|
||||
"UsageInterval": "1s",
|
||||
"PddInterval": "1s",
|
||||
utils.Weight: "20.0",
|
||||
utils.Usage: 135 * time.Second,
|
||||
utils.Cost: 123.0,
|
||||
},
|
||||
APIOpts: nil,
|
||||
}
|
||||
_, err := newCDRSrv.processEvent(context.Background(), cgrEv)
|
||||
if err != nil {
|
||||
t.Errorf("\nExpected <%+v> \n, received <%+v>", nil, err)
|
||||
}
|
||||
expected := &utils.CGREvent{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "testID",
|
||||
Event: map[string]interface{}{
|
||||
"Resources": "ResourceProfile1",
|
||||
utils.AnswerTime: time.Date(2014, 7, 14, 14, 30, 0, 0, time.UTC),
|
||||
"UsageInterval": "1s",
|
||||
"PddInterval": "1s",
|
||||
utils.Weight: "20.0",
|
||||
utils.Usage: 135 * time.Second,
|
||||
utils.Cost: 123.0,
|
||||
},
|
||||
APIOpts: nil,
|
||||
}
|
||||
if !reflect.DeepEqual(expected, cgrEv) {
|
||||
t.Errorf("\nExpected <%+v> \n,received <%+v>", expected, cgrEv)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user