Refactored versions and added tests

This commit is contained in:
edwardro22
2017-09-06 18:48:02 +00:00
parent 7cb965963b
commit 4cd54e9ab7
12 changed files with 336 additions and 135 deletions

View File

@@ -29,7 +29,7 @@ import (
)
var (
migrate = flag.String("migrate", "", "Fire up automatic migration <*cost_details|*set_versions>")
migrate = flag.String("migrate", "", "Fire up automatic migration <*set_versions|*cost_details|*accounts|*actions|*action_triggers|*action_plans|*shared_groups>")
version = flag.Bool("version", false, "Prints the application version.")
dataDBType = flag.String("datadb_type", config.CgrConfig().DataDbType, "The type of the DataDb database <redis>")

View File

@@ -1928,19 +1928,18 @@ func testOnStorITCRUDResource(t *testing.T) {
}
func testOnStorITCRUDStructVersion(t *testing.T) {
CurrentVersion:=Versions{utils.Accounts: 2,utils.Actions: 2,utils.ActionTriggers: 2,utils.ActionPlans: 2,utils.SharedGroups: 2,utils.COST_DETAILS: 2}
CurrentVersion := Versions{utils.Accounts: 2, utils.Actions: 2, utils.ActionTriggers: 2, utils.ActionPlans: 2, utils.SharedGroups: 2, utils.COST_DETAILS: 2}
if _, rcvErr := onStor.GetVersions(utils.TBLVersions); rcvErr != utils.ErrNotFound {
t.Error(rcvErr)
}
if err := onStor.SetVersions(CurrentVersion,false); err != nil {
if err := onStor.SetVersions(CurrentVersion, false); err != nil {
t.Error(err)
}
if rcv, err := onStor.GetVersions(utils.TBLVersions); err != nil {
t.Error(err)
} else if !reflect.DeepEqual(CurrentVersion, rcv) {
t.Errorf("Expecting: %v, received: %v", CurrentVersion, rcv)
}else if err = onStor.RemoveVersions(rcv); err != nil {
} else if err = onStor.RemoveVersions(rcv); err != nil {
t.Error(err)
}
if _, rcvErr := onStor.GetVersions(utils.TBLVersions); rcvErr != utils.ErrNotFound {

View File

@@ -1500,33 +1500,35 @@ func (ms *MapStorage) GetVersions(itm string) (vrs Versions, err error) {
func (ms *MapStorage) SetVersions(vrs Versions, overwrite bool) (err error) {
ms.mu.Lock()
defer ms.mu.Unlock()
var result []byte
var result []byte
var x Versions
if !overwrite{
x,err =ms.GetVersions(utils.TBLVersions)
if err != nil {
return err
if !overwrite {
x, err = ms.GetVersions(utils.TBLVersions)
if err != nil {
return err
}
for key, _ := range vrs {
if x[key] != vrs[key] {
x[key] = vrs[key]
}
}
result, err = ms.ms.Marshal(x)
if err != nil {
return err
}
ms.dict[utils.TBLVersions] = result
return
} else {
result, err = ms.ms.Marshal(vrs)
if err != nil {
return err
}
if ms.RemoveVersions(vrs); err != nil {
return err
}
ms.dict[utils.TBLVersions] = result
return
}
for key,_:= range vrs{
if x[key]!=vrs[key]{x[key]=vrs[key]}
}
result, err = ms.ms.Marshal(x)
if err != nil {
return err
}
ms.dict[utils.TBLVersions] = result
return
}else{
result, err = ms.ms.Marshal(vrs)
if err != nil {
return err
}
if ms.RemoveVersions(vrs);err != nil {
return err
}
ms.dict[utils.TBLVersions] = result
return
}
}
func (ms *MapStorage) RemoveVersions(vrs Versions) (err error) {
ms.mu.Lock()

View File

@@ -1199,9 +1199,8 @@ func (ms *MongoStorage) SetTPThreshold(tpTHs []*utils.TPThreshold) (err error) {
return
}
func (ms *MongoStorage) GetVersions(itm string) (vrs Versions, err error) {
session, col := ms.conn(colVer)
session, col := ms.conn(colVer)
defer session.Close()
if err = col.Find(bson.M{}).One(&vrs); err != nil {
if err == mgo.ErrNotFound {
@@ -1216,14 +1215,14 @@ func (ms *MongoStorage) SetVersions(vrs Versions, overwrite bool) (err error) {
session, col := ms.conn(colVer)
defer session.Close()
if overwrite {
if err=ms.RemoveVersions(vrs);err!=nil{
return err
if err = ms.RemoveVersions(vrs); err != nil {
return err
}
}
if _, err = col.Upsert(bson.M{},&vrs);err!=nil{
return
}
if _, err = col.Upsert(bson.M{}, &vrs); err != nil {
return
}
return
}
@@ -1232,9 +1231,9 @@ func (ms *MongoStorage) RemoveVersions(vrs Versions) (err error) {
defer session.Close()
err = col.Remove(bson.M{})
if err == mgo.ErrNotFound {
err = utils.ErrNotFound
}else{
return err
}
err = utils.ErrNotFound
} else {
return err
}
return nil
}
}

View File

@@ -1560,31 +1560,32 @@ func (rs *RedisStorage) MatchReqFilterIndex(dbKey, fldName, fldVal string) (item
func (rs *RedisStorage) GetVersions(itm string) (vrs Versions, err error) {
x, err := rs.Cmd("HGETALL", itm).Map()
if err != nil {
return
} else if len(x) == 0 {
return nil, err
}
vrs, err = utils.MapStringToInt64(x)
if err != nil {
return nil, err
}
if len(vrs) == 0 {
return nil, utils.ErrNotFound
}
vrs,err = utils.MapStringToInt64(x)
if err != nil {
return
}
return
return
}
func (rs *RedisStorage) SetVersions(vrs Versions, overwrite bool) (err error) {
if overwrite{
if err=rs.RemoveVersions(vrs);err!=nil{
return
if overwrite {
if err = rs.RemoveVersions(vrs); err != nil {
return
}
}
}
return rs.Cmd("HMSET", utils.TBLVersions, vrs).Err
return rs.Cmd("HMSET", utils.TBLVersions, vrs).Err
}
func (rs *RedisStorage) RemoveVersions(vrs Versions) (err error) {
for key,_:=range vrs{
err = rs.Cmd("HDEL",utils.TBLVersions, key).Err
if err!=nil{
return err
for key, _ := range vrs {
err = rs.Cmd("HDEL", utils.TBLVersions, key).Err
if err != nil {
return err
}
}

View File

@@ -1593,7 +1593,7 @@ func (self *SQLStorage) GetTPThreshold(tpid, id string) ([]*utils.TPThreshold, e
// GetVersions returns slice of all versions or a specific version if tag is specified
func (self *SQLStorage) GetVersions(itm string) (vrs Versions, err error) {
q := self.db.Model(&TBLVersion{})
if itm != "" {
if itm != utils.TBLVersions && itm != "" {
q = self.db.Where(&TBLVersion{Item: itm})
}
var verModels []*TBLVersion
@@ -1604,6 +1604,10 @@ func (self *SQLStorage) GetVersions(itm string) (vrs Versions, err error) {
for _, verModel := range verModels {
vrs[verModel.Item] = verModel.Version
}
if len(vrs) == 0 {
return nil, utils.ErrNotFound
}
return
}

View File

@@ -1867,19 +1867,23 @@ func testStorDBitCRUDVersions(t *testing.T) {
} else if len(rcv) != 1 || rcv[utils.COST_DETAILS] != 2 {
t.Errorf("Received: %+v", rcv)
}
if _, err := storDB.GetVersions("UNKNOWN"); err != nil {
if _, err := storDB.GetVersions("UNKNOWN"); err != utils.ErrNotFound {
t.Error(err)
}
vrs = Versions{"UNKNOWN": 1}
if err := storDB.RemoveVersions(vrs); err != nil {
t.Error(err)
}
if err := storDB.RemoveVersions(nil); err != nil {
t.Error(err)
}
if rcv, err := storDB.GetVersions(""); err != nil {
if rcv, err := storDB.GetVersions(""); err != utils.ErrNotFound {
t.Error(err)
} else if len(rcv) != 0 {
} else if rcv != nil {
t.Errorf("Received: %+v", rcv)
}

View File

@@ -25,61 +25,54 @@ import (
)
func CheckVersions(storage Storage) error {
x:=Versions{utils.Accounts: 2,utils.Actions: 2,utils.ActionTriggers: 2,utils.ActionPlans: 2,utils.SharedGroups: 2,utils.COST_DETAILS: 2}
x := Versions{utils.Accounts: 2, utils.Actions: 2, utils.ActionTriggers: 2, utils.ActionPlans: 2, utils.SharedGroups: 2, utils.COST_DETAILS: 2}
// get current db version
if storage == nil {
storage = dataStorage
}
dbVersion, err := storage.GetVersions(utils.TBLVersions)
if err != nil {
// no data, write version
if err := storage.SetVersions(x,false); err != nil {
utils.Logger.Warning(fmt.Sprintf("Could not write current version to db: %v", err))
}
// no data, write version
if err := storage.SetVersions(x, false); err != nil {
utils.Logger.Warning(fmt.Sprintf("Could not write current version to db: %v", err))
}
} else {
// comparing versions
message:=dbVersion.Compare(x)
if len(message) > 0 {
message := dbVersion.Compare(x)
if len(message) > 0 {
// write the new values
msg := "Migration needed: please backup cgr data and run : "+message
utils.Logger.Crit(msg)
return errors.New(msg)
}
msg := "Migration needed: please backup cgr data and run : <" + message + ">"
utils.Logger.Crit(msg)
return errors.New(msg)
}
}
return nil
}
func (vers Versions)Compare(curent Versions) string{
x:=map[string]string{
utils.Accounts: "cgr-migrator -migrate=*accounts",
utils.Actions: "cgr-migrator -migrate=*actions",
utils.ActionTriggers: "cgr-migrator -migrate=*action_triggers",
utils.ActionPlans: "cgr-migrator -migrate=*action_plans",
utils.SharedGroups: "cgr-migrator -migrate=*shared_groups",
utils.COST_DETAILS: "cgr-migrator -migrate=*cost_details",
}
for x,val :=range x{
if vers[x]!=curent[x]{
return val
func (vers Versions) Compare(curent Versions) string {
x := map[string]string{
utils.Accounts: "cgr-migrator -migrate=*accounts",
utils.Actions: "cgr-migrator -migrate=*actions",
utils.ActionTriggers: "cgr-migrator -migrate=*action_triggers",
utils.ActionPlans: "cgr-migrator -migrate=*action_plans",
utils.SharedGroups: "cgr-migrator -migrate=*shared_groups",
utils.COST_DETAILS: "cgr-migrator -migrate=*cost_details",
}
for x, val := range x {
if vers[x] != curent[x] {
return val
}
}
return ""
}
func CurrentStorDBVersions() Versions {
return Versions{utils.COST_DETAILS: 2}
}
func CurrentDataDBVersions() Versions {
return Versions{utils.Accounts: 2,utils.Actions: 2,utils.ActionTriggers: 2,utils.ActionPlans: 2,utils.SharedGroups: 2}
return Versions{utils.Accounts: 2, utils.Actions: 2, utils.ActionTriggers: 2, utils.ActionPlans: 2, utils.SharedGroups: 2}
}
// Versions will keep trac of various item versions

View File

@@ -24,26 +24,26 @@ import (
)
func TestVersionCompare(t *testing.T) {
x:=Versions{utils.Accounts: 2,utils.Actions: 2,utils.ActionTriggers: 2,utils.ActionPlans: 2,utils.SharedGroups: 2,utils.COST_DETAILS: 2}
y:=Versions{utils.Accounts: 1,utils.Actions: 2,utils.ActionTriggers: 2,utils.ActionPlans: 2,utils.SharedGroups: 2,utils.COST_DETAILS: 2}
z:=Versions{utils.Accounts: 2,utils.Actions: 2,utils.ActionTriggers: 2,utils.ActionPlans: 1,utils.SharedGroups: 2,utils.COST_DETAILS: 2}
q:=Versions{utils.Accounts: 2,utils.Actions: 2,utils.ActionTriggers: 2,utils.ActionPlans: 2,utils.SharedGroups: 1,utils.COST_DETAILS: 2}
c:=Versions{utils.Accounts: 2,utils.Actions: 2,utils.ActionTriggers: 2,utils.ActionPlans: 2,utils.SharedGroups: 2,utils.COST_DETAILS: 1}
x := Versions{utils.Accounts: 2, utils.Actions: 2, utils.ActionTriggers: 2, utils.ActionPlans: 2, utils.SharedGroups: 2, utils.COST_DETAILS: 2}
y := Versions{utils.Accounts: 1, utils.Actions: 2, utils.ActionTriggers: 2, utils.ActionPlans: 2, utils.SharedGroups: 2, utils.COST_DETAILS: 2}
z := Versions{utils.Accounts: 2, utils.Actions: 2, utils.ActionTriggers: 2, utils.ActionPlans: 1, utils.SharedGroups: 2, utils.COST_DETAILS: 2}
q := Versions{utils.Accounts: 2, utils.Actions: 2, utils.ActionTriggers: 2, utils.ActionPlans: 2, utils.SharedGroups: 1, utils.COST_DETAILS: 2}
c := Versions{utils.Accounts: 2, utils.Actions: 2, utils.ActionTriggers: 2, utils.ActionPlans: 2, utils.SharedGroups: 2, utils.COST_DETAILS: 1}
message1:=y.Compare(x)
if message1!="cgr-migrator -migrate=*accounts"{
t.Errorf("Error failed to compare to curent version expected: %s received: %s","cgr-migrator -migrate=*accounts", message1)
message1 := y.Compare(x)
if message1 != "cgr-migrator -migrate=*accounts" {
t.Errorf("Error failed to compare to curent version expected: %s received: %s", "cgr-migrator -migrate=*accounts", message1)
}
message2 := z.Compare(x)
if message2 != "cgr-migrator -migrate=*action_plans" {
t.Errorf("Error failed to compare to curent version expected: %s received: %s", "cgr-migrator -migrate=*action_plans", message2)
}
message3 := q.Compare(x)
if message3 != "cgr-migrator -migrate=*shared_groups" {
t.Errorf("Error failed to compare to curent version expected: %s received: %s", "cgr-migrator -migrate=*shared_groups", message3)
}
message4 := c.Compare(x)
if message4 != "cgr-migrator -migrate=*cost_details" {
t.Errorf("Error failed to compare to curent version expected: %s received: %s", "cgr-migrator -migrate=*cost_details", message4)
}
}
message2:=z.Compare(x)
if message2!="cgr-migrator -migrate=*action_plans"{
t.Errorf("Error failed to compare to curent version expected: %s received: %s","cgr-migrator -migrate=*action_plans", message2)
}
message3:=q.Compare(x)
if message3!="cgr-migrator -migrate=*shared_groups"{
t.Errorf("Error failed to compare to curent version expected: %s received: %s","cgr-migrator -migrate=*shared_groups", message3)
}
message4:=c.Compare(x)
if message4!="cgr-migrator -migrate=*cost_details"{
t.Errorf("Error failed to compare to curent version expected: %s received: %s","cgr-migrator -migrate=*cost_details", message4)
}
}

205
engine/versions_it_test.go Normal file
View File

@@ -0,0 +1,205 @@
// +build integration
/*
Real-time Online/Offline Charging System (OCS) for Telecom & ISP environments
Copyright (C) ITsysCOM GmbH
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package engine
import (
"flag"
"github.com/cgrates/cgrates/config"
"github.com/cgrates/cgrates/utils"
"log"
"path"
"testing"
)
var (
storageDb Storage
dataDb DataDB
dbtype string
loadHistorySize = flag.Int("load_history_size", config.CgrConfig().LoadHistorySize, "Limit the number of records in the load history")
)
var sTestsITVersions = []func(t *testing.T){
testVersionsFlush,
TestVersion,
testVersionsFlush,
}
func TestVersionsITMongoConnect(t *testing.T) {
cdrsMongoCfgPath := path.Join(*dataDir, "conf", "samples", "tutmongo")
cfg, err := config.NewCGRConfigFromFolder(cdrsMongoCfgPath)
if err != nil {
t.Fatal(err)
}
dataDB, err := ConfigureDataStorage(cfg.DataDbType, cfg.DataDbHost, cfg.DataDbPort, cfg.DataDbName, cfg.DataDbUser, cfg.DataDbPass, cfg.DBDataEncoding, cfg.CacheConfig, *loadHistorySize)
if err != nil {
log.Fatal(err)
}
storDB, err := ConfigureStorStorage(cfg.StorDBType, cfg.StorDBHost, cfg.StorDBPort, cfg.StorDBName, cfg.StorDBUser, cfg.StorDBPass, cfg.DBDataEncoding,
config.CgrConfig().StorDBMaxOpenConns, config.CgrConfig().StorDBMaxIdleConns, config.CgrConfig().StorDBConnMaxLifetime, config.CgrConfig().StorDBCDRSIndexes)
if err != nil {
log.Fatal(err)
}
storageDb = storDB
dataDb = dataDB
}
func TestVersionsITMongo(t *testing.T) {
dbtype = utils.MONGO
for _, stest := range sTestsITVersions {
t.Run("TestVersionsITMongo", stest)
}
}
func TestVersionsITRedisConnect(t *testing.T) {
cdrsMysqlCfgPath := path.Join(*dataDir, "conf", "samples", "tutmysql")
cfg, err := config.NewCGRConfigFromFolder(cdrsMysqlCfgPath)
if err != nil {
t.Fatal(err)
}
dataDB, err := ConfigureDataStorage(cfg.DataDbType, cfg.DataDbHost, cfg.DataDbPort, cfg.DataDbName, cfg.DataDbUser, cfg.DataDbPass, cfg.DBDataEncoding, cfg.CacheConfig, *loadHistorySize)
if err != nil {
log.Fatal(err)
}
storDB, err := ConfigureStorStorage(cfg.StorDBType, cfg.StorDBHost, cfg.StorDBPort, cfg.StorDBName, cfg.StorDBUser, cfg.StorDBPass, cfg.DBDataEncoding,
config.CgrConfig().StorDBMaxOpenConns, config.CgrConfig().StorDBMaxIdleConns, config.CgrConfig().StorDBConnMaxLifetime, config.CgrConfig().StorDBCDRSIndexes)
if err != nil {
log.Fatal(err)
}
storageDb = storDB
dataDb = dataDB
}
func TestVersionsITRedis(t *testing.T) {
dbtype = utils.REDIS
for _, stest := range sTestsITVersions {
t.Run("TestVersionsITRedis", stest)
}
}
func TestVersionsITPostgresConnect(t *testing.T) {
cdrsPostgresCfgPath := path.Join(*dataDir, "conf", "samples", "tutpostgres")
cfg, err := config.NewCGRConfigFromFolder(cdrsPostgresCfgPath)
if err != nil {
t.Fatal(err)
}
dataDB, err := ConfigureDataStorage(cfg.DataDbType, cfg.DataDbHost, cfg.DataDbPort, cfg.DataDbName, cfg.DataDbUser, cfg.DataDbPass, cfg.DBDataEncoding, cfg.CacheConfig, *loadHistorySize)
if err != nil {
log.Fatal(err)
}
storDB, err := ConfigureStorStorage(cfg.StorDBType, cfg.StorDBHost, cfg.StorDBPort, cfg.StorDBName, cfg.StorDBUser, cfg.StorDBPass, cfg.DBDataEncoding,
config.CgrConfig().StorDBMaxOpenConns, config.CgrConfig().StorDBMaxIdleConns, config.CgrConfig().StorDBConnMaxLifetime, config.CgrConfig().StorDBCDRSIndexes)
if err != nil {
log.Fatal(err)
}
storageDb = storDB
dataDb = dataDB
}
func TestMigratorITPostgres(t *testing.T) {
dbtype = utils.REDIS
for _, stest := range sTestsITVersions {
t.Run("TestMigratorITPostgres", stest)
}
}
func testVersionsFlush(t *testing.T) {
switch {
case dbtype == utils.REDIS:
dataDB := dataDb.(*RedisStorage)
err := dataDB.Cmd("FLUSHALL").Err
if err != nil {
t.Error("Error when flushing Redis ", err.Error())
}
if err := storDB.Flush(path.Join(cfg.DataFolderPath, "storage", cfg.StorDBType)); err != nil {
t.Error(err)
}
case dbtype == utils.MONGO:
err := dataDb.Flush("")
if err != nil {
t.Error("Error when flushing Mongo ", err.Error())
}
if err := storDB.Flush(path.Join(cfg.DataFolderPath, "storage", cfg.StorDBType)); err != nil {
t.Error(err)
}
}
}
func TestVersion(t *testing.T) {
test := "Migration needed: please backup cgr data and run : <cgr-migrator -migrate=*accounts>"
currentVersion := Versions{utils.Accounts: 2, utils.Actions: 2, utils.ActionTriggers: 2, utils.ActionPlans: 2, utils.SharedGroups: 2, utils.COST_DETAILS: 2}
testVersion := Versions{utils.Accounts: 1, utils.Actions: 2, utils.ActionTriggers: 2, utils.ActionPlans: 2, utils.SharedGroups: 2, utils.COST_DETAILS: 2}
//dataDB
if _, rcvErr := dataDb.GetVersions(utils.TBLVersions); rcvErr != utils.ErrNotFound {
t.Error(rcvErr)
}
if err := CheckVersions(dataDb); err != nil {
t.Error(err)
}
if rcv, err := dataDb.GetVersions(utils.TBLVersions); err != nil {
t.Error(err)
} else if len(currentVersion) != len(rcv) {
t.Errorf("Expecting: %v, received: %v", currentVersion, rcv)
}
if err = dataDb.RemoveVersions(currentVersion); err != nil {
t.Error(err)
}
if _, rcvErr := dataDb.GetVersions(utils.TBLVersions); rcvErr != utils.ErrNotFound {
t.Error(rcvErr)
}
if err := dataDb.SetVersions(testVersion, false); err != nil {
t.Error(err)
}
if err := CheckVersions(dataDb); err.Error() != test {
t.Error(err)
}
if err = dataDb.RemoveVersions(testVersion); err != nil {
t.Error(err)
}
//storDB
if _, rcvErr := storDb.GetVersions(utils.TBLVersions); rcvErr != utils.ErrNotFound {
t.Error(rcvErr)
}
if err := CheckVersions(storDb); err != nil {
t.Error(err)
}
if rcv, err := storDb.GetVersions(utils.TBLVersions); err != nil {
t.Error(err)
} else if len(currentVersion) != len(rcv) {
t.Errorf("Expecting: %v, received: %v", currentVersion, rcv)
}
if err = storDb.RemoveVersions(currentVersion); err != nil {
t.Error(err)
}
if _, rcvErr := storDb.GetVersions(utils.TBLVersions); rcvErr != utils.ErrNotFound {
t.Error(rcvErr)
}
if err := storDb.SetVersions(testVersion, false); err != nil {
t.Error(err)
}
if err := CheckVersions(storDb); err.Error() != test {
t.Error(err)
}
if err = storDb.RemoveVersions(testVersion); err != nil {
t.Error(err)
}
}

View File

@@ -30,29 +30,24 @@ import (
)
var (
mongo *config.CGRConfig
rdsITdb *engine.RedisStorage
mgoITdb *engine.MongoStorage
onStor engine.DataDB
onStorCfg string
dbtype string
mig *Migrator
dataDir = flag.String("data_dir", "/usr/share/cgrates", "CGR data dir path here")
loadHistorySize = flag.Int("load_history_size", config.CgrConfig().LoadHistorySize, "Limit the number of records in the load history")
dbtype string
mig *Migrator
dataDir = flag.String("data_dir", "/usr/share/cgrates", "CGR data dir path here")
loadHistorySize = flag.Int("load_history_size", config.CgrConfig().LoadHistorySize, "Limit the number of records in the load history")
)
// subtests to be executed for each migrator
var sTestsITMigrator = []func(t *testing.T){
testOnStorITFlush,
testFlush,
testMigratorAccounts,
testMigratorActionPlans,
testMigratorActionTriggers,
testMigratorActions,
testMigratorSharedGroups,
testOnStorITFlush,
testFlush,
}
func TestOnStorITPostgresConnect(t *testing.T) {
func TestMigratorITPostgresConnect(t *testing.T) {
cdrsPostgresCfgPath := path.Join(*dataDir, "conf", "samples", "tutpostgres")
postgresITCfg, err := config.NewCGRConfigFromFolder(cdrsPostgresCfgPath)
if err != nil {
@@ -82,15 +77,14 @@ func TestOnStorITPostgresConnect(t *testing.T) {
}
}
func TestOnStorITPostgres(t *testing.T) {
func TestMigratorITPostgres(t *testing.T) {
dbtype = utils.REDIS
for _, stest := range sTestsITMigrator {
t.Run("TestITMigratorOnPostgres", stest)
}
}
func TestOnStorITRedisConnect(t *testing.T) {
func TestMigratorITRedisConnect(t *testing.T) {
cdrsMysqlCfgPath := path.Join(*dataDir, "conf", "samples", "tutmysql")
mysqlITCfg, err := config.NewCGRConfigFromFolder(cdrsMysqlCfgPath)
if err != nil {
@@ -120,14 +114,14 @@ func TestOnStorITRedisConnect(t *testing.T) {
}
}
func TestOnStorITRedis(t *testing.T) {
func TestMigratorITRedis(t *testing.T) {
dbtype = utils.REDIS
for _, stest := range sTestsITMigrator {
t.Run("TestITMigratorOnRedis", stest)
}
}
func TestOnStorITMongoConnect(t *testing.T) {
func TestMigratorITMongoConnect(t *testing.T) {
cdrsMongoCfgPath := path.Join(*dataDir, "conf", "samples", "tutmongo")
mgoITCfg, err := config.NewCGRConfigFromFolder(cdrsMongoCfgPath)
if err != nil {
@@ -157,14 +151,14 @@ func TestOnStorITMongoConnect(t *testing.T) {
}
}
func TestOnStorITMongo(t *testing.T) {
func TestMigratorITMongo(t *testing.T) {
dbtype = utils.MONGO
for _, stest := range sTestsITMigrator {
t.Run("TestITMigratorOnMongo", stest)
}
}
func testOnStorITFlush(t *testing.T) {
func testFlush(t *testing.T) {
switch {
case dbtype == utils.REDIS:
dataDB := mig.dataDB.(*engine.RedisStorage)

View File

@@ -19,4 +19,4 @@ package migrator
// type v1StorDB interface {
// }
// }