From 3f3cb5b3ce08fc58b794e819b97f949bd86867a4 Mon Sep 17 00:00:00 2001 From: Radu Ioan Fericean Date: Tue, 26 May 2015 20:55:19 +0300 Subject: [PATCH] fixes for local tests --- engine/loader_db.go | 6 ++++-- engine/storage_mysql_local_test.go | 4 +++- engine/storage_psql_local_test.go | 4 +++- engine/storage_sql.go | 16 +++------------- 4 files changed, 13 insertions(+), 17 deletions(-) diff --git a/engine/loader_db.go b/engine/loader_db.go index e02c51a1b..f445fb489 100644 --- a/engine/loader_db.go +++ b/engine/loader_db.go @@ -61,9 +61,11 @@ func (dbr *DbReader) WriteToDatabase(flush, verbose bool) (err error) { func (dbr *DbReader) LoadDestinations() (err error) { tpDests, err := dbr.storDb.GetTpDestinations(dbr.tpid, "") - if err == nil { - return + if err != nil { + log.Print("ERRRR: ", err) + return err } + log.Print("TpDESTS: ", tpDests) return dbr.tp.LoadDestinations(tpDests) } diff --git a/engine/storage_mysql_local_test.go b/engine/storage_mysql_local_test.go index e90951310..9c00e6354 100644 --- a/engine/storage_mysql_local_test.go +++ b/engine/storage_mysql_local_test.go @@ -89,7 +89,9 @@ func TestMySQLSetGetTPDestination(t *testing.T) { if err := mysqlDb.SetTPDestination(TEST_SQL, dst); err != nil { t.Error(err.Error()) } - if dsts, err := mysqlDb.GetTpDestinations(TEST_SQL, TEST_SQL); err != nil { + storData, err := mysqlDb.GetTpDestinations(TEST_SQL, TEST_SQL) + dsts := TpDestinations(storData).GetDestinations() + if err != nil { t.Error(err.Error()) } else if !reflect.DeepEqual(dst, dsts[TEST_SQL]) { t.Errorf("Expecting: %+v, received: %+v", dst, dsts[TEST_SQL]) diff --git a/engine/storage_psql_local_test.go b/engine/storage_psql_local_test.go index 04f18b52c..55a6e3465 100644 --- a/engine/storage_psql_local_test.go +++ b/engine/storage_psql_local_test.go @@ -89,7 +89,9 @@ func TestPSQLSetGetTPDestination(t *testing.T) { if err := psqlDb.SetTPDestination(TEST_SQL, dst); err != nil { t.Error(err.Error()) } - if dsts, err := psqlDb.GetTpDestinations(TEST_SQL, TEST_SQL); err != nil { + storData, err := psqlDb.GetTpDestinations(TEST_SQL, TEST_SQL) + dsts := TpDestinations(storData).GetDestinations() + if err != nil { t.Error(err.Error()) } else if len(dst.Prefixes) != len(dsts[TEST_SQL].Prefixes) { t.Errorf("Expecting: %+v, received: %+v", dst, dsts[TEST_SQL]) diff --git a/engine/storage_sql.go b/engine/storage_sql.go index f53487fd8..6d39cc23c 100644 --- a/engine/storage_sql.go +++ b/engine/storage_sql.go @@ -1186,9 +1186,8 @@ func (self *SQLStorage) RemStoredCdrs(cgrIds []string) error { return nil } -func (self *SQLStorage) GetTpDestinations(tpid, tag string) (map[string]*Destination, error) { - dests := make(map[string]*Destination) - var tpDests []TpDestination +func (self *SQLStorage) GetTpDestinations(tpid, tag string) ([]*TpDestination, error) { + var tpDests []*TpDestination q := self.db.Where("tpid = ?", tpid) if len(tag) != 0 { q = q.Where("tag = ?", tag) @@ -1197,16 +1196,7 @@ func (self *SQLStorage) GetTpDestinations(tpid, tag string) (map[string]*Destina return nil, err } - for _, tpDest := range tpDests { - var dest *Destination - var found bool - if dest, found = dests[tpDest.Tag]; !found { - dest = &Destination{Id: tpDest.Tag} - dests[tpDest.Tag] = dest - } - dest.AddPrefix(tpDest.Prefix) - } - return dests, nil + return tpDests, nil } func (self *SQLStorage) GetTpRates(tpid, tag string) (map[string]*utils.TPRate, error) {