mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Updated integration test in migrator
This commit is contained in:
committed by
Dan Christian Bogos
parent
961722a788
commit
4b5c65c5e6
@@ -21,7 +21,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
package migrator
|
||||
|
||||
import (
|
||||
//"flag"
|
||||
"log"
|
||||
"path"
|
||||
"reflect"
|
||||
@@ -117,6 +116,7 @@ func TestActionITMoveEncoding(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
func TestActionITMoveEncoding2(t *testing.T) {
|
||||
var err error
|
||||
actPathIn = path.Join(*dataDir, "conf", "samples", "tutmysqljson")
|
||||
@@ -133,7 +133,7 @@ func TestActionITMoveEncoding2(t *testing.T) {
|
||||
for _, stest := range sTestsActIT {
|
||||
t.Run("TestActionITMoveEncoding2", stest)
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
func testActITConnect(t *testing.T) {
|
||||
dataDBIn, err := NewMigratorDataDB(actCfgIn.DataDbType,
|
||||
@@ -166,26 +166,31 @@ func testActITFlush(t *testing.T) {
|
||||
}
|
||||
|
||||
func testActITMigrateAndMove(t *testing.T) {
|
||||
v1act := &v1Actions{
|
||||
&v1Action{
|
||||
Id: "test",
|
||||
ActionType: "",
|
||||
BalanceType: "",
|
||||
Direction: "INBOUND",
|
||||
ExtraParameters: "",
|
||||
ExpirationString: "",
|
||||
Balance: &v1Balance{
|
||||
Timings: []*engine.RITiming{
|
||||
&engine.RITiming{
|
||||
Years: utils.Years{},
|
||||
Months: utils.Months{},
|
||||
MonthDays: utils.MonthDays{},
|
||||
WeekDays: utils.WeekDays{},
|
||||
},
|
||||
},
|
||||
},
|
||||
timingSlice := []*engine.RITiming{
|
||||
&engine.RITiming{
|
||||
Years: utils.Years{},
|
||||
Months: utils.Months{},
|
||||
MonthDays: utils.MonthDays{},
|
||||
WeekDays: utils.WeekDays{},
|
||||
},
|
||||
}
|
||||
|
||||
v1act := &v1Action{
|
||||
Id: "test",
|
||||
ActionType: "",
|
||||
BalanceType: "",
|
||||
Direction: "INBOUND",
|
||||
ExtraParameters: "",
|
||||
ExpirationString: "",
|
||||
Balance: &v1Balance{
|
||||
Timings: timingSlice,
|
||||
},
|
||||
}
|
||||
|
||||
v1acts := &v1Actions{
|
||||
v1act,
|
||||
}
|
||||
|
||||
act := &engine.Actions{
|
||||
&engine.Action{
|
||||
Id: "test",
|
||||
@@ -194,20 +199,13 @@ func testActITMigrateAndMove(t *testing.T) {
|
||||
ExpirationString: "",
|
||||
Weight: 0.00,
|
||||
Balance: &engine.BalanceFilter{
|
||||
Timings: []*engine.RITiming{
|
||||
&engine.RITiming{
|
||||
Years: utils.Years{},
|
||||
Months: utils.Months{},
|
||||
MonthDays: utils.MonthDays{},
|
||||
WeekDays: utils.WeekDays{},
|
||||
},
|
||||
},
|
||||
Timings: timingSlice,
|
||||
},
|
||||
},
|
||||
}
|
||||
switch accAction {
|
||||
switch actAction {
|
||||
case utils.Migrate:
|
||||
err := actMigrator.dmIN.setV1Actions(v1act)
|
||||
err := actMigrator.dmIN.setV1Actions(v1acts)
|
||||
if err != nil {
|
||||
t.Error("Error when setting v1 Actions ", err.Error())
|
||||
}
|
||||
@@ -220,15 +218,15 @@ func testActITMigrateAndMove(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Error("Error when migrating Actions ", err.Error())
|
||||
}
|
||||
result, err := actMigrator.dmOut.DataManager().GetActions((*v1act)[0].Id, true, utils.NonTransactional)
|
||||
result, err := actMigrator.dmOut.DataManager().GetActions(v1act.Id, true, utils.NonTransactional)
|
||||
if err != nil {
|
||||
t.Error("Error when getting Actions ", err.Error())
|
||||
}
|
||||
if !reflect.DeepEqual(*act, result) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", *act, result)
|
||||
if !reflect.DeepEqual(act, &result) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", act, &result)
|
||||
}
|
||||
case utils.Move:
|
||||
if err := actMigrator.dmIN.DataManager().SetActions((*v1act)[0].Id, *act, utils.NonTransactional); err != nil {
|
||||
if err := actMigrator.dmIN.DataManager().SetActions(v1act.Id, *act, utils.NonTransactional); err != nil {
|
||||
t.Error("Error when setting ActionPlan ", err.Error())
|
||||
}
|
||||
currentVersion := engine.CurrentDataDBVersions()
|
||||
@@ -240,12 +238,12 @@ func testActITMigrateAndMove(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Error("Error when migrating Actions ", err.Error())
|
||||
}
|
||||
result, err := actMigrator.dmOut.DataManager().GetActions((*v1act)[0].Id, true, utils.NonTransactional)
|
||||
result, err := actMigrator.dmOut.DataManager().GetActions(v1act.Id, true, utils.NonTransactional)
|
||||
if err != nil {
|
||||
t.Error("Error when getting Actions ", err.Error())
|
||||
}
|
||||
if !reflect.DeepEqual(*act, result) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", *act, result)
|
||||
if !reflect.DeepEqual(act, &result) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", act, &result)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,7 +21,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
package migrator
|
||||
|
||||
import (
|
||||
//"flag"
|
||||
"log"
|
||||
"path"
|
||||
"reflect"
|
||||
@@ -166,17 +165,19 @@ func testActPlnITFlush(t *testing.T) {
|
||||
}
|
||||
|
||||
func testActPlnITMigrateAndMove(t *testing.T) {
|
||||
timingSlice := &engine.RITiming{
|
||||
Years: utils.Years{},
|
||||
Months: utils.Months{},
|
||||
MonthDays: utils.MonthDays{},
|
||||
WeekDays: utils.WeekDays{},
|
||||
}
|
||||
|
||||
v1actPln := &v1ActionPlans{
|
||||
&v1ActionPlan{
|
||||
Id: "test",
|
||||
AccountIds: []string{"one"},
|
||||
Timing: &engine.RateInterval{
|
||||
Timing: &engine.RITiming{
|
||||
Years: utils.Years{},
|
||||
Months: utils.Months{},
|
||||
MonthDays: utils.MonthDays{},
|
||||
WeekDays: utils.WeekDays{},
|
||||
},
|
||||
Timing: timingSlice,
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -187,18 +188,13 @@ func testActPlnITMigrateAndMove(t *testing.T) {
|
||||
ActionTimings: []*engine.ActionTiming{
|
||||
&engine.ActionTiming{
|
||||
Timing: &engine.RateInterval{
|
||||
Timing: &engine.RITiming{
|
||||
Years: utils.Years{},
|
||||
Months: utils.Months{},
|
||||
MonthDays: utils.MonthDays{},
|
||||
WeekDays: utils.WeekDays{},
|
||||
},
|
||||
Timing: timingSlice,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
switch accAction {
|
||||
switch actActionPlan {
|
||||
case utils.Migrate:
|
||||
err := actPlnMigrator.dmIN.setV1ActionPlans(v1actPln)
|
||||
if err != nil {
|
||||
@@ -209,7 +205,7 @@ func testActPlnITMigrateAndMove(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Error("Error when setting version for ActionPlan ", err.Error())
|
||||
}
|
||||
err, _ = actPlnMigrator.Migrate([]string{utils.AccountActionPlansPrefix})
|
||||
err, _ = actPlnMigrator.Migrate([]string{utils.MetaActionPlans})
|
||||
if err != nil {
|
||||
t.Error("Error when migrating ActionPlan ", err.Error())
|
||||
}
|
||||
@@ -217,8 +213,13 @@ func testActPlnITMigrateAndMove(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Error("Error when getting ActionPlan ", err.Error())
|
||||
}
|
||||
if !reflect.DeepEqual(*actPln, result) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", *actPln, result)
|
||||
// compared fields, uuid is generated in ActionTiming
|
||||
if !reflect.DeepEqual(actPln.Id, result.Id) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", actPln.Id, result.Id)
|
||||
} else if !reflect.DeepEqual(actPln.AccountIDs, result.AccountIDs) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", actPln.AccountIDs, result.AccountIDs)
|
||||
} else if !reflect.DeepEqual(actPln.ActionTimings[0].Timing, result.ActionTimings[0].Timing) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", actPln.ActionTimings[0].Timing, result.ActionTimings[0].Timing)
|
||||
}
|
||||
case utils.Move:
|
||||
if err := actPlnMigrator.dmIN.DataManager().DataDB().SetActionPlan((*v1actPln)[0].Id, actPln, true, utils.NonTransactional); err != nil {
|
||||
@@ -229,7 +230,7 @@ func testActPlnITMigrateAndMove(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Error("Error when setting version for ActionPlan ", err.Error())
|
||||
}
|
||||
err, _ = actPlnMigrator.Migrate([]string{utils.MetaActions})
|
||||
err, _ = actPlnMigrator.Migrate([]string{utils.MetaActionPlans})
|
||||
if err != nil {
|
||||
t.Error("Error when migrating ActionPlan ", err.Error())
|
||||
}
|
||||
@@ -237,8 +238,13 @@ func testActPlnITMigrateAndMove(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Error("Error when getting ActionPlan ", err.Error())
|
||||
}
|
||||
if !reflect.DeepEqual(*actPln, result) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", *actPln, result)
|
||||
// compared fields, uuid is generated in ActionTiming
|
||||
if !reflect.DeepEqual(actPln.Id, result.Id) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", actPln.Id, result.Id)
|
||||
} else if !reflect.DeepEqual(actPln.AccountIDs, result.AccountIDs) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", actPln.AccountIDs, result.AccountIDs)
|
||||
} else if !reflect.DeepEqual(actPln.ActionTimings[0].Timing, result.ActionTimings[0].Timing) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", actPln.ActionTimings[0].Timing, result.ActionTimings[0].Timing)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
|
||||
package migrator
|
||||
|
||||
/*
|
||||
import (
|
||||
//"flag"
|
||||
"log"
|
||||
@@ -199,9 +200,9 @@ func testActTrgITMigrateAndMove(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
switch accAction {
|
||||
switch actActionTrigger {
|
||||
case utils.Migrate:
|
||||
err := actTrgMigrator.dmIN.setV1ActionTriggers(v1actTrg)
|
||||
err := actTrgMigrator.dmIN.setV2ActionTrigger(v1actTrg)
|
||||
if err != nil {
|
||||
t.Error("Error when setting v1 ActionTriggers ", err.Error())
|
||||
}
|
||||
@@ -210,19 +211,20 @@ func testActTrgITMigrateAndMove(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Error("Error when setting version for ActionTriggers ", err.Error())
|
||||
}
|
||||
err, _ = actTrgMigrator.Migrate([]string{utils.AccountActionPlansPrefix})
|
||||
err, _ = actTrgMigrator.Migrate([]string{utils.MetaActionTriggers})
|
||||
if err != nil {
|
||||
t.Error("Error when migrating ActionTriggers ", err.Error())
|
||||
}
|
||||
result, err := actTrgMigrator.dmOut.DataManager().DataDB().GetActionTriggersDrv((*v1actTrg)[0].Id)
|
||||
result, err := actTrgMigrator.dmOut.DataManager().GetActionTriggers((*v1actTrg)[0].Id, false, utils.NonTransactional)
|
||||
if err != nil {
|
||||
t.Error("Error when getting ActionTriggers ", err.Error())
|
||||
}
|
||||
if !reflect.DeepEqual(&actTrg, result) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", &actTrg, result)
|
||||
if !reflect.DeepEqual(actTrg, result) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", actTrg, result)
|
||||
}
|
||||
// utils.tojson si verificat
|
||||
case utils.Move:
|
||||
if err := actTrgMigrator.dmIN.DataManager().DataDB().SetActionTriggersDrv((*v1actTrg)[0].Id, actTrg); err != nil {
|
||||
if err := actTrgMigrator.dmIN.DataManager().SetActionTriggers((*v1actTrg)[0].Id, actTrg, utils.NonTransactional); err != nil {
|
||||
t.Error("Error when setting ActionTriggers ", err.Error())
|
||||
}
|
||||
currentVersion := engine.CurrentDataDBVersions()
|
||||
@@ -234,12 +236,13 @@ func testActTrgITMigrateAndMove(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Error("Error when migrating ActionTriggers ", err.Error())
|
||||
}
|
||||
result, err := actTrgMigrator.dmOut.DataManager().DataDB().GetActionTriggersDrv((*v1actTrg)[0].Id)
|
||||
result, err := actTrgMigrator.dmOut.DataManager().GetActionTriggers((*v1actTrg)[0].Id, false, utils.NonTransactional)
|
||||
if err != nil {
|
||||
t.Error("Error when getting ActionTriggers ", err.Error())
|
||||
}
|
||||
if !reflect.DeepEqual(&actTrg, result) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", &actTrg, result)
|
||||
if !reflect.DeepEqual(actTrg, result) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", actTrg, result)
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
@@ -180,7 +180,7 @@ func testShrGrpITMigrateAndMove(t *testing.T) {
|
||||
MemberIds: utils.NewStringMap("1", "2", "3"),
|
||||
}
|
||||
|
||||
switch accAction {
|
||||
switch shrSharedGroup {
|
||||
case utils.Migrate:
|
||||
err := shrGrpMigrator.dmIN.setV1SharedGroup(v1shrGrp)
|
||||
if err != nil {
|
||||
@@ -195,15 +195,15 @@ func testShrGrpITMigrateAndMove(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Error("Error when migrating SharedGroup ", err.Error())
|
||||
}
|
||||
result, err := shrGrpMigrator.dmOut.DataManager().DataDB().GetSharedGroupDrv(v1shrGrp.Id)
|
||||
result, err := shrGrpMigrator.dmOut.DataManager().GetSharedGroup(v1shrGrp.Id, true, utils.NonTransactional)
|
||||
if err != nil {
|
||||
t.Error("Error when getting SharedGroup ", err.Error())
|
||||
}
|
||||
if !reflect.DeepEqual(&shrGrp, result) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", &shrGrp, result)
|
||||
if !reflect.DeepEqual(shrGrp, result) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", shrGrp, result)
|
||||
}
|
||||
case utils.Move:
|
||||
if err := shrGrpMigrator.dmIN.DataManager().DataDB().SetSharedGroupDrv(shrGrp); err != nil {
|
||||
if err := shrGrpMigrator.dmIN.DataManager().SetSharedGroup(shrGrp, utils.NonTransactional); err != nil {
|
||||
t.Error("Error when setting SharedGroup ", err.Error())
|
||||
}
|
||||
currentVersion := engine.CurrentDataDBVersions()
|
||||
@@ -215,12 +215,12 @@ func testShrGrpITMigrateAndMove(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Error("Error when migrating SharedGroup ", err.Error())
|
||||
}
|
||||
result, err := shrGrpMigrator.dmOut.DataManager().DataDB().GetSharedGroupDrv(v1shrGrp.Id)
|
||||
result, err := shrGrpMigrator.dmOut.DataManager().GetSharedGroup(v1shrGrp.Id, true, utils.NonTransactional)
|
||||
if err != nil {
|
||||
t.Error("Error when getting SharedGroup ", err.Error())
|
||||
}
|
||||
if !reflect.DeepEqual(&shrGrp, result) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", &shrGrp, result)
|
||||
if !reflect.DeepEqual(shrGrp, result) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", shrGrp, result)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -175,8 +175,8 @@ func testTrsITMigrateAndMove(t *testing.T) {
|
||||
ThresholdValue: 5.32,
|
||||
Recurrent: false, // reset excuted flag each run
|
||||
MinSleep: time.Duration(5) * time.Second, // Minimum duration between two executions in case of recurrent triggers
|
||||
ExpirationDate: time.Now(),
|
||||
ActivationDate: time.Now(),
|
||||
ExpirationDate: tim,
|
||||
ActivationDate: tim,
|
||||
Balance: &engine.BalanceFilter{
|
||||
ID: utils.StringPointer("TESTZ"),
|
||||
Timings: []*engine.RITiming{},
|
||||
@@ -196,22 +196,14 @@ func testTrsITMigrateAndMove(t *testing.T) {
|
||||
}
|
||||
filters = append(filters, x)
|
||||
|
||||
filter := &engine.Filter{Tenant: config.CgrConfig().DefaultTenant, ID: *v1trs.Balance.ID, Rules: filters}
|
||||
|
||||
tresProf := &engine.ThresholdProfile{
|
||||
ID: v1trs.ID,
|
||||
Tenant: config.CgrConfig().DefaultTenant,
|
||||
FilterIDs: []string{filter.ID},
|
||||
Blocker: false,
|
||||
Weight: v1trs.Weight,
|
||||
ActivationInterval: &utils.ActivationInterval{v1trs.ExpirationDate, v1trs.ActivationDate},
|
||||
MinSleep: v1trs.MinSleep,
|
||||
}
|
||||
tres := &engine.Threshold{
|
||||
Tenant: config.CgrConfig().DefaultTenant,
|
||||
ID: v1trs.ID,
|
||||
}
|
||||
switch accAction {
|
||||
switch trsThresholds {
|
||||
case utils.Migrate:
|
||||
err := trsMigrator.dmIN.setV2ActionTrigger(v1trs)
|
||||
if err != nil {
|
||||
@@ -226,15 +218,23 @@ func testTrsITMigrateAndMove(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Error("Error when migrating Thresholds ", err.Error())
|
||||
}
|
||||
result, err := trsMigrator.dmOut.DataManager().DataDB().GetThresholdDrv(tresProf.Tenant, tresProf.ID)
|
||||
result, err := trsMigrator.dmOut.DataManager().GetThresholdProfile(tresProf.Tenant, tresProf.ID, false, utils.NonTransactional)
|
||||
if err != nil {
|
||||
t.Error("Error when getting Thresholds ", err.Error())
|
||||
}
|
||||
if !reflect.DeepEqual(&tres, result) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", &tres, result)
|
||||
if !reflect.DeepEqual(tresProf.ID, result.ID) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", tresProf.ID, result.ID)
|
||||
} else if !reflect.DeepEqual(tresProf.Tenant, result.Tenant) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", tresProf.Tenant, result.Tenant)
|
||||
} else if !reflect.DeepEqual(tresProf.Weight, result.Weight) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", tresProf.Weight, result.Weight)
|
||||
} else if !reflect.DeepEqual(tresProf.ActivationInterval, result.ActivationInterval) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", tresProf.ActivationInterval, result.ActivationInterval)
|
||||
} else if !reflect.DeepEqual(tresProf.MinSleep, result.MinSleep) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", tresProf.MinSleep, result.MinSleep)
|
||||
}
|
||||
case utils.Move:
|
||||
if err := trsMigrator.dmIN.DataManager().DataDB().SetThresholdDrv(tres); err != nil {
|
||||
if err := trsMigrator.dmIN.DataManager().SetThresholdProfile(tresProf, false); err != nil {
|
||||
t.Error("Error when setting Thresholds ", err.Error())
|
||||
}
|
||||
currentVersion := engine.CurrentDataDBVersions()
|
||||
@@ -246,12 +246,20 @@ func testTrsITMigrateAndMove(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Error("Error when migrating Thresholds ", err.Error())
|
||||
}
|
||||
result, err := trsMigrator.dmOut.DataManager().DataDB().GetThresholdDrv(tresProf.Tenant, tresProf.ID)
|
||||
result, err := trsMigrator.dmOut.DataManager().GetThresholdProfile(tresProf.Tenant, tresProf.ID, false, utils.NonTransactional)
|
||||
if err != nil {
|
||||
t.Error("Error when getting Thresholds ", err.Error())
|
||||
}
|
||||
if !reflect.DeepEqual(&tres, result) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", &tres, result)
|
||||
if !reflect.DeepEqual(tresProf.ID, result.ID) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", tresProf.ID, result.ID)
|
||||
} else if !reflect.DeepEqual(tresProf.Tenant, result.Tenant) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", tresProf.Tenant, result.Tenant)
|
||||
} else if !reflect.DeepEqual(tresProf.Weight, result.Weight) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", tresProf.Weight, result.Weight)
|
||||
} else if !reflect.DeepEqual(tresProf.ActivationInterval, result.ActivationInterval) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", tresProf.ActivationInterval, result.ActivationInterval)
|
||||
} else if !reflect.DeepEqual(tresProf.MinSleep, result.MinSleep) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", tresProf.MinSleep, result.MinSleep)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user