more checks for tags existance

This commit is contained in:
Radu Ioan Fericean
2015-06-10 20:49:19 +03:00
parent 5903b40e83
commit c732a18ae9
3 changed files with 32 additions and 4 deletions

View File

@@ -38,6 +38,7 @@ func TestHistoryDestinations(t *testing.T) {
buf := scribe.GetBuffer(history.DESTINATIONS_FN)
expected := `[{"Id":"ALL","Prefixes":["49","41","43"]},
{"Id":"DST_UK_Mobile_BIG5","Prefixes":["447956"]},
{"Id":"EU_LANDLINE","Prefixes":["444"]},
{"Id":"GERMANY","Prefixes":["49"]},
{"Id":"GERMANY_O2","Prefixes":["41"]},
{"Id":"GERMANY_PREMIUM","Prefixes":["43"]},

View File

@@ -47,6 +47,7 @@ PSTN_72,+4972
PSTN_70,+4970
DST_UK_Mobile_BIG5,447956
URG,112
EU_LANDLINE,444
`
timings = `
WORKDAYS_00,*any,*any,*any,1;2;3;4;5,00:00:00
@@ -136,6 +137,7 @@ RP_MX,MX_FREE,WORKDAYS_18,10
*out,cgrates.org,call,discounted_minutes,2013-01-06T00:00:00Z,RP_UK_Mobile_BIG5_PKG,,
*out,cgrates.org,data,rif,2013-01-06T00:00:00Z,RP_DATA,,
*out,cgrates.org,call,max,2013-03-23T00:00:00Z,RP_MX,,
*in,cgrates.org,LCR_STANDARD,max,2013-03-23T00:00:00Z,RP_MX,,
`
sharedGroups = `
SG1,*any,*lowest,
@@ -260,7 +262,7 @@ func init() {
}
func TestLoadDestinations(t *testing.T) {
if len(csvr.destinations) != 11 {
if len(csvr.destinations) != 12 {
t.Error("Failed to load destinations: ", len(csvr.destinations))
}
for _, d := range csvr.destinations {
@@ -732,7 +734,7 @@ func TestLoadRatingPlans(t *testing.T) {
}
func TestLoadRatingProfiles(t *testing.T) {
if len(csvr.ratingProfiles) != 18 {
if len(csvr.ratingProfiles) != 19 {
t.Error("Failed to load rating profiles: ", len(csvr.ratingProfiles), csvr.ratingProfiles)
}
rp := csvr.ratingProfiles["*out:test:0:trp"]

View File

@@ -374,6 +374,28 @@ func (tpr *TpReader) LoadLCRs() (err error) {
}
for _, tpLcr := range tps {
// check the rating profiles
ratingProfileSearchKey := utils.ConcatenatedKey(tpLcr.Direction, tpLcr.Tenant, tpLcr.RpCategory)
found := false
for rpfKey := range tpr.ratingProfiles {
if strings.HasPrefix(rpfKey, ratingProfileSearchKey) {
found = true
break
}
}
if !found {
if keys, err := tpr.ratingStorage.GetKeysForPrefix(RATING_PROFILE_PREFIX + ratingProfileSearchKey); err != nil || len(keys) == 0 {
return fmt.Errorf("[LCR] could not find ratingProfiles with prefix %s", ratingProfileSearchKey)
}
}
// check destination tags
if tpLcr.DestinationTag != "" && tpLcr.DestinationTag != utils.ANY {
if _, found := tpr.destinations[tpLcr.DestinationTag]; !found {
if found, err := tpr.ratingStorage.HasData(DESTINATION_PREFIX, tpLcr.DestinationTag); err != nil || !found {
return fmt.Errorf("[LCR] could not find destination with tag %s", tpLcr.DestinationTag)
}
}
}
tag := utils.LCRKey(tpLcr.Direction, tpLcr.Tenant, tpLcr.Category, tpLcr.Account, tpLcr.Subject)
activationTime, _ := utils.ParseTimeDetectLayout(tpLcr.ActivationTime)
@@ -485,11 +507,14 @@ func (tpr *TpReader) LoadActionPlans() (err error) {
_, exists := tpr.actions[at.ActionsId]
if !exists {
return fmt.Errorf("actionTiming: Could not load the action for tag: %v", at.ActionsId)
if dbExists, err := tpr.ratingStorage.HasData(ACTION_PREFIX, at.ActionsId); err != nil || !dbExists {
return fmt.Errorf("[ActionPlans] Could not load the action for tag: %v",
at.ActionsId)
}
}
t, exists := tpr.timings[at.TimingId]
if !exists {
return fmt.Errorf("actionTiming: Could not load the timing for tag: %v", at.TimingId)
return fmt.Errorf("[ActionPlans] Could not load the timing for tag: %v", at.TimingId)
}
actTmg := &ActionPlan{
Uuid: utils.GenUUID(),