mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-24 08:38:45 +05:00
Add test in loader for RateProfile with updated fields
This commit is contained in:
@@ -849,11 +849,14 @@ const CGRATES_CFG_JSON = `
|
||||
{"tag": "MaxCostStrategy", "path": "MaxCostStrategy", "type": "*variable", "value": "~*req.10"},
|
||||
{"tag": "RateID", "path": "RateID", "type": "*variable", "value": "~*req.11"},
|
||||
{"tag": "RateFilterIDs", "path": "RateFilterIDs", "type": "*variable", "value": "~*req.12"},
|
||||
{"tag": "RateWeight", "path": "RateWeight", "type": "*variable", "value": "~*req.13"},
|
||||
{"tag": "RateValue", "path": "RateValue", "type": "*variable", "value": "~*req.14"},
|
||||
{"tag": "RateUnit", "path": "RateUnit", "type": "*variable", "value": "~*req.15"},
|
||||
{"tag": "RateIncrement", "path": "RateIncrement", "type": "*variable", "value": "~*req.16"},
|
||||
{"tag": "RateBlocker", "path": "RateBlocker", "type": "*variable", "value": "~*req.17"},
|
||||
{"tag": "RateActivationStart", "path": "RateActivationStart", "type": "*variable", "value": "~*req.13"},
|
||||
{"tag": "RateWeight", "path": "RateWeight", "type": "*variable", "value": "~*req.14"},
|
||||
{"tag": "RateBlocker", "path": "RateBlocker", "type": "*variable", "value": "~*req.15"},
|
||||
{"tag": "RateIntervalStart", "path": "RateIntervalStart", "type": "*variable", "value": "~*req.16"},
|
||||
{"tag": "RateValue", "path": "RateValue", "type": "*variable", "value": "~*req.17"},
|
||||
{"tag": "RateUnit", "path": "RateUnit", "type": "*variable", "value": "~*req.18"},
|
||||
{"tag": "RateIncrement", "path": "RateIncrement", "type": "*variable", "value": "~*req.19"},
|
||||
|
||||
],
|
||||
},
|
||||
],
|
||||
|
||||
@@ -1683,26 +1683,34 @@ func TestDfLoaderJsonCfg(t *testing.T) {
|
||||
Path: utils.StringPointer("RateFilterIDs"),
|
||||
Type: utils.StringPointer(utils.MetaVariable),
|
||||
Value: utils.StringPointer("~*req.12")},
|
||||
{Tag: utils.StringPointer("RateActivationStart"),
|
||||
Path: utils.StringPointer("RateActivationStart"),
|
||||
Type: utils.StringPointer(utils.MetaVariable),
|
||||
Value: utils.StringPointer("~*req.13")},
|
||||
{Tag: utils.StringPointer("RateWeight"),
|
||||
Path: utils.StringPointer("RateWeight"),
|
||||
Type: utils.StringPointer(utils.MetaVariable),
|
||||
Value: utils.StringPointer("~*req.13")},
|
||||
{Tag: utils.StringPointer("RateValue"),
|
||||
Path: utils.StringPointer("RateValue"),
|
||||
Type: utils.StringPointer(utils.MetaVariable),
|
||||
Value: utils.StringPointer("~*req.14")},
|
||||
{Tag: utils.StringPointer("RateUnit"),
|
||||
Path: utils.StringPointer("RateUnit"),
|
||||
Type: utils.StringPointer(utils.MetaVariable),
|
||||
Value: utils.StringPointer("~*req.15")},
|
||||
{Tag: utils.StringPointer("RateIncrement"),
|
||||
Path: utils.StringPointer("RateIncrement"),
|
||||
Type: utils.StringPointer(utils.MetaVariable),
|
||||
Value: utils.StringPointer("~*req.16")},
|
||||
{Tag: utils.StringPointer("RateBlocker"),
|
||||
Path: utils.StringPointer("RateBlocker"),
|
||||
Type: utils.StringPointer(utils.MetaVariable),
|
||||
Value: utils.StringPointer("~*req.15")},
|
||||
{Tag: utils.StringPointer("RateIntervalStart"),
|
||||
Path: utils.StringPointer("RateIntervalStart"),
|
||||
Type: utils.StringPointer(utils.MetaVariable),
|
||||
Value: utils.StringPointer("~*req.16")},
|
||||
{Tag: utils.StringPointer("RateValue"),
|
||||
Path: utils.StringPointer("RateValue"),
|
||||
Type: utils.StringPointer(utils.MetaVariable),
|
||||
Value: utils.StringPointer("~*req.17")},
|
||||
{Tag: utils.StringPointer("RateUnit"),
|
||||
Path: utils.StringPointer("RateUnit"),
|
||||
Type: utils.StringPointer(utils.MetaVariable),
|
||||
Value: utils.StringPointer("~*req.18")},
|
||||
{Tag: utils.StringPointer("RateIncrement"),
|
||||
Path: utils.StringPointer("RateIncrement"),
|
||||
Type: utils.StringPointer(utils.MetaVariable),
|
||||
Value: utils.StringPointer("~*req.19")},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
@@ -1741,36 +1741,48 @@ func TestCgrLoaderCfgITDefaults(t *testing.T) {
|
||||
Value: NewRSRParsersMustCompile("~*req.12", true, utils.INFIELD_SEP),
|
||||
Layout: time.RFC3339,
|
||||
},
|
||||
{Tag: "RateWeight",
|
||||
Path: "RateWeight",
|
||||
{Tag: "RateActivationStart",
|
||||
Path: "RateActivationStart",
|
||||
Type: utils.MetaVariable,
|
||||
Value: NewRSRParsersMustCompile("~*req.13", true, utils.INFIELD_SEP),
|
||||
Layout: time.RFC3339,
|
||||
},
|
||||
{Tag: "RateValue",
|
||||
Path: "RateValue",
|
||||
{Tag: "RateWeight",
|
||||
Path: "RateWeight",
|
||||
Type: utils.MetaVariable,
|
||||
Value: NewRSRParsersMustCompile("~*req.14", true, utils.INFIELD_SEP),
|
||||
Layout: time.RFC3339,
|
||||
},
|
||||
{Tag: "RateUnit",
|
||||
Path: "RateUnit",
|
||||
Type: utils.MetaVariable,
|
||||
Value: NewRSRParsersMustCompile("~*req.15", true, utils.INFIELD_SEP),
|
||||
Layout: time.RFC3339,
|
||||
},
|
||||
{Tag: "RateIncrement",
|
||||
Path: "RateIncrement",
|
||||
Type: utils.MetaVariable,
|
||||
Value: NewRSRParsersMustCompile("~*req.16", true, utils.INFIELD_SEP),
|
||||
Layout: time.RFC3339,
|
||||
},
|
||||
{Tag: "RateBlocker",
|
||||
Path: "RateBlocker",
|
||||
Type: utils.MetaVariable,
|
||||
Value: NewRSRParsersMustCompile("~*req.15", true, utils.INFIELD_SEP),
|
||||
Layout: time.RFC3339,
|
||||
},
|
||||
{Tag: "RateIntervalStart",
|
||||
Path: "RateIntervalStart",
|
||||
Type: utils.MetaVariable,
|
||||
Value: NewRSRParsersMustCompile("~*req.16", true, utils.INFIELD_SEP),
|
||||
Layout: time.RFC3339,
|
||||
},
|
||||
{Tag: "RateValue",
|
||||
Path: "RateValue",
|
||||
Type: utils.MetaVariable,
|
||||
Value: NewRSRParsersMustCompile("~*req.17", true, utils.INFIELD_SEP),
|
||||
Layout: time.RFC3339,
|
||||
},
|
||||
{Tag: "RateUnit",
|
||||
Path: "RateUnit",
|
||||
Type: utils.MetaVariable,
|
||||
Value: NewRSRParsersMustCompile("~*req.18", true, utils.INFIELD_SEP),
|
||||
Layout: time.RFC3339,
|
||||
},
|
||||
{Tag: "RateIncrement",
|
||||
Path: "RateIncrement",
|
||||
Type: utils.MetaVariable,
|
||||
Value: NewRSRParsersMustCompile("~*req.19", true, utils.INFIELD_SEP),
|
||||
Layout: time.RFC3339,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
@@ -1223,3 +1223,179 @@ func TestLoaderRemoveContentSingleFile(t *testing.T) {
|
||||
utils.ToJSON(ap), utils.ToJSON(rcv))
|
||||
}
|
||||
}
|
||||
|
||||
func TestLoaderProcessRateProfile(t *testing.T) {
|
||||
data := engine.NewInternalDB(nil, nil, true, config.CgrConfig().DataDbCfg().Items)
|
||||
ldr := &Loader{
|
||||
ldrID: "TestLoaderProcessRateProfile",
|
||||
bufLoaderData: make(map[string][]LoaderData),
|
||||
dm: engine.NewDataManager(data, config.CgrConfig().CacheCfg(), nil),
|
||||
timezone: "UTC",
|
||||
}
|
||||
ldr.dataTpls = map[string][]*config.FCTemplate{
|
||||
utils.MetaRateProfiles: []*config.FCTemplate{
|
||||
&config.FCTemplate{Tag: "TenantID",
|
||||
Path: "Tenant",
|
||||
Type: utils.META_COMPOSED,
|
||||
Value: config.NewRSRParsersMustCompile("~*req.0", true, utils.INFIELD_SEP),
|
||||
Mandatory: true},
|
||||
&config.FCTemplate{Tag: "ProfileID",
|
||||
Path: "ID",
|
||||
Type: utils.META_COMPOSED,
|
||||
Value: config.NewRSRParsersMustCompile("~*req.1", true, utils.INFIELD_SEP),
|
||||
Mandatory: true},
|
||||
&config.FCTemplate{Tag: "FilterIDs",
|
||||
Path: "FilterIDs",
|
||||
Type: utils.META_COMPOSED,
|
||||
Value: config.NewRSRParsersMustCompile("~*req.2", true, utils.INFIELD_SEP)},
|
||||
&config.FCTemplate{Tag: "ActivationInterval",
|
||||
Path: "ActivationInterval",
|
||||
Type: utils.META_COMPOSED,
|
||||
Value: config.NewRSRParsersMustCompile("~*req.3", true, utils.INFIELD_SEP)},
|
||||
&config.FCTemplate{Tag: "Weight",
|
||||
Path: "Weight",
|
||||
Type: utils.META_COMPOSED,
|
||||
Value: config.NewRSRParsersMustCompile("~*req.4", true, utils.INFIELD_SEP)},
|
||||
&config.FCTemplate{Tag: "ConnectFee",
|
||||
Path: "ConnectFee",
|
||||
Type: utils.META_COMPOSED,
|
||||
Value: config.NewRSRParsersMustCompile("~*req.5", true, utils.INFIELD_SEP)},
|
||||
&config.FCTemplate{Tag: "RoundingMethod",
|
||||
Path: "RoundingMethod",
|
||||
Type: utils.META_COMPOSED,
|
||||
Value: config.NewRSRParsersMustCompile("~*req.6", true, utils.INFIELD_SEP)},
|
||||
&config.FCTemplate{Tag: "RoundingDecimals",
|
||||
Path: "RoundingDecimals",
|
||||
Type: utils.META_COMPOSED,
|
||||
Value: config.NewRSRParsersMustCompile("~*req.7", true, utils.INFIELD_SEP)},
|
||||
&config.FCTemplate{Tag: "MinCost",
|
||||
Path: "MinCost",
|
||||
Type: utils.META_COMPOSED,
|
||||
Value: config.NewRSRParsersMustCompile("~*req.8", true, utils.INFIELD_SEP)},
|
||||
&config.FCTemplate{Tag: "MaxCost",
|
||||
Path: "MaxCost",
|
||||
Type: utils.META_COMPOSED,
|
||||
Value: config.NewRSRParsersMustCompile("~*req.9", true, utils.INFIELD_SEP)},
|
||||
&config.FCTemplate{Tag: "MaxCostStrategy",
|
||||
Path: "MaxCostStrategy",
|
||||
Type: utils.META_COMPOSED,
|
||||
Value: config.NewRSRParsersMustCompile("~*req.10", true, utils.INFIELD_SEP)},
|
||||
&config.FCTemplate{Tag: "RateID",
|
||||
Path: "RateID",
|
||||
Type: utils.META_COMPOSED,
|
||||
Value: config.NewRSRParsersMustCompile("~*req.11", true, utils.INFIELD_SEP)},
|
||||
&config.FCTemplate{Tag: "RateFilterIDs",
|
||||
Path: "RateFilterIDs",
|
||||
Type: utils.META_COMPOSED,
|
||||
Value: config.NewRSRParsersMustCompile("~*req.12", true, utils.INFIELD_SEP)},
|
||||
&config.FCTemplate{Tag: "RateActivationStart",
|
||||
Path: "RateActivationStart",
|
||||
Type: utils.META_COMPOSED,
|
||||
Value: config.NewRSRParsersMustCompile("~*req.13", true, utils.INFIELD_SEP)},
|
||||
&config.FCTemplate{Tag: "RateWeight",
|
||||
Path: "RateWeight",
|
||||
Type: utils.META_COMPOSED,
|
||||
Value: config.NewRSRParsersMustCompile("~*req.14", true, utils.INFIELD_SEP)},
|
||||
&config.FCTemplate{Tag: "RateBlocker",
|
||||
Path: "RateBlocker",
|
||||
Type: utils.META_COMPOSED,
|
||||
Value: config.NewRSRParsersMustCompile("~*req.15", true, utils.INFIELD_SEP)},
|
||||
&config.FCTemplate{Tag: "RateIntervalStart",
|
||||
Path: "RateIntervalStart",
|
||||
Type: utils.META_COMPOSED,
|
||||
Value: config.NewRSRParsersMustCompile("~*req.16", true, utils.INFIELD_SEP)},
|
||||
&config.FCTemplate{Tag: "RateValue",
|
||||
Path: "RateValue",
|
||||
Type: utils.META_COMPOSED,
|
||||
Value: config.NewRSRParsersMustCompile("~*req.17", true, utils.INFIELD_SEP)},
|
||||
&config.FCTemplate{Tag: "RateUnit",
|
||||
Path: "RateUnit",
|
||||
Type: utils.META_COMPOSED,
|
||||
Value: config.NewRSRParsersMustCompile("~*req.18", true, utils.INFIELD_SEP)},
|
||||
&config.FCTemplate{Tag: "RateIncrement",
|
||||
Path: "RateIncrement",
|
||||
Type: utils.META_COMPOSED,
|
||||
Value: config.NewRSRParsersMustCompile("~*req.19", true, utils.INFIELD_SEP)},
|
||||
},
|
||||
}
|
||||
rdr := ioutil.NopCloser(strings.NewReader(engine.RateProfileCSVContent))
|
||||
csvRdr := csv.NewReader(rdr)
|
||||
csvRdr.Comment = '#'
|
||||
ldr.rdrs = map[string]map[string]*openedCSVFile{
|
||||
utils.MetaRateProfiles: map[string]*openedCSVFile{
|
||||
utils.RateProfilesCsv: &openedCSVFile{fileName: utils.RateProfilesCsv,
|
||||
rdr: rdr, csvRdr: csvRdr}},
|
||||
}
|
||||
if err := ldr.processContent(utils.MetaRateProfiles, utils.EmptyString); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if len(ldr.bufLoaderData) != 0 {
|
||||
t.Errorf("wrong buffer content: %+v", ldr.bufLoaderData)
|
||||
}
|
||||
eRatePrf := &engine.RateProfile{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "RP1",
|
||||
FilterIDs: []string{"*string:~*req.Subject:1001"},
|
||||
Weight: 0,
|
||||
ConnectFee: 0.1,
|
||||
RoundingMethod: "*up",
|
||||
RoundingDecimals: 4,
|
||||
MinCost: 0.1,
|
||||
MaxCost: 0.6,
|
||||
MaxCostStrategy: "*free",
|
||||
Rates: map[string]*engine.Rate{
|
||||
"RT_WEEK": &engine.Rate{
|
||||
ID: "RT_WEEK",
|
||||
Weight: 0,
|
||||
ActivationStart: "* * * * 1-5",
|
||||
IntervalRates: []*engine.IntervalRate{
|
||||
&engine.IntervalRate{
|
||||
IntervalStart: time.Duration(0 * time.Second),
|
||||
Value: 0.12,
|
||||
Unit: time.Duration(1 * time.Minute),
|
||||
Increment: time.Duration(1 * time.Minute),
|
||||
},
|
||||
&engine.IntervalRate{
|
||||
IntervalStart: time.Duration(1 * time.Minute),
|
||||
Value: 0.06,
|
||||
Unit: time.Duration(1 * time.Minute),
|
||||
Increment: time.Duration(1 * time.Second),
|
||||
},
|
||||
},
|
||||
},
|
||||
"RT_WEEKEND": &engine.Rate{
|
||||
ID: "RT_WEEKEND",
|
||||
Weight: 10,
|
||||
ActivationStart: "* * * * 0,6",
|
||||
IntervalRates: []*engine.IntervalRate{
|
||||
&engine.IntervalRate{
|
||||
IntervalStart: time.Duration(0 * time.Second),
|
||||
Value: 0.06,
|
||||
Unit: time.Duration(1 * time.Minute),
|
||||
Increment: time.Duration(1 * time.Second),
|
||||
},
|
||||
},
|
||||
},
|
||||
"RT_CHRISTMAS": &engine.Rate{
|
||||
ID: "RT_CHRISTMAS",
|
||||
Weight: 30,
|
||||
ActivationStart: "* * 24 12 *",
|
||||
IntervalRates: []*engine.IntervalRate{
|
||||
&engine.IntervalRate{
|
||||
IntervalStart: time.Duration(0 * time.Second),
|
||||
Value: 0.06,
|
||||
Unit: time.Duration(1 * time.Minute),
|
||||
Increment: time.Duration(1 * time.Second),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
if rcv, err := ldr.dm.GetRateProfile("cgrates.org", "RP1",
|
||||
true, false, utils.NonTransactional); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(rcv, eRatePrf) {
|
||||
t.Errorf("expecting: %+v,\n received: %+v", utils.ToJSON(eRatePrf), utils.ToJSON(rcv))
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user