mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Testing regexp validators
This commit is contained in:
@@ -1,2 +1,5 @@
|
||||
#ActionsTag,Action,BalanceType,Direction,Units,ExpiryTime,DestinationTag,RatingSubject,BalanceWeight,ExtraParameters,Weight
|
||||
PREPAID_10,*topup_reset,*monetary,*out,10,*unlimited,*any,,10,,10
|
||||
WARN_HTTP,*call_url,,,,,,,,http://localhost:8000,10
|
||||
LOG_BALANCE,*log,,,,,,,,,10
|
||||
|
||||
|
||||
|
@@ -27,13 +27,89 @@ import (
|
||||
"bufio"
|
||||
)
|
||||
|
||||
var ratesTest = `#Tag,DestinationRatesTag,TimingTag,Weight
|
||||
var timingsSample = `#Tag,Years,Months,MonthDays,WeekDays,Time
|
||||
ALWAYS,*any,*any,*any,*any,00:00:00
|
||||
DUMMY,INVALID;DATA
|
||||
ASAP,*any,*any,*any,*any,*asap
|
||||
`
|
||||
|
||||
var destsSample = `#Tag,Prefix
|
||||
GERMANY,+49
|
||||
DUMMY,INVALID;DATA
|
||||
GERMANY_MOBILE,+4915
|
||||
`
|
||||
var ratesSample = `#Tag,DestinationRatesTag,TimingTag,Weight
|
||||
RT_1CENT,0,1,1s,1s,0s,*up,2
|
||||
DUMMY,INVALID;DATA
|
||||
`
|
||||
|
||||
var destRatesSample = `#Tag,DestinationsTag,RatesTag
|
||||
DR_RETAIL,GERMANY,RT_1CENT
|
||||
DUMMY,INVALID;DATA
|
||||
|
||||
`
|
||||
var ratingPlansSample = `#Tag,DestinationRatesTag,TimingTag,Weight
|
||||
RP_RETAIL,DR_RETAIL,ALWAYS,10
|
||||
DUMMY,INVALID;DATA
|
||||
`
|
||||
|
||||
var ratingProfilesSample = `#Tenant,TOR,Direction,Subject,ActivationTime,RatingPlanTag,FallbackSubject
|
||||
cgrates.org,call,*out,*any,2012-01-01T00:00:00Z,RP_RETAIL,
|
||||
DUMMY,INVALID;DATA
|
||||
`
|
||||
|
||||
var actionsSample = `#ActionsTag,Action,BalanceType,Direction,Units,ExpiryTime,DestinationTag,RatingSubject,BalanceWeight,ExtraParameters,Weight
|
||||
PREPAID_10,*topup_reset,*monetary,*out,5,*unlimited,*any,,10,,10
|
||||
WARN_HTTP,*call_url,,,,,,,,http://localhost:8000,10
|
||||
LOG_BALANCE,*log,,,,,,,,,10
|
||||
DUMMY,INVALID;DATA
|
||||
`
|
||||
|
||||
var actionTimingsSample = `#Tag,ActionsTag,TimingTag,Weight
|
||||
PREPAID_10,PREPAID_10,ASAP,10
|
||||
DUMMY,INVALID;DATA
|
||||
`
|
||||
|
||||
var actionTriggersSample = `#Tag,BalanceType,Direction,ThresholdType,ThresholdValue,DestinationTag,ActionsTag,Weight
|
||||
STANDARD_TRIGGERS,*monetary,*out,*min_balance,2,,LOG_BALANCE,10
|
||||
STANDARD_TRIGGERS,*monetary,*out,*max_balance,20,,LOG_BALANCE,10
|
||||
STANDARD_TRIGGERS,*monetary,*out,*max_counter,15,FS_USERS,LOG_BALANCE,10
|
||||
DUMMY,INVALID;DATA
|
||||
`
|
||||
|
||||
var accountActionsSample = `#Tenant,Account,Direction,ActionTimingsTag,ActionTriggersTag
|
||||
cgrates.org,1001,*out,PREPAID_10,STANDARD_TRIGGERS
|
||||
DUMMY,INVALID;DATA
|
||||
`
|
||||
|
||||
|
||||
func TestTimingsValidator(t *testing.T) {
|
||||
reader := bufio.NewReader(strings.NewReader(timingsSample))
|
||||
lnValidator := FileValidators[utils.TIMINGS_CSV]
|
||||
lineNr := 0
|
||||
for {
|
||||
lineNr++
|
||||
ln, _, err := reader.ReadLine()
|
||||
if err == io.EOF { // Reached end of the string
|
||||
break
|
||||
}
|
||||
valid := lnValidator.Rule.Match(ln)
|
||||
switch lineNr {
|
||||
case 1, 3:
|
||||
if valid {
|
||||
t.Error("Validation passed for invalid line", ln)
|
||||
}
|
||||
case 2,4:
|
||||
if !valid {
|
||||
t.Error("Validation did not pass for valid line", ln)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
func TestTPCSVFileParser(t *testing.T) {
|
||||
bfRdr := bufio.NewReader( strings.NewReader(ratesTest) )
|
||||
bfRdr := bufio.NewReader(strings.NewReader(ratesSample))
|
||||
fParser := &TPCSVFileParser{FileValidators[utils.RATES_CSV], bfRdr}
|
||||
lineNr := 0
|
||||
for {
|
||||
|
||||
Reference in New Issue
Block a user