mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Fixup tests
This commit is contained in:
@@ -52,35 +52,6 @@ func SetCgrConfig(cfg *CGRConfig) {
|
||||
cgrCfg = cfg
|
||||
}
|
||||
|
||||
type DerivedCharger struct {
|
||||
RunId string // Unique runId in the chain
|
||||
ReqTypeField string // Field containing request type info, number in case of csv source, '^' as prefix in case of static values
|
||||
DirectionField string // Field containing direction info
|
||||
TenantField string // Field containing tenant info
|
||||
TorField string // Field containing tor info
|
||||
AccountField string // Field containing account information
|
||||
SubjectField string // Field containing subject information
|
||||
DestinationField string // Field containing destination information
|
||||
SetupTimeField string // Field containing setup time information
|
||||
AnswerTimeField string // Field containing answer time information
|
||||
DurationField string // Field containing duration information
|
||||
}
|
||||
|
||||
type DerivedChargers []*DerivedCharger
|
||||
|
||||
// Precheck that RunId is unique
|
||||
func (dcs DerivedChargers) Append(dc *DerivedCharger) (DerivedChargers, error) {
|
||||
if dc.RunId == utils.DEFAULT_RUNID {
|
||||
return nil, errors.New("Reserved RunId")
|
||||
}
|
||||
for _, dcLocal := range dcs {
|
||||
if dcLocal.RunId == dc.RunId {
|
||||
return nil, errors.New("Duplicated RunId")
|
||||
}
|
||||
}
|
||||
return append(dcs, dc), nil
|
||||
}
|
||||
|
||||
// Holds system configuration, defaults are overwritten with values from config file if found
|
||||
type CGRConfig struct {
|
||||
RatingDBType string
|
||||
|
||||
@@ -37,27 +37,6 @@ func TestConfigSharing(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestAppendDerivedChargers(t *testing.T) {
|
||||
var err error
|
||||
dcs := make(DerivedChargers, 0)
|
||||
if _, err := dcs.Append(&DerivedCharger{RunId: utils.DEFAULT_RUNID}); err == nil {
|
||||
t.Error("Failed to detect using of the default runid")
|
||||
}
|
||||
if dcs, err = dcs.Append(&DerivedCharger{RunId: "FIRST_RUNID"}); err != nil {
|
||||
t.Error("Failed to add runid")
|
||||
} else if len(dcs) != 1 {
|
||||
t.Error("Unexpected number of items inside DerivedChargers configuration", len(dcs))
|
||||
}
|
||||
if dcs, err = dcs.Append(&DerivedCharger{RunId: "SECOND_RUNID"}); err != nil {
|
||||
t.Error("Failed to add runid")
|
||||
} else if len(dcs) != 2 {
|
||||
t.Error("Unexpected number of items inside DerivedChargers configuration", len(dcs))
|
||||
}
|
||||
if _, err := dcs.Append(&DerivedCharger{RunId: "SECOND_RUNID"}); err == nil {
|
||||
t.Error("Failed to detect duplicate runid")
|
||||
}
|
||||
}
|
||||
|
||||
// Make sure defaults did not change by mistake
|
||||
func TestDefaults(t *testing.T) {
|
||||
cfg := &CGRConfig{}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
Tenant,Tor,Direction,Account,Subject,RunId,ReqTypeField,DirectionField,TenantField,TorField,AccountField,SubjectField,DestinationField,SetupTimeField,AnswerTimeField,DurationField
|
||||
cgrates.org,call,*out,dan,dan,extra1,^prepaid,,,,rif,rif,,,,cgr_duration
|
||||
cgrates.org,call,*out,dan,dan,extra2,,,,,ivo,ivo,,,,
|
||||
cgrates.org,call,*out,*any,*any,extra1,,,,,rif2,rif2,,,,
|
||||
cgrates.org,call,*out,dan,*any,extra1,,,,,rif2,rif2,,,,
|
||||
|
||||
|
@@ -57,7 +57,9 @@ TOPUP10_AC1,*topup_reset,*minutes,*out,40,*unlimited,DST_UK_Mobile_BIG5,discount
|
||||
TOPUP10_AT,TOPUP10_AC1,ASAP,10`
|
||||
actionTriggers := ``
|
||||
accountActions := `cgrates.org,12345,*out,TOPUP10_AT,`
|
||||
csvr := engine.NewStringCSVReader(ratingDb, acntDb, ',', destinations, timings, rates, destinationRates, ratingPlans, ratingProfiles, sharedGroups, actions, actionPlans, actionTriggers, accountActions)
|
||||
derivedCharges := ``
|
||||
csvr := engine.NewStringCSVReader(ratingDb, acntDb, ',', destinations, timings, rates, destinationRates, ratingPlans, ratingProfiles,
|
||||
sharedGroups, actions, actionPlans, actionTriggers, accountActions, derivedCharges)
|
||||
if err := csvr.LoadDestinations(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -91,6 +93,9 @@ TOPUP10_AT,TOPUP10_AC1,ASAP,10`
|
||||
if err := csvr.LoadAccountActions(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := csvr.LoadDerivedChargers(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
csvr.WriteToDatabase(false, false)
|
||||
if acnt, err := acntDb.GetAccount("*out:cgrates.org:12345"); err != nil {
|
||||
t.Error(err)
|
||||
|
||||
@@ -57,7 +57,9 @@ TOPUP10_AC1,*topup_reset,*minutes,*out,40,*unlimited,DST_UK_Mobile_BIG5,discount
|
||||
TOPUP10_AT,TOPUP10_AC1,ASAP,10`
|
||||
actionTriggers := ``
|
||||
accountActions := `cgrates.org,12345,*out,TOPUP10_AT,`
|
||||
csvr := engine.NewStringCSVReader(ratingDb2, acntDb2, ',', destinations, timings, rates, destinationRates, ratingPlans, ratingProfiles, sharedGroups, actions, actionPlans, actionTriggers, accountActions)
|
||||
derivedCharges := ``
|
||||
csvr := engine.NewStringCSVReader(ratingDb2, acntDb2, ',', destinations, timings, rates, destinationRates, ratingPlans, ratingProfiles,
|
||||
sharedGroups, actions, actionPlans, actionTriggers, accountActions, derivedCharges)
|
||||
if err := csvr.LoadDestinations(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -91,6 +93,9 @@ TOPUP10_AT,TOPUP10_AC1,ASAP,10`
|
||||
if err := csvr.LoadAccountActions(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := csvr.LoadDerivedChargers(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
csvr.WriteToDatabase(false, false)
|
||||
if acnt, err := acntDb2.GetAccount("*out:cgrates.org:12345"); err != nil {
|
||||
t.Error(err)
|
||||
|
||||
@@ -55,7 +55,9 @@ cgrates.org,call,*out,discounted_minutes,2013-01-06T00:00:00Z,RP_UK_Mobile_BIG5_
|
||||
actionPlans := `TOPUP10_AT,TOPUP10_AC1,ASAP,10`
|
||||
actionTriggers := ``
|
||||
accountActions := `cgrates.org,12345,*out,TOPUP10_AT,`
|
||||
csvr := engine.NewStringCSVReader(ratingDb3, acntDb3, ',', destinations, timings, rates, destinationRates, ratingPlans, ratingProfiles, sharedGroups, actions, actionPlans, actionTriggers, accountActions)
|
||||
derivedCharges := ``
|
||||
csvr := engine.NewStringCSVReader(ratingDb3, acntDb3, ',', destinations, timings, rates, destinationRates, ratingPlans, ratingProfiles,
|
||||
sharedGroups, actions, actionPlans, actionTriggers, accountActions, derivedCharges)
|
||||
if err := csvr.LoadDestinations(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -89,6 +91,9 @@ cgrates.org,call,*out,discounted_minutes,2013-01-06T00:00:00Z,RP_UK_Mobile_BIG5_
|
||||
if err := csvr.LoadAccountActions(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := csvr.LoadDerivedChargers(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
csvr.WriteToDatabase(false, false)
|
||||
if acnt, err := acntDb3.GetAccount("*out:cgrates.org:12345"); err != nil {
|
||||
t.Error(err)
|
||||
|
||||
Reference in New Issue
Block a user