mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Adding regexp rules for shared groups csv file
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
#Tag,ActionsTag,TimingTag,Weight
|
||||
PACKAGE_10,TOPUP_RST_10,ASAP,10
|
||||
PACKAGE_10_SHAREDA_5,TOPUP_RST_5,ASAP,10
|
||||
PACKAGE_10_SHAREDA_5,TOPUP_RST_SHARED_5,ASAP,10
|
||||
PACKAGE_10_SHARED_A_5,TOPUP_RST_5,ASAP,10
|
||||
PACKAGE_10_SHARED_A_5,TOPUP_RST_SHARED_5,ASAP,10
|
||||
USE_SHARED_A,SHARED_A_0,ASAP,10
|
||||
|
||||
|
@@ -1,3 +1,3 @@
|
||||
#Tenant,TOR,Direction,Subject,ActivationTime,RatingPlanTag,FallbackSubject
|
||||
cgrates.org,call,*out,*any,2014-01-14T00:00:00Z,RP_RETAIL1,
|
||||
cgrates.org,call,*out,1001,2014-01-14T00:00:00Z,RP_RETAIL2,
|
||||
cgrates.org,call,*out,1001;1006,2014-01-14T00:00:00Z,RP_RETAIL2,
|
||||
|
||||
|
@@ -692,7 +692,7 @@ func (csvr *CSVReader) LoadAccountActions() (err error) {
|
||||
csvr.accountActions[tag] = ub
|
||||
aTimings, exists := csvr.actionsTimings[record[3]]
|
||||
if !exists {
|
||||
log.Printf("Could not get action timing for tag %s", record[3])
|
||||
log.Printf("Could not get action plan for tag %s", record[3])
|
||||
// must not continue here
|
||||
}
|
||||
for _, at := range aTimings {
|
||||
|
||||
@@ -200,8 +200,8 @@ var FileValidators = map[string]*FileLineRegexValidator{
|
||||
regexp.MustCompile(`(?:\w+\s*,\s*){2}(?:\*out\s*,\s*){1}(?:\*any\s*,\s*|(\w+;?)+\s*,\s*){1}(?:\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z){1}(?:\w*\s*,?\s*){2}$`),
|
||||
"Tenant([0-9A-Za-z_]),TOR([0-9A-Za-z_]),Direction(*out),Subject([0-9A-Za-z_]|*all),RatesFallbackSubject([0-9A-Za-z_]|<empty>),RatesTimingTag([0-9A-Za-z_]),ActivationTime([0-9T:X])"},
|
||||
utils.SHARED_GROUPS_CSV: &FileLineRegexValidator{utils.SHARED_GROUPS_NRCOLS,
|
||||
regexp.MustCompile(``),
|
||||
""},
|
||||
regexp.MustCompile(`(?:\w+\s*),(?:\*?\w+\s*),(?:\*\w+\s*),(?:\*?\w+\s*)?`),
|
||||
"Id([0-9A-Za-z_]),Account(*?[0-9A-Za-z_]),Strategy(*[0-9A-Za-z_]),RatingSubject(*?[0-9A-Za-z_])"},
|
||||
utils.ACTIONS_CSV: &FileLineRegexValidator{utils.ACTIONS_NRCOLS,
|
||||
regexp.MustCompile(`^(?:\w+\s*),(?:\*\w+\s*),(?:\*\w+\s*)?,(?:\*out\s*)?,(?:\d+\s*)?,(?:\*\w+\s*|\+\d+[smh]\s*|\d+\s*)?,(?:\*any|\w+\s*)?,(?:\*?\w+\s*)?,(?:\d+\.?\d*\s*)?,(?:\w+\s*)?,(?:\S+\s*)?,(?:\d+\.?\d*\s*)$`),
|
||||
"Tag([0-9A-Za-z_]),Action([0-9A-Za-z_]),BalanceType([*a-z_]),Direction(*out),Units([0-9]),ExpiryTime(*[a-z_]|+[0-9][smh]|[0-9])DestinationTag([0-9A-Za-z_]|*all),RatingSubject([0-9A-Za-z_]),BalanceWeight([0-9.]),ExtraParameters([0-9A-Za-z_:;]),Weight([0-9.])"},
|
||||
|
||||
@@ -79,6 +79,11 @@ STANDARD_TRIGGERS,*monetary,*out,*max_counter,15,FS_USERS,LOG_BALANCE,10
|
||||
DUMMY,INVALID;DATA
|
||||
`
|
||||
|
||||
var sharedGroupsSample = `#Id,Account,Strategy,RatingSubject
|
||||
SHARED_A,*any,*lowest_first,
|
||||
DUMMY,INVALID;DATA
|
||||
`
|
||||
|
||||
var accountActionsSample = `#Tenant,Account,Direction,ActionTimingsTag,ActionTriggersTag
|
||||
cgrates.org,1001,*out,PREPAID_10,STANDARD_TRIGGERS
|
||||
DUMMY,INVALID;DATA
|
||||
@@ -301,6 +306,30 @@ func TestActionTriggersValidator(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestSharedGroupsValidator(t *testing.T) {
|
||||
reader := bufio.NewReader(strings.NewReader(sharedGroupsSample))
|
||||
lnValidator := FileValidators[utils.SHARED_GROUPS_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 TestAccountActionsValidator(t *testing.T) {
|
||||
reader := bufio.NewReader(strings.NewReader(accountActionsSample))
|
||||
lnValidator := FileValidators[utils.ACCOUNT_ACTIONS_CSV]
|
||||
|
||||
Reference in New Issue
Block a user