mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 10:06:24 +05:00
Removing ActionS
This commit is contained in:
committed by
Dan Christian Bogos
parent
a2bde1ad6e
commit
ce915c77a6
@@ -1,95 +0,0 @@
|
||||
/*
|
||||
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 migrator
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/cgrates/cgrates/engine"
|
||||
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
)
|
||||
|
||||
func (m *Migrator) migrateCurrentActionProfiles() (err error) {
|
||||
var ids []string
|
||||
ids, err = m.dmIN.DataManager().DataDB().GetKeysForPrefix(utils.ActionProfilePrefix)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, id := range ids {
|
||||
tntID := strings.SplitN(strings.TrimPrefix(id, utils.ActionProfilePrefix), utils.InInFieldSep, 2)
|
||||
if len(tntID) < 2 {
|
||||
return fmt.Errorf("Invalid key <%s> when migrating from action profiles", id)
|
||||
}
|
||||
ap, err := m.dmIN.DataManager().GetActionProfile(tntID[0], tntID[1], false, false, utils.NonTransactional)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if ap == nil || m.dryRun {
|
||||
continue
|
||||
}
|
||||
if err := m.dmOut.DataManager().SetActionProfile(ap, true); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := m.dmIN.DataManager().RemoveActionProfile(tntID[0], tntID[1], utils.NonTransactional, false); err != nil {
|
||||
return err
|
||||
}
|
||||
m.stats[utils.ActionProfiles]++
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (m *Migrator) migrateActionProfiles() (err error) {
|
||||
var vrs engine.Versions
|
||||
current := engine.CurrentDataDBVersions()
|
||||
if vrs, err = m.getVersions(utils.ActionProfiles); err != nil {
|
||||
return
|
||||
}
|
||||
migrated := true
|
||||
for {
|
||||
version := vrs[utils.ActionProfiles]
|
||||
for {
|
||||
switch version {
|
||||
default:
|
||||
return fmt.Errorf("Unsupported version %v", version)
|
||||
case current[utils.ActionProfiles]:
|
||||
migrated = false
|
||||
if m.sameDataDB {
|
||||
break
|
||||
}
|
||||
if err = m.migrateCurrentActionProfiles(); err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
if version == current[utils.ActionProfiles] || err == utils.ErrNoMoreData {
|
||||
break
|
||||
}
|
||||
}
|
||||
if err == utils.ErrNoMoreData || !migrated {
|
||||
break
|
||||
}
|
||||
m.stats[utils.ActionProfiles]++
|
||||
}
|
||||
//All done, update version with current one
|
||||
if err = m.setVersions(utils.ActionProfiles); err != nil {
|
||||
return
|
||||
}
|
||||
return m.ensureIndexesDataDB(engine.ColApp)
|
||||
}
|
||||
@@ -1,256 +0,0 @@
|
||||
// +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 migrator
|
||||
|
||||
import (
|
||||
"log"
|
||||
"path"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/cgrates/cgrates/engine"
|
||||
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
|
||||
"github.com/cgrates/cgrates/config"
|
||||
)
|
||||
|
||||
var (
|
||||
actPrfPathIn string
|
||||
actPrfPathOut string
|
||||
actPrfCfgIn *config.CGRConfig
|
||||
actPrfCfgOut *config.CGRConfig
|
||||
actPrfMigrator *Migrator
|
||||
actPrfAction string
|
||||
)
|
||||
|
||||
var sTestsActPrfIT = []func(t *testing.T){
|
||||
testActPrfITConnect,
|
||||
testActPrfITFlush,
|
||||
testActPrfMigrateAndMove,
|
||||
}
|
||||
|
||||
func TestActPrfITMove1(t *testing.T) {
|
||||
var err error
|
||||
actPrfPathIn = path.Join(*dataDir, "conf", "samples", "tutmongo")
|
||||
actPrfCfgIn, err = config.NewCGRConfigFromPath(actPrfPathIn)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
actPrfPathOut = path.Join(*dataDir, "conf", "samples", "tutmysql")
|
||||
actPrfCfgOut, err = config.NewCGRConfigFromPath(actPrfPathOut)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
actPrfAction = utils.Move
|
||||
for _, stest := range sTestsActPrfIT {
|
||||
t.Run("TestActPrfITMove1", stest)
|
||||
}
|
||||
actPrfMigrator.Close()
|
||||
}
|
||||
|
||||
func TestActPrfITMove2(t *testing.T) {
|
||||
var err error
|
||||
actPrfPathIn = path.Join(*dataDir, "conf", "samples", "tutmysql")
|
||||
actPrfCfgIn, err = config.NewCGRConfigFromPath(actPrfPathIn)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
actPrfPathOut = path.Join(*dataDir, "conf", "samples", "tutmongo")
|
||||
actPrfCfgOut, err = config.NewCGRConfigFromPath(actPrfPathOut)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
actPrfAction = utils.Move
|
||||
for _, stest := range sTestsActPrfIT {
|
||||
t.Run("TestActPrfITMove2", stest)
|
||||
}
|
||||
actPrfMigrator.Close()
|
||||
}
|
||||
|
||||
func TestActPrfITMoveEncoding(t *testing.T) {
|
||||
var err error
|
||||
actPrfPathIn = path.Join(*dataDir, "conf", "samples", "tutmongo")
|
||||
actPrfCfgIn, err = config.NewCGRConfigFromPath(actPrfPathIn)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
actPrfPathOut = path.Join(*dataDir, "conf", "samples", "tutmongojson")
|
||||
actPrfCfgOut, err = config.NewCGRConfigFromPath(actPrfPathOut)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
actPrfAction = utils.Move
|
||||
for _, stest := range sTestsActPrfIT {
|
||||
t.Run("TestActPrfITMove2", stest)
|
||||
}
|
||||
actPrfMigrator.Close()
|
||||
}
|
||||
|
||||
func TestActPrfITMoveEncoding2(t *testing.T) {
|
||||
var err error
|
||||
actPrfPathIn = path.Join(*dataDir, "conf", "samples", "tutmysql")
|
||||
actPrfCfgIn, err = config.NewCGRConfigFromPath(actPrfPathIn)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
actPrfPathOut = path.Join(*dataDir, "conf", "samples", "tutmysqljson")
|
||||
actPrfCfgOut, err = config.NewCGRConfigFromPath(actPrfPathOut)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
actPrfAction = utils.Move
|
||||
for _, stest := range sTestsActPrfIT {
|
||||
t.Run("TestActPrfITMove2", stest)
|
||||
}
|
||||
actPrfMigrator.Close()
|
||||
}
|
||||
|
||||
func testActPrfITConnect(t *testing.T) {
|
||||
dataDBIn, err := NewMigratorDataDB(actPrfCfgIn.DataDbCfg().Type,
|
||||
actPrfCfgIn.DataDbCfg().Host, actPrfCfgIn.DataDbCfg().Port,
|
||||
actPrfCfgIn.DataDbCfg().Name, actPrfCfgIn.DataDbCfg().User,
|
||||
actPrfCfgIn.DataDbCfg().Password, actPrfCfgIn.GeneralCfg().DBDataEncoding,
|
||||
config.CgrConfig().CacheCfg(), actPrfCfgIn.DataDbCfg().Opts)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
dataDBOut, err := NewMigratorDataDB(actPrfCfgOut.DataDbCfg().Type,
|
||||
actPrfCfgOut.DataDbCfg().Host, actPrfCfgOut.DataDbCfg().Port,
|
||||
actPrfCfgOut.DataDbCfg().Name, actPrfCfgOut.DataDbCfg().User,
|
||||
actPrfCfgOut.DataDbCfg().Password, actPrfCfgOut.GeneralCfg().DBDataEncoding,
|
||||
config.CgrConfig().CacheCfg(), actPrfCfgOut.DataDbCfg().Opts)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
if reflect.DeepEqual(actPrfPathIn, actPrfPathOut) {
|
||||
actPrfMigrator, err = NewMigrator(dataDBIn, dataDBOut, nil, nil,
|
||||
false, true, false, false)
|
||||
} else {
|
||||
actPrfMigrator, err = NewMigrator(dataDBIn, dataDBOut, nil, nil,
|
||||
false, false, false, false)
|
||||
}
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func testActPrfITFlush(t *testing.T) {
|
||||
//dmIn
|
||||
if err := actPrfMigrator.dmIN.DataManager().DataDB().Flush(utils.EmptyString); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if isEmpty, err := actPrfMigrator.dmIN.DataManager().DataDB().IsDBEmpty(); err != nil {
|
||||
t.Error(err)
|
||||
} else if !isEmpty {
|
||||
t.Errorf("Expecting: true got :%+v", isEmpty)
|
||||
}
|
||||
if err := engine.SetDBVersions(actPrfMigrator.dmIN.DataManager().DataDB()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
//dmOut
|
||||
if err := actPrfMigrator.dmOut.DataManager().DataDB().Flush(utils.EmptyString); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if isEMpty, err := actPrfMigrator.dmOut.DataManager().DataDB().IsDBEmpty(); err != nil {
|
||||
t.Error(err)
|
||||
} else if !isEMpty {
|
||||
t.Error(err)
|
||||
}
|
||||
if err := engine.SetDBVersions(actPrfMigrator.dmOut.DataManager().DataDB()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func testActPrfMigrateAndMove(t *testing.T) {
|
||||
actPrf := &engine.ActionProfile{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "TEST_ID1",
|
||||
FilterIDs: []string{"*string:~*req.Account:1001"},
|
||||
Weight: 20,
|
||||
Schedule: utils.MetaASAP,
|
||||
Targets: map[string]utils.StringSet{
|
||||
utils.MetaAccounts: utils.NewStringSet([]string{"acc1", "acc2"}),
|
||||
},
|
||||
Actions: []*engine.APAction{
|
||||
{
|
||||
ID: "TOPUP",
|
||||
FilterIDs: []string{},
|
||||
Type: "*topup",
|
||||
Diktats: []*engine.APDiktat{{
|
||||
Path: "~*balance.TestBalance.Value",
|
||||
}},
|
||||
},
|
||||
{
|
||||
ID: "TOPUP_TEST_VOICE",
|
||||
FilterIDs: []string{},
|
||||
Type: "*topup",
|
||||
Diktats: []*engine.APDiktat{{
|
||||
Path: "~*balance.TestVoiceBalance.Value",
|
||||
}},
|
||||
},
|
||||
},
|
||||
}
|
||||
switch actPrfAction {
|
||||
case utils.Migrate: // for the moment only one version of actions profiles exists
|
||||
case utils.Move:
|
||||
//set, get and migrate
|
||||
if err := actPrfMigrator.dmIN.DataManager().SetActionProfile(actPrf, true); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
currentVersion := engine.CurrentDataDBVersions()
|
||||
err := actPrfMigrator.dmIN.DataManager().DataDB().SetVersions(currentVersion, false)
|
||||
if err != nil {
|
||||
t.Error("Error when setting version for ActionPrf", err.Error())
|
||||
}
|
||||
|
||||
_, err = actPrfMigrator.dmOut.DataManager().GetActionProfile(actPrf.Tenant, actPrf.ID,
|
||||
false, false, utils.NonTransactional)
|
||||
if err != utils.ErrNotFound {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
err, _ = actPrfMigrator.Migrate([]string{utils.MetaActionProfiles})
|
||||
if err != nil {
|
||||
t.Error("Error when migrating ActPrf", err.Error())
|
||||
}
|
||||
//compared with dmOut
|
||||
receivedACtPrf, err := actPrfMigrator.dmOut.DataManager().GetActionProfile(actPrf.Tenant, actPrf.ID,
|
||||
false, false, utils.NonTransactional)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if !reflect.DeepEqual(receivedACtPrf, actPrf) {
|
||||
t.Errorf("Expected %+v, received %+v", utils.ToJSON(actPrf), utils.ToJSON(receivedACtPrf))
|
||||
}
|
||||
|
||||
//compared with dmIn(should be empty)
|
||||
_, err = actPrfMigrator.dmIN.DataManager().GetActionProfile(actPrf.Tenant, actPrf.ID,
|
||||
false, false, utils.NonTransactional)
|
||||
if err != utils.ErrNotFound {
|
||||
t.Error(err)
|
||||
}
|
||||
if actPrfMigrator.stats[utils.ActionProfiles] != 1 {
|
||||
t.Errorf("Expected 1, received: %v", actPrfMigrator.stats[utils.ActionProfiles])
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -133,8 +133,6 @@ func (m *Migrator) Migrate(taskIDs []string) (err error, stats map[string]int) {
|
||||
err = m.migrateRatingPlans()
|
||||
case utils.MetaRatingProfiles:
|
||||
err = m.migrateRatingProfiles()
|
||||
case utils.MetaActionProfiles:
|
||||
err = m.migrateActionProfiles()
|
||||
case utils.MetaDestinations:
|
||||
err = m.migrateDestinations()
|
||||
case utils.MetaReverseDestinations:
|
||||
@@ -180,8 +178,6 @@ func (m *Migrator) Migrate(taskIDs []string) (err error, stats map[string]int) {
|
||||
err = m.migrateTPsharedgroups()
|
||||
case utils.MetaTpRatingProfiles:
|
||||
err = m.migrateTPratingprofiles()
|
||||
case utils.MetaTpActionProfiles:
|
||||
err = m.migrateTPActionProfiles()
|
||||
case utils.MetaTpResources:
|
||||
err = m.migrateTPresources()
|
||||
case utils.MetaTpRates:
|
||||
|
||||
@@ -1,79 +0,0 @@
|
||||
/*
|
||||
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 migrator
|
||||
|
||||
import (
|
||||
"github.com/cgrates/cgrates/engine"
|
||||
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
)
|
||||
|
||||
func (m *Migrator) migrateCurrentTPActionProfiles() (err error) {
|
||||
tpIds, err := m.storDBIn.StorDB().GetTpIds(utils.TBLTPActionProfiles)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, tpid := range tpIds {
|
||||
ids, err := m.storDBIn.StorDB().GetTpTableIds(tpid, utils.TBLTPActionProfiles,
|
||||
utils.TPDistinctIds{"id"}, map[string]string{}, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, id := range ids {
|
||||
actionProfiles, err := m.storDBIn.StorDB().GetTPActionProfiles(tpid, utils.EmptyString, id)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if actionProfiles == nil || m.dryRun {
|
||||
continue
|
||||
}
|
||||
if err := m.storDBOut.StorDB().SetTPActionProfiles(actionProfiles); err != nil {
|
||||
return err
|
||||
}
|
||||
for _, actionProfile := range actionProfiles {
|
||||
if err := m.storDBIn.StorDB().RemTpData(utils.TBLTPActionProfiles, actionProfile.TPid,
|
||||
map[string]string{"id": actionProfile.ID}); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
m.stats[utils.TpActionProfiles]++
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (m *Migrator) migrateTPActionProfiles() (err error) {
|
||||
var vrs engine.Versions
|
||||
current := engine.CurrentStorDBVersions()
|
||||
if vrs, err = m.getVersions(utils.TpActionProfiles); err != nil {
|
||||
return
|
||||
}
|
||||
switch vrs[utils.TpActionProfiles] {
|
||||
case current[utils.TpActionProfiles]:
|
||||
if m.sameStorDB {
|
||||
break
|
||||
}
|
||||
if err := m.migrateCurrentTPActionProfiles(); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return m.ensureIndexesStorDB(utils.TBLTPActionProfiles)
|
||||
}
|
||||
@@ -1,167 +0,0 @@
|
||||
// +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 migrator
|
||||
|
||||
import (
|
||||
"path"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/cgrates/cgrates/engine"
|
||||
|
||||
"github.com/cgrates/cgrates/config"
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
)
|
||||
|
||||
var (
|
||||
tpActPrfPathIn string
|
||||
tpActPrfPathOut string
|
||||
tpActPrfCfgIn *config.CGRConfig
|
||||
tpActPrfCfgOut *config.CGRConfig
|
||||
tpActPrfMigrator *Migrator
|
||||
actPrf []*utils.TPActionProfile
|
||||
)
|
||||
|
||||
var sTestTpActPrfIT = []func(t *testing.T){
|
||||
testTpActPrfConnect,
|
||||
testTpActPrfFlush,
|
||||
testTpACtPrfPopulate,
|
||||
testTpACtPrfMove,
|
||||
testTpACtPrfCheckData,
|
||||
}
|
||||
|
||||
func TestTpActPrfMove(t *testing.T) {
|
||||
for _, tests := range sTestTpActPrfIT {
|
||||
t.Run("TestTpActPrfMove", tests)
|
||||
}
|
||||
tpActPrfMigrator.Close()
|
||||
}
|
||||
|
||||
func testTpActPrfConnect(t *testing.T) {
|
||||
var err error
|
||||
tpActPrfPathIn = path.Join(*dataDir, "conf", "samples", "tutmongo")
|
||||
tpActPrfCfgIn, err = config.NewCGRConfigFromPath(tpActPrfPathIn)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
tpActPrfPathOut = path.Join(*dataDir, "conf", "samples", "tutmysql")
|
||||
tpActPrfCfgOut, err = config.NewCGRConfigFromPath(tpActPrfPathOut)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
storDBIn, err := NewMigratorStorDB(tpActPrfCfgIn.StorDbCfg().Type,
|
||||
tpActPrfCfgIn.StorDbCfg().Host, tpActPrfCfgIn.StorDbCfg().Port,
|
||||
tpActPrfCfgIn.StorDbCfg().Name, tpActPrfCfgIn.StorDbCfg().User,
|
||||
tpActPrfCfgIn.StorDbCfg().Password, tpActPrfCfgIn.GeneralCfg().DBDataEncoding,
|
||||
tpActPrfCfgIn.StorDbCfg().StringIndexedFields, tpActPrfCfgIn.StorDbCfg().PrefixIndexedFields,
|
||||
tpActPrfCfgIn.StorDbCfg().Opts)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
storDBOut, err := NewMigratorStorDB(tpActPrfCfgOut.StorDbCfg().Type,
|
||||
tpActPrfCfgOut.StorDbCfg().Host, tpActPrfCfgOut.StorDbCfg().Port,
|
||||
tpActPrfCfgOut.StorDbCfg().Name, tpActPrfCfgOut.StorDbCfg().User,
|
||||
tpActPrfCfgOut.StorDbCfg().Password, tpActPrfCfgOut.GeneralCfg().DBDataEncoding,
|
||||
tpActPrfCfgOut.StorDbCfg().StringIndexedFields, tpActPrfCfgOut.StorDbCfg().PrefixIndexedFields,
|
||||
tpActPrfCfgOut.StorDbCfg().Opts)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
tpActPrfMigrator, err = NewMigrator(nil, nil, storDBIn, storDBOut,
|
||||
false, false, false, false)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func testTpActPrfFlush(t *testing.T) {
|
||||
if err := tpActPrfMigrator.storDBIn.StorDB().Flush(
|
||||
path.Join(tpActPrfCfgIn.DataFolderPath, "storage", tpActPrfCfgIn.StorDbCfg().Type)); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if err := tpActPrfMigrator.storDBOut.StorDB().Flush(
|
||||
path.Join(tpActPrfCfgOut.DataFolderPath, "storage", tpActPrfCfgOut.StorDbCfg().Type)); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func testTpACtPrfPopulate(t *testing.T) {
|
||||
actPrf = []*utils.TPActionProfile{
|
||||
{
|
||||
Tenant: "cgrates.org",
|
||||
TPid: "TEST_ID1",
|
||||
ID: "sub_id1",
|
||||
FilterIDs: []string{"*string:~*req.Account:1001"},
|
||||
Weight: 20,
|
||||
Schedule: utils.MetaASAP,
|
||||
Actions: []*utils.TPAPAction{
|
||||
{
|
||||
ID: "TOPUP",
|
||||
FilterIDs: []string{},
|
||||
Type: "*topup",
|
||||
Diktats: []*utils.TPAPDiktat{{
|
||||
Path: "~*balance.TestBalance.Value",
|
||||
}},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
//empty in database
|
||||
if _, err := tpActPrfMigrator.storDBIn.StorDB().GetTPActionProfiles(actPrf[0].TPid,
|
||||
utils.EmptyString, actPrf[0].ID); err != utils.ErrNotFound {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
//set an TPActionProfile in database
|
||||
if err := tpActPrfMigrator.storDBIn.StorDB().SetTPActionProfiles(actPrf); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
currVersion := engine.CurrentStorDBVersions()
|
||||
err := tpActPrfMigrator.storDBIn.StorDB().SetVersions(currVersion, false)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func testTpACtPrfMove(t *testing.T) {
|
||||
err, _ := tpActPrfMigrator.Migrate([]string{utils.MetaTpActionProfiles})
|
||||
if err != nil {
|
||||
t.Error("Error when migrating TpActionProfile ", err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
func testTpACtPrfCheckData(t *testing.T) {
|
||||
rcv, err := tpActPrfMigrator.storDBOut.StorDB().GetTPActionProfiles(actPrf[0].TPid,
|
||||
utils.EmptyString, actPrf[0].ID)
|
||||
if err != nil {
|
||||
t.Error("Error when getting TPActionProfile from database", err)
|
||||
}
|
||||
actPrf[0].Actions[0].FilterIDs = nil // because of converting and empty string into a slice
|
||||
if !reflect.DeepEqual(rcv[0], actPrf[0]) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", utils.ToJSON(actPrf[0]), utils.ToJSON(rcv[0]))
|
||||
}
|
||||
|
||||
_, err = tpActPrfMigrator.storDBIn.StorDB().GetTPActionProfiles(actPrf[0].TPid,
|
||||
utils.EmptyString, actPrf[0].ID)
|
||||
if err != utils.ErrNotFound {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user