Added unit tests for dispatchers

This commit is contained in:
gezimbll
2023-08-02 10:59:57 -04:00
committed by Dan Christian Bogos
parent 763310e46c
commit ebd4ae3b6d
2 changed files with 130 additions and 1 deletions

View File

@@ -496,6 +496,7 @@ func TestDspCacheSv1GetItemWithRemote(t *testing.T) {
"Opt": "Disp",
},
}
if err := dm.SetDispatcherProfile(&engine.DispatcherProfile{
Tenant: "cgrates.org",
ID: "DSP_Test1",
@@ -515,7 +516,46 @@ func TestDspCacheSv1GetItemWithRemote(t *testing.T) {
t.Error(err)
}
var reply any
if err := dsp.CacheSv1GetItemWithRemote(args, &reply); err == nil { //not finished
if err := dsp.CacheSv1GetItemWithRemote(args, &reply); err == nil {
t.Error(err)
}
}
func TestDspCacheSv1GetItem(t *testing.T) {
cfg := config.NewDefaultCGRConfig()
dm := engine.NewDataManager(engine.NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items), cfg.CacheCfg(), nil)
dsp := NewDispatcherService(dm, cfg, engine.NewFilterS(cfg, nil, dm), nil)
args := &utils.ArgsGetCacheItemWithAPIOpts{
Tenant: "cgrates.org",
ArgsGetCacheItem: utils.ArgsGetCacheItem{
CacheID: utils.CacheChargerProfiles,
ItemID: "cgrates.org:DISP1 ",
},
APIOpts: map[string]any{
"Opt": "Disp",
},
}
if err := dm.SetDispatcherProfile(&engine.DispatcherProfile{
Tenant: "cgrates.org",
ID: "DSP_Test1",
FilterIDs: []string{"*string:~*opts.Opt:Disp"},
Strategy: utils.MetaRoundRobin,
Subsystems: []string{utils.MetaAny},
Hosts: engine.DispatcherHostProfiles{
&engine.DispatcherHostProfile{
ID: "ALL2",
FilterIDs: []string{},
Weight: 20,
Params: make(map[string]any),
},
},
Weight: 20,
}, true); err != nil {
t.Error(err)
}
var reply any
if err := dsp.CacheSv1GetItem(args, &reply); err == nil {
t.Error(err)
}
}

View File

@@ -294,3 +294,92 @@ func TestDspResponderShutdownErrorNil(t *testing.T) {
t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result)
}
}
func TestDspResponderGetCostOnRatingPlans(t *testing.T) {
cfg := config.NewDefaultCGRConfig()
dm := engine.NewDataManager(engine.NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items), cfg.CacheCfg(), nil)
dsp := NewDispatcherService(dm, cfg, nil, nil)
args := &utils.GetCostOnRatingPlansArgs{
Account: "1002",
RatingPlanIDs: []string{
"RP1",
"RP2",
},
Subject: "1002",
Destination: "1001",
Usage: 2 * time.Minute,
Tenant: "cgrates.org",
}
if err := dm.SetDispatcherHost(&engine.DispatcherHost{
Tenant: "cgrates.org",
RemoteHost: &config.RemoteHost{
ID: "ALL2",
},
}); err != nil {
t.Error(err)
}
if err := dm.SetDispatcherProfile(&engine.DispatcherProfile{
Tenant: "cgrates.org",
ID: "DSP_Test1",
FilterIDs: []string{},
Strategy: utils.MetaRoundRobin,
Subsystems: []string{utils.MetaAny},
Hosts: engine.DispatcherHostProfiles{
&engine.DispatcherHostProfile{
ID: "ALL2",
FilterIDs: []string{},
Weight: 20,
Params: make(map[string]any),
},
},
Weight: 20,
}, true); err != nil {
t.Error(err)
}
var reply map[string]any
if err := dsp.ResponderGetCostOnRatingPlans(args, &reply); err == nil {
t.Error(err)
}
}
// func TestDspResponderGetMaxSessionTimeOnAccounts(t *testing.T) {
// cfg := config.NewDefaultCGRConfig()
// dm := engine.NewDataManager(engine.NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items), cfg.CacheCfg(), nil)
// dsp := NewDispatcherService(dm, cfg, nil, nil)
// args := &utils.GetMaxSessionTimeOnAccountsArgs{
// Subject: "1002",
// Destination: "1001",
// Usage: 2 * time.Minute,
// Tenant: "cgrates.org",
// }
// if err := dm.SetDispatcherHost(&engine.DispatcherHost{
// Tenant: "cgrates.org",
// RemoteHost: &config.RemoteHost{
// ID: "ALL2",
// },
// }); err != nil {
// t.Error(err)
// }
// if err := dm.SetDispatcherProfile(&engine.DispatcherProfile{
// Tenant: "cgrates.org",
// ID: "DSP_Test1",
// FilterIDs: []string{},
// Strategy: utils.MetaRoundRobin,
// Subsystems: []string{utils.MetaAny},
// Hosts: engine.DispatcherHostProfiles{
// &engine.DispatcherHostProfile{
// ID: "ALL2",
// FilterIDs: []string{},
// Weight: 20,
// Params: make(map[string]any),
// },
// },
// Weight: 20,
// }, true); err != nil {
// t.Error(err)
// }
// var reply map[string]any
// if err := dsp.ResponderGetMaxSessionTimeOnAccounts(args, &reply); err == nil {
// t.Error(err)
// }
// }