mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Adding local tests for TPImporter into stordb
This commit is contained in:
@@ -145,7 +145,7 @@ func main() {
|
||||
}
|
||||
loader = engine.NewFileCSVReader(dataDb, ',', utils.DESTINATIONS_CSV, utils.TIMINGS_CSV, utils.RATES_CSV, utils.DESTINATION_RATES_CSV, utils.RATING_PLANS_CSV, utils.RATING_PROFILES_CSV, utils.ACTIONS_CSV, utils.ACTION_TIMINGS_CSV, utils.ACTION_TRIGGERS_CSV, utils.ACCOUNT_ACTIONS_CSV)
|
||||
}
|
||||
|
||||
// ToDo: put these methods in loader package so we can properly test loads
|
||||
err = loader.LoadDestinations()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
|
||||
@@ -50,7 +50,8 @@ var testLocal = flag.Bool("local", false, "Perform the tests only on local test
|
||||
var dataDir = flag.String("data_dir", "/usr/share/cgrates/data", "CGR data dir path here")
|
||||
var tpCsvScenario = flag.String("tp_scenario", "prepaid1centpsec", "Use this scenario folder to import tp csv data from")
|
||||
|
||||
// Create connection to dataDb and flush it's data
|
||||
|
||||
// Create connection to dataDb
|
||||
// Will use 3 different datadbs in order to be able to see differences in data loaded
|
||||
func TestConnDataDbs(t *testing.T) {
|
||||
if !*testLocal {
|
||||
@@ -97,7 +98,7 @@ func TestLoadFromCSV(t *testing.T) {
|
||||
t.Error("Failed validating data: ", err.Error())
|
||||
}
|
||||
}
|
||||
loader := NewFileCSVReader(dataDbCsv, ',',
|
||||
loader := NewFileCSVReader(dataDbCsv, utils.CSV_SEP,
|
||||
path.Join(*dataDir, "tariffplans", *tpCsvScenario, utils.DESTINATIONS_CSV),
|
||||
path.Join(*dataDir, "tariffplans", *tpCsvScenario, utils.TIMINGS_CSV),
|
||||
path.Join(*dataDir, "tariffplans", *tpCsvScenario, utils.RATES_CSV),
|
||||
@@ -144,3 +145,19 @@ func TestLoadFromCSV(t *testing.T) {
|
||||
t.Error("Could not write data into dataDb: ", err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
func TestLoadToStorDb(t *testing.T) {
|
||||
if !*testLocal {
|
||||
return
|
||||
}
|
||||
csvImporter := TPCSVImporter{TEST_SQL, storDb, path.Join(*dataDir, "tariffplans", *tpCsvScenario), utils.CSV_SEP, false, TEST_SQL}
|
||||
if err := csvImporter.Run(); err != nil {
|
||||
t.Error("Error when importing tpdata to storDb: ", err)
|
||||
}
|
||||
if tpids, err := storDb.GetTPIds(); err != nil {
|
||||
t.Error("Error when querying storDb for imported data: ", err)
|
||||
} else if len(tpids) != 1 || tpids[0] != TEST_SQL {
|
||||
t.Errorf("Data in storDb is different than expected %v", tpids)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,7 +65,9 @@ func (self *TPCSVImporter) Run() error {
|
||||
|
||||
// Handler importing timings from file, saved row by row to storDb
|
||||
func (self *TPCSVImporter) importTimings(fn string) error {
|
||||
log.Printf("Processing file: <%s> ", fn)
|
||||
if self.Verbose {
|
||||
log.Printf("Processing file: <%s> ", fn)
|
||||
}
|
||||
fParser, err := NewTPCSVFileParser(self.DirPath, fn)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -93,7 +95,9 @@ func (self *TPCSVImporter) importTimings(fn string) error {
|
||||
}
|
||||
|
||||
func (self *TPCSVImporter) importDestinations(fn string) error {
|
||||
log.Printf("Processing file: <%s> ", fn)
|
||||
if self.Verbose {
|
||||
log.Printf("Processing file: <%s> ", fn)
|
||||
}
|
||||
fParser, err := NewTPCSVFileParser(self.DirPath, fn)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -121,7 +125,9 @@ func (self *TPCSVImporter) importDestinations(fn string) error {
|
||||
}
|
||||
|
||||
func (self *TPCSVImporter) importRates(fn string) error {
|
||||
log.Printf("Processing file: <%s> ", fn)
|
||||
if self.Verbose {
|
||||
log.Printf("Processing file: <%s> ", fn)
|
||||
}
|
||||
fParser, err := NewTPCSVFileParser(self.DirPath, fn)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -152,7 +158,9 @@ func (self *TPCSVImporter) importRates(fn string) error {
|
||||
}
|
||||
|
||||
func (self *TPCSVImporter) importDestinationRates(fn string) error {
|
||||
log.Printf("Processing file: <%s> ", fn)
|
||||
if self.Verbose {
|
||||
log.Printf("Processing file: <%s> ", fn)
|
||||
}
|
||||
fParser, err := NewTPCSVFileParser(self.DirPath, fn)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -186,7 +194,9 @@ func (self *TPCSVImporter) importDestinationRates(fn string) error {
|
||||
}
|
||||
|
||||
func (self *TPCSVImporter) importRatingPlans(fn string) error {
|
||||
log.Printf("Processing file: <%s> ", fn)
|
||||
if self.Verbose {
|
||||
log.Printf("Processing file: <%s> ", fn)
|
||||
}
|
||||
fParser, err := NewTPCSVFileParser(self.DirPath, fn)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -227,7 +237,9 @@ func (self *TPCSVImporter) importRatingPlans(fn string) error {
|
||||
}
|
||||
|
||||
func (self *TPCSVImporter) importRatingProfiles(fn string) error {
|
||||
log.Printf("Processing file: <%s> ", fn)
|
||||
if self.Verbose {
|
||||
log.Printf("Processing file: <%s> ", fn)
|
||||
}
|
||||
fParser, err := NewTPCSVFileParser(self.DirPath, fn)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -275,7 +287,9 @@ func (self *TPCSVImporter) importRatingProfiles(fn string) error {
|
||||
}
|
||||
|
||||
func (self *TPCSVImporter) importActions(fn string) error {
|
||||
log.Printf("Processing file: <%s> ", fn)
|
||||
if self.Verbose {
|
||||
log.Printf("Processing file: <%s> ", fn)
|
||||
}
|
||||
fParser, err := NewTPCSVFileParser(self.DirPath, fn)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -330,7 +344,9 @@ func (self *TPCSVImporter) importActions(fn string) error {
|
||||
}
|
||||
|
||||
func (self *TPCSVImporter) importActionTimings(fn string) error {
|
||||
log.Printf("Processing file: <%s> ", fn)
|
||||
if self.Verbose {
|
||||
log.Printf("Processing file: <%s> ", fn)
|
||||
}
|
||||
fParser, err := NewTPCSVFileParser(self.DirPath, fn)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -372,7 +388,9 @@ func (self *TPCSVImporter) importActionTimings(fn string) error {
|
||||
}
|
||||
|
||||
func (self *TPCSVImporter) importActionTriggers(fn string) error {
|
||||
log.Printf("Processing file: <%s> ", fn)
|
||||
if self.Verbose {
|
||||
log.Printf("Processing file: <%s> ", fn)
|
||||
}
|
||||
fParser, err := NewTPCSVFileParser(self.DirPath, fn)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -423,7 +441,9 @@ func (self *TPCSVImporter) importActionTriggers(fn string) error {
|
||||
}
|
||||
|
||||
func (self *TPCSVImporter) importAccountActions(fn string) error {
|
||||
log.Printf("Processing file: <%s> ", fn)
|
||||
if self.Verbose {
|
||||
log.Printf("Processing file: <%s> ", fn)
|
||||
}
|
||||
fParser, err := NewTPCSVFileParser(self.DirPath, fn)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -57,6 +57,7 @@ const (
|
||||
ROUNDING_MIDDLE = "*middle"
|
||||
ROUNDING_DOWN = "*down"
|
||||
COMMENT_CHAR = '#'
|
||||
CSV_SEP = ','
|
||||
FALLBACK_SEP = ';'
|
||||
JSON = "json"
|
||||
MSGPACK = "msgpack"
|
||||
|
||||
Reference in New Issue
Block a user