Add integration test routes with Account RateProfile combination

This commit is contained in:
TeoV
2020-11-19 17:03:12 +02:00
committed by Dan Christian Bogos
parent 5d437a9631
commit 58e00909c7
5 changed files with 223 additions and 0 deletions

View File

@@ -39,6 +39,7 @@ var (
testV1RouteSWithRateSRpcConn,
testV1RouteSWithRateSFromFolder,
testV1RouteSWithRateSGetRoutes,
//testV1RouteSWithRateSAccountWithRateProfile, //need to be discussed
testV1RouteSWithRateSStopEngine,
}
)
@@ -164,6 +165,223 @@ func testV1RouteSWithRateSGetRoutes(t *testing.T) {
}
}
/*
func testV1RouteSWithRateSAccountWithRateProfile(t *testing.T) {
routePrf = &RouteWithCache{
RouteProfile: &engine.RouteProfile{
Tenant: "cgrates.org",
ID: "RouteWithAccAndRatePrf",
FilterIDs: []string{"*string:~*req.EventType:testV1RouteSWithRateSAccountWithRateProfile"},
Sorting: utils.MetaLC,
Routes: []*engine.Route{
{
ID: "RouteWithAccAndRatePrf",
AccountIDs: []string{"AccWithVoice"},
RateProfileIDs: []string{"RT_ANY2CNT_SEC"},
Weight: 20,
},
{
ID: "RouteWithRP",
RateProfileIDs: []string{"RT_ANY1CNT_SEC"},
Weight: 10,
},
},
Weight: 100,
},
}
var result string
if err := routeSv1Rpc.Call(utils.APIerSv1SetRouteProfile, routePrf, &result); err != nil {
t.Error(err)
} else if result != utils.OK {
t.Error("Unexpected reply returned", result)
}
attrSetBalance := utils.AttrSetBalance{
Tenant: "cgrates.org",
Account: "AccWithVoice",
BalanceType: utils.VOICE,
Value: 30 * float64(time.Second),
Balance: map[string]interface{}{
utils.ID: "VoiceBalance",
},
}
var reply string
if err := routeSv1Rpc.Call(utils.APIerSv2SetBalance, &attrSetBalance, &reply); err != nil {
t.Error(err)
} else if reply != utils.OK {
t.Errorf("Received: %s", reply)
}
var acnt *engine.Account
attrAcc := &utils.AttrGetAccount{
Tenant: "cgrates.org",
Account: "AccWithVoice",
}
if err := routeSv1Rpc.Call(utils.APIerSv2GetAccount, attrAcc, &acnt); err != nil {
t.Error(err)
} else if acnt.BalanceMap[utils.VOICE].GetTotalValue() != 30*float64(time.Second) {
t.Errorf("Unexpected balance received : %+v", acnt.BalanceMap[utils.VOICE].GetTotalValue())
}
// test for 30 seconds usage
// we expect that the route with account to have cost 0
tNow := time.Now()
ev := &engine.ArgsGetRoutes{
CGREventWithOpts: &utils.CGREventWithOpts{
CGREvent: &utils.CGREvent{
Tenant: "cgrates.org",
Time: &tNow,
ID: "testV1RouteAccountWithRatingPlan",
Event: map[string]interface{}{
utils.Account: "RandomAccount",
utils.Destination: "+135876",
utils.SetupTime: utils.MetaNow,
utils.Usage: "30s",
"EventType": "testV1RouteSWithRateSAccountWithRateProfile",
},
},
},
}
eSpls := &engine.SortedRoutes{
ProfileID: "RouteWithAccAndRatePrf",
Sorting: utils.MetaLC,
Count: 2,
SortedRoutes: []*engine.SortedRoute{
{
RouteID: "RouteWithAccAndRatePrf",
SortingData: map[string]interface{}{
utils.Account: "AccWithVoice",
"Cost": 0.0,
"MaxUsage": 30000000000.0,
utils.Weight: 20.0,
},
},
{
RouteID: "RouteWithRP",
SortingData: map[string]interface{}{
utils.Cost: 0.3,
utils.RateProfileMatched: "RT_ANY1CNT_SEC",
utils.Weight: 10.0,
},
},
},
}
var suplsReply *engine.SortedRoutes
if err := routeSv1Rpc.Call(utils.RouteSv1GetRoutes,
ev, &suplsReply); err != nil {
t.Error(err)
} else if !reflect.DeepEqual(eSpls, suplsReply) {
t.Errorf("Expecting: %s \n received: %s",
utils.ToJSON(eSpls), utils.ToJSON(suplsReply))
}
// test for 60 seconds usage
// 30 seconds are covered by account and the remaining will be calculated
ev = &engine.ArgsGetRoutes{
CGREventWithOpts: &utils.CGREventWithOpts{
CGREvent: &utils.CGREvent{
Tenant: "cgrates.org",
Time: &tNow,
ID: "testV1RouteAccountWithRatingPlan",
Event: map[string]interface{}{
utils.Account: "RandomAccount",
utils.Destination: "+135876",
utils.SetupTime: utils.MetaNow,
utils.Usage: "60s",
"EventType": "testV1RouteSWithRateSAccountWithRateProfile",
},
},
},
}
eSpls = &engine.SortedRoutes{
ProfileID: "RouteWithAccAndRatePrf",
Sorting: utils.MetaLC,
Count: 2,
SortedRoutes: []*engine.SortedRoute{
{
RouteID: "RouteWithAccAndRatePrf",
SortingData: map[string]interface{}{
utils.Account: "AccWithVoice",
"Cost": 0.6,
"MaxUsage": 30000000000.0,
utils.RateProfileMatched: "RT_ANY2CNT_SEC",
utils.Weight: 20.0,
},
},
{
RouteID: "RouteWithRP",
SortingData: map[string]interface{}{
"Cost": 0.6,
utils.RateProfileMatched: "RT_ANY1CNT_SEC",
utils.Weight: 10.0,
},
},
},
}
var routeRply *engine.SortedRoutes
if err := routeSv1Rpc.Call(utils.RouteSv1GetRoutes,
ev, &routeRply); err != nil {
t.Error(err)
} else if !reflect.DeepEqual(eSpls, routeRply) {
t.Errorf("Expecting: %s \n received: %s",
utils.ToJSON(eSpls), utils.ToJSON(routeRply))
}
// test for 61 seconds usage
// 30 seconds are covered by account and the remaining will be calculated
ev = &engine.ArgsGetRoutes{
CGREventWithOpts: &utils.CGREventWithOpts{
CGREvent: &utils.CGREvent{
Tenant: "cgrates.org",
Time: &tNow,
ID: "testV1RouteAccountWithRatingPlan",
Event: map[string]interface{}{
utils.Account: "RandomAccount",
utils.Destination: "+135876",
utils.SetupTime: utils.MetaNow,
utils.Usage: "1m1s",
"EventType": "testV1RouteSWithRateSAccountWithRateProfile",
},
},
},
}
eSpls = &engine.SortedRoutes{
ProfileID: "RouteWithAccAndRatePrf",
Sorting: utils.MetaLC,
Count: 2,
SortedRoutes: []*engine.SortedRoute{
{
RouteID: "RouteWithRP",
SortingData: map[string]interface{}{
utils.Cost: 0.61,
utils.RateProfileMatched: "RT_ANY1CNT_SEC",
utils.Weight: 10.0,
},
},
{
RouteID: "RouteWithAccAndRatePrf",
SortingData: map[string]interface{}{
utils.Account: "AccWithVoice",
utils.Cost: 0.62,
"MaxUsage": 30000000000.0,
utils.RateProfileMatched: "RT_ANY2CNT_SEC",
utils.Weight: 20.0,
},
},
},
}
var routeRply2 *engine.SortedRoutes
if err := routeSv1Rpc.Call(utils.RouteSv1GetRoutes,
ev, &routeRply2); err != nil {
t.Error(err)
} else if !reflect.DeepEqual(eSpls, routeRply2) {
t.Errorf("Expecting: %s \n received: %s",
utils.ToJSON(eSpls), utils.ToJSON(routeRply2))
}
}
*/
func testV1RouteSWithRateSStopEngine(t *testing.T) {
if err := engine.KillEngine(100); err != nil {
t.Error(err)

View File

@@ -37,6 +37,7 @@
"routes": {
"enabled": true,
"rals_conns": ["*internal"],
"rates_conns": ["*internal"],
},

View File

@@ -39,6 +39,7 @@
"routes": {
"enabled": true,
"rals_conns": ["*internal"],
"rates_conns": ["*internal"],
},

View File

@@ -39,6 +39,7 @@
"routes": {
"enabled": true,
"rals_conns": ["*internal"],
"rates_conns": ["*internal"]
},

View File

@@ -2,4 +2,6 @@
cgrates.org,RT_SPECIAL_1002,,,0,0,*up,4,0,0,*free,RT_ALWAYS,,"* * * * *",0,false,0s,0.01,1m,1s
cgrates.org,RT_RETAIL1,,,0,0,*up,4,0,0,*free,RT_ALWAYS,,"* * * * *",0,false,0s,0.4,1m,30s
cgrates.org,RT_RETAIL1,,,,,,,,,,RT_ALWAYS,,"* * * * *",0,false,1m,0.2,1m,10s
cgrates.org,RT_ANY2CNT_SEC,,,0,0,*up,4,0,0,*free,RT_ALWAYS,,"* * * * *",0,false,0s,0.02,1s,1s
cgrates.org,RT_ANY1CNT_SEC,,,0,0,*up,4,0,0,*free,RT_ALWAYS,,"* * * * *",0,false,0s,0.01,1s,1s
1 #Tenant ID FilterIDs ActivationInterval Weight ConnectFee RoundingMethod RoundingDecimals MinCost MaxCost MaxCostStrategy RateID RateFilterIDs RateActivationStart RateWeight RateBlocker RateIntervalStart RateValue RateUnit RateIncrement
2 cgrates.org RT_SPECIAL_1002 0 0 *up 4 0 0 *free RT_ALWAYS * * * * * 0 false 0s 0.01 1m 1s
3 cgrates.org RT_RETAIL1 0 0 *up 4 0 0 *free RT_ALWAYS * * * * * 0 false 0s 0.4 1m 30s
4 cgrates.org RT_RETAIL1 RT_ALWAYS * * * * * 0 false 1m 0.2 1m 10s
5 cgrates.org RT_ANY2CNT_SEC 0 0 *up 4 0 0 *free RT_ALWAYS * * * * * 0 false 0s 0.02 1s 1s
6 cgrates.org RT_ANY1CNT_SEC 0 0 *up 4 0 0 *free RT_ALWAYS * * * * * 0 false 0s 0.01 1s 1s
7