mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Add test for special case in case of suppliers
This commit is contained in:
committed by
Dan Christian Bogos
parent
5c14688366
commit
ffd39481ad
@@ -67,6 +67,10 @@ var sTestsSupplierSV1 = []func(t *testing.T){
|
||||
testV1SplSUpdateSupplierProfiles,
|
||||
testV1SplSRemSupplierProfiles,
|
||||
testV1SplSGetSupplierForEvent,
|
||||
//reset the database and load the TP again
|
||||
testV1SplSInitDataDb,
|
||||
testV1SplSFromFolder,
|
||||
testV1SplsOneSupplierWithoutDestination,
|
||||
testV1SplSupplierPing,
|
||||
testV1SplSStopEngine,
|
||||
}
|
||||
@@ -950,6 +954,94 @@ func testV1SplSGetSupplierForEvent(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// Scenario: We create two rating plans RP_MOBILE and RP_LOCAL
|
||||
// RP_LOCAL contains destination for both mobile and local
|
||||
// and RP_MOBILE contains destinations only for mobile
|
||||
// Create a SupplierProfile with *least_cost strategy with 2 suppliers
|
||||
// supplier1 have attached RP_LOCAL and supplier2 have attach RP_MOBILE
|
||||
func testV1SplsOneSupplierWithoutDestination(t *testing.T) {
|
||||
var reply *engine.SupplierProfile
|
||||
if err := splSv1Rpc.Call("ApierV1.GetSupplierProfile",
|
||||
&utils.TenantID{Tenant: "cgrates.org", ID: "SPL_DESTINATION"}, &reply); err == nil ||
|
||||
err.Error() != utils.ErrNotFound.Error() {
|
||||
t.Error(err)
|
||||
}
|
||||
splPrf = &SupplierWithCache{
|
||||
SupplierProfile: &engine.SupplierProfile{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "SPL_DESTINATION",
|
||||
FilterIDs: []string{"*string:~Account:SpecialCase"},
|
||||
Sorting: utils.MetaLeastCost,
|
||||
Suppliers: []*engine.Supplier{
|
||||
{
|
||||
ID: "local",
|
||||
RatingPlanIDs: []string{"RP_LOCAL"},
|
||||
Weight: 10,
|
||||
},
|
||||
{
|
||||
ID: "mobile",
|
||||
RatingPlanIDs: []string{"RP_MOBILE"},
|
||||
FilterIDs: []string{"*destinations:~*req.Destination:DST_MOBILE"},
|
||||
Weight: 10,
|
||||
},
|
||||
},
|
||||
Weight: 100,
|
||||
},
|
||||
}
|
||||
|
||||
var result string
|
||||
if err := splSv1Rpc.Call("ApierV1.SetSupplierProfile", splPrf, &result); err != nil {
|
||||
t.Error(err)
|
||||
} else if result != utils.OK {
|
||||
t.Error("Unexpected reply returned", result)
|
||||
}
|
||||
|
||||
ev := &engine.ArgsGetSuppliers{
|
||||
CGREvent: &utils.CGREvent{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "testV1SplsOneSupplierWithoutDestination",
|
||||
Event: map[string]interface{}{
|
||||
utils.Account: "SpecialCase",
|
||||
utils.Destination: "+24680",
|
||||
utils.SetupTime: utils.MetaNow,
|
||||
utils.Usage: "2m",
|
||||
},
|
||||
},
|
||||
IgnoreErrors: true,
|
||||
}
|
||||
eSpls := engine.SortedSuppliers{
|
||||
ProfileID: "SPL_DESTINATION",
|
||||
Sorting: utils.MetaLeastCost,
|
||||
Count: 1,
|
||||
SortedSuppliers: []*engine.SortedSupplier{
|
||||
{
|
||||
SupplierID: "local",
|
||||
SortingData: map[string]interface{}{
|
||||
utils.Cost: 0.0396,
|
||||
"RatingPlanID": "RP_LOCAL",
|
||||
utils.Weight: 10.0,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
var suplsReply engine.SortedSuppliers
|
||||
if err := splSv1Rpc.Call(utils.SupplierSv1GetSuppliers,
|
||||
ev, &suplsReply); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(eSpls, suplsReply) {
|
||||
t.Errorf("Expecting: %s, received: %s",
|
||||
utils.ToJSON(eSpls), utils.ToJSON(suplsReply))
|
||||
}
|
||||
|
||||
//in case that we don't use ignore errors
|
||||
//we get an error for the second supplier
|
||||
ev.IgnoreErrors = false
|
||||
if err := splSv1Rpc.Call(utils.SupplierSv1GetSuppliers,
|
||||
ev, &suplsReply); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func testV1SplSStopEngine(t *testing.T) {
|
||||
if err := engine.KillEngine(100); err != nil {
|
||||
t.Error(err)
|
||||
|
||||
@@ -3,4 +3,7 @@ DR_ANY_1CNT,*any,RT_1CNT,*up,5,0,
|
||||
DR_ANY_2CNT,*any,RT_2CNT,*up,5,0,
|
||||
DR_SPECIAL_1002,DST_1002,RT_1CNT,*up,4,0,
|
||||
DR_FS_40CNT,DST_FS,RT_40CNT,*up,4,0,
|
||||
DR_TEST_1,DST_1001,RT_TEST_1,*up,4,0,
|
||||
DR_TEST_1,DST_1001,RT_TEST_1,*up,4,0,
|
||||
DR_MOBILE_1CNT,DST_MOBILE,RT_1CNT,*up,5,0,
|
||||
DR_LOCAL_2CNT,DST_LOCAL,RT_2CNT,*up,5,0,
|
||||
DR_LOCAL_2CNT,DST_MOBILE,RT_2CNT,*up,5,0,
|
||||
|
@@ -3,5 +3,6 @@ DST_1002,1002
|
||||
DST_FS,10
|
||||
DST_DE_MOBILE,+49151
|
||||
DST_1001,1001
|
||||
|
||||
DST_MOBILE,+135
|
||||
DST_LOCAL,+246
|
||||
|
||||
|
||||
|
@@ -4,4 +4,6 @@ RP_SPECIAL_1002,DR_SPECIAL_1002,*any,10
|
||||
RP_RETAIL1,DR_FS_40CNT,*any,10
|
||||
RP_ANY2CNT,DR_ANY_2CNT,*any,10
|
||||
RP_ANY1CNT,DR_ANY_1CNT,*any,10
|
||||
RP_TEST,DR_TEST_1,*any,10
|
||||
RP_TEST,DR_TEST_1,*any,10
|
||||
RP_MOBILE,DR_MOBILE_1CNT,*any,10
|
||||
RP_LOCAL,DR_LOCAL_2CNT,*any,10
|
||||
|
Reference in New Issue
Block a user