Updated integration tests

This commit is contained in:
Trial97
2021-01-13 09:51:36 +02:00
committed by Dan Christian Bogos
parent 6ce8cc549a
commit b6a2434969
7 changed files with 61 additions and 84 deletions

View File

@@ -211,10 +211,8 @@ func testCacheSReplicateProcessRateProfile(t *testing.T) {
},
}
exp := &engine.RateProfileCost{
ID: "RT_SPECIAL_1002",
Cost: 0.01,
RoundingDecimals: 4,
RoundingMethod: utils.MetaUp,
ID: "RT_SPECIAL_1002",
Cost: 0.01,
RateSIntervals: []*engine.RateSInterval{{
UsageStart: 0,

View File

@@ -121,13 +121,11 @@ func testTPRatePrfGetTPRatePrfBeforeSet(t *testing.T) {
func testTPRatePrfSetTPRatePrf(t *testing.T) {
tpRatePrf = &utils.TPRateProfile{
TPid: "TP1",
Tenant: "cgrates.org",
ID: "RT_SPECIAL_1002",
Weight: 10,
RoundingDecimals: 4,
RoundingMethod: "*up",
FilterIDs: make([]string, 0),
TPid: "TP1",
Tenant: "cgrates.org",
ID: "RT_SPECIAL_1002",
Weight: 10,
FilterIDs: make([]string, 0),
Rates: map[string]*utils.TPRate{
"RT_ALWAYS": {
ID: "RT_ALWAYS",

View File

@@ -85,26 +85,22 @@ func testDspRPrfPing(t *testing.T) {
}
func testDspRPrfCostForEvent(t *testing.T) {
minDecimal, err := utils.NewDecimalFromUnit("1m")
if err != nil {
t.Error(err)
}
rPrf := &engine.RateProfile{
rPrf := &engine.APIRateProfile{
ID: "DefaultRate",
Tenant: "cgrates.org",
FilterIDs: []string{"*string:~*req.Subject:1001"},
Weight: 10,
Rates: map[string]*engine.Rate{
Rates: map[string]*engine.APIRate{
"RT_WEEK": {
ID: "RT_WEEK",
Weight: 0,
ActivationTimes: "* * * * *",
IntervalRates: []*engine.IntervalRate{
IntervalRates: []*engine.APIIntervalRate{
{
IntervalStart: 0,
RecurrentFee: utils.NewDecimal(12, 2),
Unit: minDecimal,
Increment: minDecimal,
IntervalStart: "0",
RecurrentFee: utils.Float64Pointer(0.12),
Unit: utils.Float64Pointer(float64(time.Minute)),
Increment: utils.Float64Pointer(float64(time.Minute)),
},
},
},
@@ -123,6 +119,10 @@ func testDspRPrfCostForEvent(t *testing.T) {
}, &rply); err != nil {
t.Error(err)
}
rtWeek, err := rPrf.Rates["RT_WEEK"].AsRate()
if err != nil {
t.Fatal(err)
}
exp := &engine.RateProfileCost{
ID: "DefaultRate",
Cost: 0.12,
@@ -131,7 +131,7 @@ func testDspRPrfCostForEvent(t *testing.T) {
Increments: []*engine.RateSIncrement{{
UsageStart: 0,
Usage: time.Minute,
Rate: rPrf.Rates["RT_WEEK"],
Rate: rtWeek,
IntervalRateIndex: 0,
CompressFactor: 1,
}},
@@ -154,34 +154,26 @@ func testDspRPrfCostForEvent(t *testing.T) {
}}}, &rpCost); err != nil {
t.Error(err)
} else if !reflect.DeepEqual(rpCost, exp) {
t.Errorf("Expected %+v, received %+v", exp, rpCost)
t.Errorf("Expected %+v, received %+v", utils.ToJSON(exp), utils.ToJSON(rpCost))
}
}
func testDspRPrfCostForEventWithoutFilters(t *testing.T) {
minDecimal, err := utils.NewDecimalFromUnit("1m")
if err != nil {
t.Error(err)
}
secDecimal, err := utils.NewDecimalFromUnit("1s")
if err != nil {
t.Error(err)
}
rPrf := &engine.RateProfile{
rPrf := &engine.APIRateProfile{
ID: "ID_RP",
Tenant: "cgrates.org",
Weight: 10,
Rates: map[string]*engine.Rate{
Rates: map[string]*engine.APIRate{
"RT_WEEK": {
ID: "RT_WEEK",
Weight: 0,
ActivationTimes: "* * * * *",
IntervalRates: []*engine.IntervalRate{
IntervalRates: []*engine.APIIntervalRate{
{
IntervalStart: 0,
RecurrentFee: utils.NewDecimal(25, 2),
Unit: minDecimal,
Increment: secDecimal,
IntervalStart: "0",
RecurrentFee: utils.Float64Pointer(0.25),
Unit: utils.Float64Pointer(float64(time.Minute)),
Increment: utils.Float64Pointer(float64(time.Second)),
},
},
},
@@ -200,6 +192,10 @@ func testDspRPrfCostForEventWithoutFilters(t *testing.T) {
}, &rply); err != nil {
t.Error(err)
}
rtWeek, err := rPrf.Rates["RT_WEEK"].AsRate()
if err != nil {
t.Fatal(err)
}
exp := &engine.RateProfileCost{
ID: "ID_RP",
Cost: 0.25,
@@ -208,7 +204,7 @@ func testDspRPrfCostForEventWithoutFilters(t *testing.T) {
Increments: []*engine.RateSIncrement{{
UsageStart: 0,
Usage: time.Minute,
Rate: rPrf.Rates["RT_WEEK"],
Rate: rtWeek,
IntervalRateIndex: 0,
CompressFactor: 60,
}},

View File

@@ -1473,13 +1473,11 @@ func testDspRplRateProfile(t *testing.T) {
var replyStr string
rPrf := &engine.RateProfileWithOpts{
RateProfile: &engine.RateProfile{
Tenant: "cgrates.org",
ID: "RP1",
FilterIDs: []string{"*string:~*req.Subject:1001", "*string:~*req.Subject:1002"},
Weight: 0,
RoundingMethod: "*up",
RoundingDecimals: 4,
MaxCostStrategy: "*free",
Tenant: "cgrates.org",
ID: "RP1",
FilterIDs: []string{"*string:~*req.Subject:1001", "*string:~*req.Subject:1002"},
Weight: 0,
MaxCostStrategy: "*free",
Rates: map[string]*engine.Rate{
"FIRST_GI": {
ID: "FIRST_GI",

View File

@@ -144,27 +144,18 @@ type RateSIncrement struct {
// RateProfileCost is the cost returned by RateS at cost queries
type RateProfileCost struct {
ID string // RateProfileID
Cost float64
RoundingDecimals int
RoundingMethod string
MinCost float64
MaxCost float64
MaxCostStrategy string
RateSIntervals []*RateSInterval
Altered []string
ID string // RateProfileID
Cost float64
MinCost float64
MaxCost float64
MaxCostStrategy string
RateSIntervals []*RateSInterval
Altered []string
}
// CorrectCost should be called in final phase of cost calculation
// in order to apply further correction like Min/MaxCost or rounding
func (rPc *RateProfileCost) CorrectCost(rndDec *int, rndMtd string) {
if rndDec != nil {
rPc.RoundingDecimals = *rndDec
if rndMtd != utils.EmptyString {
rPc.RoundingMethod = rndMtd
}
}
if rPc.MinCost != 0 && rPc.Cost < rPc.MinCost {
rPc.Cost = rPc.MinCost
rPc.Altered = append(rPc.Altered, utils.MinCost)
@@ -173,8 +164,8 @@ func (rPc *RateProfileCost) CorrectCost(rndDec *int, rndMtd string) {
rPc.Cost = rPc.MaxCost
rPc.Altered = append(rPc.Altered, utils.MaxCost)
}
if rPc.RoundingDecimals != 0 {
rPc.Cost = utils.Round(rPc.Cost, rPc.RoundingDecimals, rPc.RoundingMethod)
if rndDec != nil {
rPc.Cost = utils.Round(rPc.Cost, *rndDec, rndMtd)
rPc.Altered = append(rPc.Altered, utils.RoundingDecimals)
}
}

View File

@@ -186,15 +186,13 @@ func testRatePrfITMigrateAndMove(t *testing.T) {
t.Error(err)
}
rPrf := &engine.RateProfile{
Tenant: "cgrates.org",
ID: "RP1",
FilterIDs: []string{"*string:~*req.Subject:1001"},
Weight: 0,
RoundingMethod: "*up",
RoundingDecimals: 4,
MinCost: utils.NewDecimal(1, 1),
MaxCost: utils.NewDecimal(6, 1),
MaxCostStrategy: "*free",
Tenant: "cgrates.org",
ID: "RP1",
FilterIDs: []string{"*string:~*req.Subject:1001"},
Weight: 0,
MinCost: utils.NewDecimal(1, 1),
MaxCost: utils.NewDecimal(6, 1),
MaxCostStrategy: "*free",
Rates: map[string]*engine.Rate{
"FIRST_GI": {
ID: "FIRST_GI",

View File

@@ -104,16 +104,14 @@ func testTPRateProfileFlush(t *testing.T) {
func testTPRateProfilePopulate(t *testing.T) {
tpRateProfiles = []*utils.TPRateProfile{
{
TPid: "id_RP1",
Tenant: "cgrates.org",
ID: "RP1",
FilterIDs: []string{"*string:~*req.Subject:1001"},
Weight: 0,
RoundingMethod: "*up",
RoundingDecimals: 4,
MinCost: 0.1,
MaxCost: 0.6,
MaxCostStrategy: "*free",
TPid: "id_RP1",
Tenant: "cgrates.org",
ID: "RP1",
FilterIDs: []string{"*string:~*req.Subject:1001"},
Weight: 0,
MinCost: 0.1,
MaxCost: 0.6,
MaxCostStrategy: "*free",
Rates: map[string]*utils.TPRate{
"FIRST_GI": {
ID: "FIRST_GI",