Improving coverage tests

This commit is contained in:
gezimbll
2023-05-05 11:00:31 -04:00
committed by Dan Christian Bogos
parent 11e2e2dbb8
commit 7a0ff57a36
4 changed files with 264 additions and 0 deletions

View File

@@ -4918,3 +4918,65 @@ func TestDmCheckFiltersRmt(t *testing.T) {
}
//unfinished
}
func TestDmRebuildReverseForPrefix(t *testing.T) {
testCases := []struct {
desc string
prefix string
expectErr bool
}{
{
desc: "Valid prefix - ReverseDestinationPrefix",
prefix: utils.ReverseDestinationPrefix,
expectErr: false,
},
{
desc: "Valid prefix - AccountActionPlansPrefix",
prefix: utils.AccountActionPlansPrefix,
expectErr: false,
},
{
desc: "Invalid prefix",
prefix: "invalid_prefix",
expectErr: true,
},
}
cfg := config.NewDefaultCGRConfig()
db := NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items)
dm := NewDataManager(db, cfg.CacheCfg(), nil)
dm.SetDestination(&Destination{
Id: "Dest",
Prefixes: []string{"1001", "1002"},
}, "")
apls := []*ActionPlan{
{
Id: "DisableBal",
AccountIDs: utils.StringMap{"cgrates:1001": true},
},
{
Id: "MoreMinutes",
AccountIDs: utils.StringMap{"cgrates:1002": true},
},
}
dm.SetAccount(&Account{ID: "cgrates:org:1001"})
dm.SetAccount(&Account{ID: "cgrates:org:1002"})
for _, apl := range apls {
dm.SetActionPlan(apl.Id, apl, true, "")
}
for _, tc := range testCases {
t.Run(tc.desc, func(t *testing.T) {
err := dm.RebuildReverseForPrefix(tc.prefix)
if tc.expectErr {
if err == nil {
t.Fatal("Expected error, got nil")
}
} else {
if err != nil {
t.Fatalf("Expected no error, got: %v", err)
}
}
})
}
}

View File

@@ -2181,3 +2181,66 @@ func TestV1GetRoutesList(t *testing.T) {
}
}
func TestRoutesV1GetRoutes(t *testing.T) {
cfg := config.NewDefaultCGRConfig()
db := NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items)
dm := NewDataManager(db, cfg.CacheCfg(), nil)
rpS := NewRouteService(dm, NewFilterS(cfg, nil, dm), cfg, nil)
var reply []*RouteProfile
fltr := &Filter{
Tenant: "cgrates.org",
ID: "FLT1",
Rules: []*FilterRule{
{
Type: utils.MetaString,
Element: "~*req.Account",
Values: []string{"1003"},
},
},
}
dm.SetFilter(fltr, true)
rpp := &RouteProfile{
Tenant: "cgrates.org",
ID: "ROUTE1",
FilterIDs: []string{"FLT1"},
ActivationInterval: &utils.ActivationInterval{
ActivationTime: time.Date(2022, 11, 27, 0, 0, 0, 0, time.UTC),
},
Sorting: utils.MetaWeight,
Routes: []*Route{{
ID: "route1",
Weight: 10,
}, {
ID: "route2",
Weight: 20,
}},
Weight: 20,
}
dm.SetRouteProfile(rpp, true)
args := &utils.CGREvent{
Tenant: "cgrates.org",
ID: "RouteProcessEvent",
Event: map[string]interface{}{
utils.RequestType: utils.MetaPostpaid,
utils.Category: utils.Call,
utils.AccountField: "1003",
utils.Subject: "1003",
utils.Destination: "1002",
utils.AnswerTime: time.Date(2018, 8, 24, 16, 00, 26, 0, time.UTC),
utils.SetupTime: time.Date(2018, 8, 24, 16, 00, 00, 0, time.UTC),
utils.Usage: time.Minute,
},
}
if err := rpS.V1GetRouteProfilesForEvent(args, &reply); err != nil {
t.Error(err)
}
if !reflect.DeepEqual(reply[0], rpp) {
t.Errorf("expected %+v,received %+v", utils.ToJSON(rpp), utils.ToJSON(reply))
}
}