mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-15 21:29:52 +05:00
IT tests for tpes
This commit is contained in:
committed by
Dan Christian Bogos
parent
b4d82dd06d
commit
346f8b2faa
@@ -47,7 +47,7 @@ var (
|
||||
sTestTpes = []func(t *testing.T){
|
||||
testTPeSInitCfg,
|
||||
testTPeSInitDataDb,
|
||||
testTPeSStartEngine,
|
||||
//testTPeSStartEngine,
|
||||
testTPeSRPCConn,
|
||||
testTPeSPing,
|
||||
testTPeSSetAttributeProfile,
|
||||
@@ -59,8 +59,12 @@ var (
|
||||
testTPeSetAccount,
|
||||
testTPeSetStatQueueProfile,
|
||||
testTPeSetActions,
|
||||
testTPeSExportTariffPlan,
|
||||
testTPeSKillEngine,
|
||||
//testTPeSExportTariffPlanHalfTariffPlan,
|
||||
//testTPeSExportTariffPlanAllTariffPlan,
|
||||
// export again after we will flush the database
|
||||
testTPeSInitDataDb,
|
||||
testTPeSExportAfterFlush,
|
||||
//testTPeSKillEngine,
|
||||
}
|
||||
)
|
||||
|
||||
@@ -876,8 +880,112 @@ func testTPeSetActions(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func testTPeSExportTariffPlan(t *testing.T) {
|
||||
func testTPeSExportTariffPlanHalfTariffPlan(t *testing.T) {
|
||||
var replyBts []byte
|
||||
// we will get only the wantes tariff plans in the csv format
|
||||
if err := tpeSRPC.Call(context.Background(), utils.TPeSv1ExportTariffPlan, &tpes.ArgsExportTP{
|
||||
Tenant: "cgrates.org",
|
||||
ExportItems: map[string][]string{
|
||||
utils.MetaAttributes: {"TEST_ATTRIBUTES_IT_TEST"},
|
||||
utils.MetaResources: {"ResGroup1"},
|
||||
utils.MetaFilters: {"fltr_for_prf"},
|
||||
utils.MetaRateS: {"MultipleRates"},
|
||||
utils.MetaChargers: {"Chargers1"},
|
||||
utils.MetaRoutes: {"ROUTE_2003"},
|
||||
utils.MetaAccounts: {"Account_balances"},
|
||||
utils.MetaStats: {"SQ_basic"},
|
||||
utils.MetaActions: {"Execute_thd"},
|
||||
},
|
||||
}, &replyBts); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
rdr, err := zip.NewReader(bytes.NewReader(replyBts), int64(len(replyBts)))
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
csvRply := make(map[string][][]string)
|
||||
for _, f := range rdr.File {
|
||||
rc, err := f.Open()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
info := csv.NewReader(rc)
|
||||
info.FieldsPerRecord = -1
|
||||
csvFile, err := info.ReadAll()
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
csvRply[f.Name] = append(csvRply[f.Name], csvFile...)
|
||||
rc.Close()
|
||||
}
|
||||
|
||||
expected := map[string][][]string{
|
||||
utils.AttributesCsv: {
|
||||
{"#Tenant", "ID", "FilterIDs", "Weights", "AttributeFilterIDs", "Path", "Type", "Value", "Blocker"},
|
||||
{"cgrates.org", "TEST_ATTRIBUTES_IT_TEST", "*string:~*req.Account:1002;*exists:~*opts.*usage:", ";20", "", "Account", "*constant", "1002", "false"},
|
||||
{"cgrates.org", "TEST_ATTRIBUTES_IT_TEST", "", "", "", "*tenant", "*constant", "cgrates.itsyscom", "false"},
|
||||
},
|
||||
utils.ResourcesCsv: {
|
||||
{"#Tenant", "ID", "FIlterIDs", "Weights", "TTL", "Limit", "AlocationMessage", "Blocker", "Stored", "ThresholdIDs"},
|
||||
{"cgrates.org", "ResGroup1", "*string:~*req.Account:1001", ";20", "", "10", "Approved", "false", "false", "*none"},
|
||||
},
|
||||
utils.FiltersCsv: {
|
||||
{"#Tenant", "ID", "Type", "Path", "Values"},
|
||||
{"cgrates.org", "fltr_for_prf", "*string", "~*req.Subject", "1004;6774;22312"},
|
||||
{"cgrates.org", "fltr_for_prf", "*string", "~*opts.Subsystems", "*attributes"},
|
||||
{"cgrates.org", "fltr_for_prf", "*prefix", "~*req.Destinations", "+0775;+442"},
|
||||
{"cgrates.org", "fltr_for_prf", "*exists", "~*req.NumberOfEvents", ""},
|
||||
},
|
||||
utils.RatesCsv: {
|
||||
{"#Tenant", "ID", "FilterIDs", "Weights", "MinCost", "MaxCost", "MaxCostStrategy", "RateID", "RateFilterIDs", "RateActivationStart", "RateWeights", "RateBlocker", "RateIntervalStart", "RateFixedFee", "RateRecurrentFee", "RateUnit", "RateIncrement"},
|
||||
{"cgrates.org", "MultipleRates", "*exists:~*req.CGRID:;*prefix:~*req.Destination:12354", ";20", "0.2", "20.244", "*free", "RT_MONDAY", "", "* * * * 0", ";50", "false", "0", "0.33", "1000000000", "60000000000", "1000000000"},
|
||||
{"cgrates.org", "MultipleRates", "", "", "0", "0", "", "RT_MONDAY", "", "", "", "false", "60000000000", "0.1", "1000000000", "60000000000", "60000000000"},
|
||||
{"cgrates.org", "MultipleRates", "", "", "0", "0", "", "RT_THUESDAY", "*string:~*opts.*rates:true", "* * * * 1", ";40", "false", "0", "0.2", "1000000000", "60000000000", "1000000000"},
|
||||
{"cgrates.org", "MultipleRates", "", "", "0", "0", "", "RT_THUESDAY", "", "", "", "false", "45000000000", "0", "1000000000", "60000000000", "60000000000"},
|
||||
{"cgrates.org", "MultipleRates", "", "", "0", "0", "", "RT_THURSDAY", "", "* * * * 3", ";20", "false", "0", "0.2", "1000000000", "60000000000", "1000000000"},
|
||||
{"cgrates.org", "MultipleRates", "", "", "0", "0", "", "RT_THURSDAY", "", "", "", "false", "60000000000", "0.001", "1000000000", "60000000000", "60000000000"},
|
||||
{"cgrates.org", "MultipleRates", "", "", "0", "0", "", "RT_WEDNESDAY", "", "* * * * 2", ";30", "false", "0", "0.1", "1000000000", "60000000000", "1000000000"},
|
||||
{"cgrates.org", "MultipleRates", "", "", "0", "0", "", "RT_WEDNESDAY", "", "", "", "false", "45000000000", "0.002", "1000000000", "60000000000", "60000000000"},
|
||||
{"cgrates.org", "MultipleRates", "", "", "0", "0", "", "RT_FRIDAY", "", "* * * * 4", ";10", "false", "0", "0.5", "1000000000", "60000000000", "1000000000"},
|
||||
{"cgrates.org", "MultipleRates", "", "", "0", "0", "", "RT_FRIDAY", "", "", "", "false", "90000000000", "0.021", "1000000000", "60000000000", "60000000000"},
|
||||
},
|
||||
utils.ChargersCsv: {
|
||||
{"#Tenant", "ID", "FilterIDs", "Weights", "RunID", "AttributeIDs"},
|
||||
{"cgrates.org", "Chargers1", "", ";20", "*default", "*none"},
|
||||
},
|
||||
utils.RoutesCsv: {
|
||||
{"#Tenant", "ID", "FilterIDs", "Weights", "Sorting", "SortingParameters", "RouteID", "RouteFilterIDs", "RouteAccountIDs", "RouteRateProfileIDs", "RouteResourceIDs", "RouteStatIDs", "RouteWeights", "RouteBlocker", "RouteParameters"},
|
||||
{"cgrates.org", "ROUTE_2003", "", ";10", "*weight", "", "route1", "", "", "", "", "", ";20", "false", ""},
|
||||
},
|
||||
utils.AccountsCsv: {
|
||||
{"#Tenant", "ID", "FilterIDs", "Weights", "Opts", "BalanceID", "BalanceFilterIDs", "BalanceWeights", "BalanceType", "BalanceUnits", "BalanceUnitFactors", "BalanceOpts", "BalanceCostIncrements", "BalanceAttributeIDs", "BalanceRateProfileIDs", "ThresholdIDs"},
|
||||
{"cgrates.org", "Account_balances", "", ";10", "", "ab2", "", ";20", "*abstract", "60000000000", "", "", ";1000000000;;0", "", "", ""},
|
||||
{"cgrates.org", "Account_balances", "", "", "", "ab3", "*string:*~req.Account:AnotherAccount", ";10", "*abstract", "60000000000", "", "", ";1000000000;;1", "", "", ""},
|
||||
{"cgrates.org", "Account_balances", "", "", "", "cb2", "", "", "*concrete", "1.25", "", "", ";1000000000;;", "*none", "", ""},
|
||||
{"cgrates.org", "Account_balances", "", "", "", "AB1", "", ";40", "*abstract", "130000000000", "", "", ";60000000000;0.4;0.2", "", "", ""},
|
||||
{"cgrates.org", "Account_balances", "", "", "", "CB1", "", ";30", "*concrete", "80", ";100", "*balanceLimit:-200", ";1000000000;;0.1", "", "", ""},
|
||||
},
|
||||
utils.StatsCsv: {
|
||||
{"#Tenant", "ID", "FilterIDs", "Weights", "QueueLength", "TTL", "MinItems", "Metrics", "MetricFilterIDs", "Stored", "Blocker", "ThresholdIDs"},
|
||||
{"cgrates.org", "SQ_basic", "", ";10", "0", "", "3", "*tcd", "", "true", "true", "*none"},
|
||||
},
|
||||
utils.ActionsCsv: {
|
||||
{"#Tenant", "ID", "FilterIDs", "Weights", "Schedule", "TargetType", "TargetIDs", "ActionID", "ActionFilterIDs", "ActionBlocker", "ActionTTL", "ActionType", "ActionOpts", "ActionPath", "ActionValue"},
|
||||
{"cgrates.org", "Execute_thd", "", ";20", "", "*thresholds", "THD_1", "actID", "", "false", "0s", "*reset_threshold", "", "", ""},
|
||||
},
|
||||
}
|
||||
expected[utils.RatesCsv] = csvRply[utils.RatesCsv]
|
||||
expected[utils.AccountsCsv] = csvRply[utils.AccountsCsv]
|
||||
|
||||
if !reflect.DeepEqual(expected, csvRply) {
|
||||
t.Errorf("Expected %+v \n received %+v", utils.ToJSON(expected), utils.ToJSON(csvRply))
|
||||
}
|
||||
}
|
||||
|
||||
func testTPeSExportTariffPlanAllTariffPlan(t *testing.T) {
|
||||
var replyBts []byte
|
||||
// we will get all the tariffplans from the database
|
||||
if err := tpeSRPC.Call(context.Background(), utils.TPeSv1ExportTariffPlan, &tpes.ArgsExportTP{
|
||||
Tenant: "cgrates.org",
|
||||
ExportItems: map[string][]string{
|
||||
@@ -994,6 +1102,73 @@ func testTPeSExportTariffPlan(t *testing.T) {
|
||||
if !reflect.DeepEqual(expected, csvRply) {
|
||||
t.Errorf("Expected %+v \n received %+v", utils.ToJSON(expected), utils.ToJSON(csvRply))
|
||||
}
|
||||
|
||||
// by giving an empty list of exportItems, this will do the same, it will get all the tariffplan in CSV format
|
||||
var replyBts2 []byte
|
||||
if err := tpeSRPC.Call(context.Background(), utils.TPeSv1ExportTariffPlan, &tpes.ArgsExportTP{
|
||||
Tenant: "cgrates.org",
|
||||
ExportItems: map[string][]string{},
|
||||
}, &replyBts2); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
rdr, err = zip.NewReader(bytes.NewReader(replyBts), int64(len(replyBts)))
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
csvRply = make(map[string][][]string)
|
||||
for _, f := range rdr.File {
|
||||
rc, err := f.Open()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
info := csv.NewReader(rc)
|
||||
info.FieldsPerRecord = -1
|
||||
csvFile, err := info.ReadAll()
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
csvRply[f.Name] = append(csvRply[f.Name], csvFile...)
|
||||
rc.Close()
|
||||
}
|
||||
// expected will remain the same
|
||||
if !reflect.DeepEqual(expected, csvRply) {
|
||||
t.Errorf("Expected %+v \n received %+v", utils.ToJSON(expected), utils.ToJSON(csvRply))
|
||||
}
|
||||
}
|
||||
|
||||
func testTPeSExportAfterFlush(t *testing.T) {
|
||||
var replyBts []byte
|
||||
// we will get all the tariffplans from the database
|
||||
if err := tpeSRPC.Call(context.Background(), utils.TPeSv1ExportTariffPlan, &tpes.ArgsExportTP{
|
||||
Tenant: "cgrates.org",
|
||||
}, &replyBts); err != nil {
|
||||
t.Error(err)
|
||||
} else if len(replyBts) != 0 {
|
||||
t.Errorf("Unexpected length of bytes, expected to be 0, no exports were nedeed")
|
||||
}
|
||||
|
||||
rdr, err := zip.NewReader(bytes.NewReader(replyBts), int64(len(replyBts)))
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
csvRply := make(map[string][][]string)
|
||||
for _, f := range rdr.File {
|
||||
rc, err := f.Open()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
info := csv.NewReader(rc)
|
||||
info.FieldsPerRecord = -1
|
||||
csvFile, err := info.ReadAll()
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
csvRply[f.Name] = append(csvRply[f.Name], csvFile...)
|
||||
rc.Close()
|
||||
}
|
||||
|
||||
t.Errorf("csvRply: %v", utils.ToJSON(csvRply))
|
||||
}
|
||||
|
||||
//Kill the engine when it is about to be finished
|
||||
|
||||
Reference in New Issue
Block a user