Completing validators basic tests

This commit is contained in:
DanB
2013-12-04 20:46:39 +01:00
parent 131997507d
commit a3d4b9dd8b
2 changed files with 226 additions and 3 deletions

View File

@@ -1,5 +1,4 @@
#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
#WARN_HTTP,*call_url,,,,,,,,http://localhost:8000,10
#LOG_BALANCE,*log,,,,,,,,,10
1 #ActionsTag Action BalanceType Direction Units ExpiryTime DestinationTag RatingSubject BalanceWeight ExtraParameters Weight
2 PREPAID_10 *topup_reset *monetary *out 10 *unlimited *any 10 10
3 WARN_HTTP #WARN_HTTP *call_url http://localhost:8000 10
4 LOG_BALANCE #LOG_BALANCE *log 10

View File

@@ -106,6 +106,230 @@ func TestTimingsValidator(t *testing.T) {
}
}
}
func TestDestinationsValidator(t *testing.T) {
reader := bufio.NewReader(strings.NewReader(destsSample))
lnValidator := FileValidators[utils.DESTINATIONS_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", string(ln))
}
case 2,4:
if !valid {
t.Error("Validation did not pass for valid line", string(ln))
}
}
}
}
func TestRatesValidator(t *testing.T) {
reader := bufio.NewReader(strings.NewReader(ratesSample))
lnValidator := FileValidators[utils.RATES_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", string(ln))
}
case 2:
if !valid {
t.Error("Validation did not pass for valid line", string(ln))
}
}
}
}
func TestDestRatesValidator(t *testing.T) {
reader := bufio.NewReader(strings.NewReader(destRatesSample))
lnValidator := FileValidators[utils.DESTINATION_RATES_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", string(ln))
}
case 2:
if !valid {
t.Error("Validation did not pass for valid line", string(ln))
}
}
}
}
func TestRatingPlansValidator(t *testing.T) {
reader := bufio.NewReader(strings.NewReader(ratingPlansSample))
lnValidator := FileValidators[utils.RATING_PLANS_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", string(ln))
}
case 2:
if !valid {
t.Error("Validation did not pass for valid line", string(ln))
}
}
}
}
func TestRatingProfilesValidator(t *testing.T) {
reader := bufio.NewReader(strings.NewReader(ratingProfilesSample))
lnValidator := FileValidators[utils.RATING_PROFILES_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", string(ln))
}
case 2:
if !valid {
t.Error("Validation did not pass for valid line", string(ln))
}
}
}
}
func TestActionsValidator(t *testing.T) {
reader := bufio.NewReader(strings.NewReader(actionsSample))
lnValidator := FileValidators[utils.ACTIONS_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, 5:
if valid {
t.Error("Validation passed for invalid line", string(ln))
}
case 2,3,4:
if !valid {
t.Error("Validation did not pass for valid line", string(ln))
}
}
}
}
func TestActionTimingsValidator(t *testing.T) {
reader := bufio.NewReader(strings.NewReader(actionTimingsSample))
lnValidator := FileValidators[utils.ACTION_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", string(ln))
}
case 2:
if !valid {
t.Error("Validation did not pass for valid line", string(ln))
}
}
}
}
func TestActionTriggersValidator(t *testing.T) {
reader := bufio.NewReader(strings.NewReader(actionTriggersSample))
lnValidator := FileValidators[utils.ACTION_TRIGGERS_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, 5:
if valid {
t.Error("Validation passed for invalid line", string(ln))
}
case 2,3,4:
if !valid {
t.Error("Validation did not pass for valid line", string(ln))
}
}
}
}
func TestAccountActionsValidator(t *testing.T) {
reader := bufio.NewReader(strings.NewReader(accountActionsSample))
lnValidator := FileValidators[utils.ACCOUNT_ACTIONS_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", string(ln))
}
case 2:
if !valid {
t.Error("Validation did not pass for valid line", string(ln))
}
}
}
}
func TestTPCSVFileParser(t *testing.T) {