Skip to content

Commit

Permalink
Added test for migration stats
Browse files Browse the repository at this point in the history
  • Loading branch information
adragusin committed Jun 30, 2020
1 parent 5566635 commit b7b5c09
Show file tree
Hide file tree
Showing 22 changed files with 100 additions and 2 deletions.
2 changes: 2 additions & 0 deletions migrator/accounts2_it_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,5 +256,7 @@ func testAcc2ITMigrate(t *testing.T) {
t.Errorf("Expecting: %+v, received: %+v", testAccount.BalanceMap, result.BalanceMap)
} else if !reflect.DeepEqual(testAccount.UnitCounters, result.UnitCounters) {
t.Errorf("Expecting: %+v, received: %+v", testAccount.UnitCounters, result.UnitCounters)
} else if acc2Migrator.stats[utils.Accounts] != 1 {
t.Errorf("Expecting: 1, received: %+v", acc2Migrator.stats[utils.Accounts])
}
}
4 changes: 4 additions & 0 deletions migrator/accounts_it_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,8 @@ func testAccITMigrateAndMove(t *testing.T) {
t.Errorf("Expecting: %+v, received: %+v", testAccount.BalanceMap, result.BalanceMap)
} else if !reflect.DeepEqual(testAccount.UnitCounters, result.UnitCounters) {
t.Errorf("Expecting: %+v, received: %+v", testAccount.UnitCounters, result.UnitCounters)
} else if accMigrator.stats[utils.Accounts] != 1 {
t.Errorf("Expecting: 1, received: %+v", accMigrator.stats[utils.Accounts])
}
case utils.Move:
//set an account in dmIN
Expand Down Expand Up @@ -363,6 +365,8 @@ func testAccITMigrateAndMove(t *testing.T) {
result, err = accMigrator.dmIN.DataManager().GetAccount(testAccount.ID)
if err != utils.ErrNotFound {
t.Error(err)
} else if accMigrator.stats[utils.Accounts] != 1 {
t.Errorf("Expecting: 1, received: %+v", accMigrator.stats[utils.Accounts])
}

}
Expand Down
4 changes: 4 additions & 0 deletions migrator/action_it_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,8 @@ func testActITMigrateAndMove(t *testing.T) {
}
if !reflect.DeepEqual(act, &result) {
t.Errorf("Expecting: %+v, received: %+v", act, &result)
} else if actMigrator.stats[utils.Actions] != 1 {
t.Errorf("Expecting: 1, received: %+v", actMigrator.stats[utils.Actions])
}
case utils.Move:
if err := actMigrator.dmIN.DataManager().SetActions(v1act.Id, *act, utils.NonTransactional); err != nil {
Expand All @@ -287,6 +289,8 @@ func testActITMigrateAndMove(t *testing.T) {
}
if !reflect.DeepEqual(act, &result) {
t.Errorf("Expecting: %+v, received: %+v", act, &result)
} else if actMigrator.stats[utils.Actions] != 1 {
t.Errorf("Expecting: 1, received: %+v", actMigrator.stats[utils.Actions])
}
}
}
4 changes: 4 additions & 0 deletions migrator/action_plan_it_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,8 @@ func testActPlnITMigrateAndMove(t *testing.T) {
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)
} else if actPlnMigrator.stats[utils.ActionPlans] != 1 {
t.Errorf("Expecting: 1, received: %+v", actPlnMigrator.stats[utils.ActionPlans])
}
case utils.Move:
if err := actPlnMigrator.dmIN.DataManager().SetActionPlan((*v1actPln)[0].Id, actPln, true, utils.NonTransactional); err != nil {
Expand Down Expand Up @@ -291,6 +293,8 @@ func testActPlnITMigrateAndMove(t *testing.T) {
result, err = actPlnMigrator.dmIN.DataManager().GetActionPlan((*v1actPln)[0].Id, true, utils.NonTransactional)
if err != utils.ErrNotFound {
t.Error(err)
} else if actPlnMigrator.stats[utils.ActionPlans] != 1 {
t.Errorf("Expecting: 1, received: %+v", actPlnMigrator.stats[utils.ActionPlans])
}
}
}
2 changes: 2 additions & 0 deletions migrator/action_trigger.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ func (m *Migrator) migrateCurrentActionTrigger() (err error) {
if err := m.dmOut.DataManager().SetActionTriggers(idg, acts, utils.NonTransactional); err != nil {
return err
}
m.stats[utils.ActionTriggers]++

}
return
}
Expand Down
6 changes: 5 additions & 1 deletion migrator/action_trigger_it_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,9 @@ func testActTrgITMigrateAndMove(t *testing.T) {
}
if !reflect.DeepEqual(actTrg, result) {
t.Errorf("Expecting: %+v,\nReceived: %+v", utils.ToJSON(actTrg), utils.ToJSON(result))
} else if actTrgMigrator.stats[utils.ActionTriggers] != 1 {
t.Errorf("Expecting: 1, received: %+v", actTrgMigrator.stats[utils.ActionTriggers])
}
// utils.tojson si verificat
case utils.Move:
if err := actTrgMigrator.dmIN.DataManager().SetActionTriggers((*v1actTrg)[0].Id, actTrg, utils.NonTransactional); err != nil {
t.Error("Error when setting ActionTriggers ", err.Error())
Expand All @@ -253,5 +254,8 @@ func testActTrgITMigrateAndMove(t *testing.T) {
if !reflect.DeepEqual(actTrg, result) {
t.Errorf("Expecting: %+v, received: %+v", actTrg, result)
}
if actTrgMigrator.stats[utils.ActionTriggers] != 1 {
t.Errorf("Expecting: 1, received: %+v", actTrgMigrator.stats[utils.ActionTriggers])
}
}
}
2 changes: 2 additions & 0 deletions migrator/alias_it_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,5 +231,7 @@ func testAlsITMigrateAndMove(t *testing.T) {
t.Error(err)
} else if !reflect.DeepEqual(expAlsIdx, alsidx) {
t.Errorf("Expected %v, recived: %v", utils.ToJSON(expAlsIdx), utils.ToJSON(alsidx))
} else if alsMigrator.stats[Alias] != 1 {
t.Errorf("Expected 1, recived: %v", alsMigrator.stats[Alias] != 1)
}
}
47 changes: 47 additions & 0 deletions migrator/attributes_it_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,9 @@ func testAttrITMigrateOnlyVersion(t *testing.T) {
} else if vrs[utils.Attributes] != 5 {
t.Errorf("Unexpected version returned: %d", vrs[utils.Attributes])
}
if attrMigrator.stats[utils.Attributes] != 0 {
t.Errorf("Expecting: 0, received: %+v", attrMigrator.stats[utils.Attributes])
}
}

func testAttrITMigrateAndMove(t *testing.T) {
Expand Down Expand Up @@ -374,6 +377,8 @@ func testAttrITMigrateAndMove(t *testing.T) {
attrPrf.Compile()
if !reflect.DeepEqual(result, attrPrf) {
t.Errorf("Expecting: %+v, received: %+v", utils.ToJSON(attrPrf), utils.ToJSON(result))
} else if attrMigrator.stats[utils.Attributes] != 1 {
t.Errorf("Expecting: 1, received: %+v", attrMigrator.stats[utils.Attributes])
}
case utils.Move:
if err := attrMigrator.dmIN.DataManager().SetAttributeProfile(attrPrf, false); err != nil {
Expand Down Expand Up @@ -431,6 +436,8 @@ func testAttrITMigrateAndMove(t *testing.T) {
if _, err = attrMigrator.dmIN.DataManager().GetAttributeProfile("cgrates.com",
"ATTR_1", false, false, utils.NonTransactional); err == nil || err != utils.ErrNotFound {
t.Error(err)
} else if attrMigrator.stats[utils.Attributes] != 2 {
t.Errorf("Expecting: 2, received: %+v", attrMigrator.stats[utils.Attributes])
}
}
}
Expand Down Expand Up @@ -598,6 +605,9 @@ func testAttrITMigrateV3(t *testing.T) {
if !reflect.DeepEqual(result, attrPrf) {
t.Errorf("Expecting: %+v, received: %+v", utils.ToJSON(attrPrf), utils.ToJSON(result))
}
if attrMigrator.stats[utils.Attributes] != 3 {
t.Errorf("Expecting: 3, received: %+v", attrMigrator.stats[utils.Attributes])
}
}

func testAttrITMigrateV4(t *testing.T) {
Expand Down Expand Up @@ -807,6 +817,15 @@ func testAttrITV1ToV5(t *testing.T) {
t.Errorf("Expecting: %+v, received: %+v", utils.ToJSON(eOut2), utils.ToJSON(result))
}
}
if attrAction == utils.Move {
if attrMigrator.stats[utils.Attributes] != 4 {
t.Errorf("Expecting: 4, received: %+v", attrMigrator.stats[utils.Attributes])
}
} else {
if attrMigrator.stats[utils.Attributes] != 6 {
t.Errorf("Expecting: 6, received: %+v", attrMigrator.stats[utils.Attributes])
}
}
}

func testAttrITV2ToV5(t *testing.T) {
Expand Down Expand Up @@ -1065,6 +1084,15 @@ func testAttrITV3ToV5(t *testing.T) {
t.Errorf("Expecting: %+v, received: %+v", utils.ToJSON(eOut2), utils.ToJSON(result))
}
}
if attrAction == utils.Move {
if attrMigrator.stats[utils.Attributes] != 8 {
t.Errorf("Expecting: 8, received: %+v", attrMigrator.stats[utils.Attributes])
}
} else {
if attrMigrator.stats[utils.Attributes] != 10 {
t.Errorf("Expecting: 10, received: %+v", attrMigrator.stats[utils.Attributes])
}
}
}

func testAttrITdryRunV2ToV5(t *testing.T) {
Expand Down Expand Up @@ -1114,6 +1142,16 @@ func testAttrITdryRunV2ToV5(t *testing.T) {
if err != nil && err != utils.ErrNotFound {
t.Errorf("Expecting: %+v, received: %+v", utils.ErrNotFound, err)
}

if attrAction == utils.Move {
if attrMigrator.stats[utils.Attributes] != 9 {
t.Errorf("Expecting: 9, received: %+v", attrMigrator.stats[utils.Attributes])
}
} else {
if attrMigrator.stats[utils.Attributes] != 11 {
t.Errorf("Expecting: 11, received: %+v", attrMigrator.stats[utils.Attributes])
}
}
}

func testAttrITdryRunV3ToV5(t *testing.T) {
Expand Down Expand Up @@ -1162,4 +1200,13 @@ func testAttrITdryRunV3ToV5(t *testing.T) {
if err != nil && err != utils.ErrNotFound {
t.Errorf("Expecting: %+v, received: %+v", utils.ErrNotFound, err)
}
if attrAction == utils.Move {
if attrMigrator.stats[utils.Attributes] != 10 {
t.Errorf("Expecting: 10, received: %+v", attrMigrator.stats[utils.Attributes])
}
} else {
if attrMigrator.stats[utils.Attributes] != 12 {
t.Errorf("Expecting: 12, received: %+v", attrMigrator.stats[utils.Attributes])
}
}
}
1 change: 1 addition & 0 deletions migrator/cdrs.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ func (m *Migrator) migrateCurrentCDRs() (err error) {
if err := m.storDBOut.StorDB().SetCDR(cdr, true); err != nil {
return err
}
m.stats[utils.CDRs]++
}
return
}
Expand Down
3 changes: 3 additions & 0 deletions migrator/cdrs_it_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,4 +185,7 @@ func testCdrITMigrateAndMove(t *testing.T) {
} else if vrs[utils.CDRs] != 2 {
t.Errorf("Unexpected version returned: %d", vrs[utils.CDRs])
}
// else if cdrMigrator.stats[utils.CDRs] != 1 {
// t.Errorf("Expected 1, recived: %v", cdrMigrator.stats[utils.CDRs])
// }
}
2 changes: 2 additions & 0 deletions migrator/chargers_it_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,8 @@ func testChrgITMigrateAndMove(t *testing.T) {
if _, err = chrgMigrator.dmIN.DataManager().GetChargerProfile("cgrates.com",
"CHRG_1", false, false, utils.NonTransactional); err == nil || err != utils.ErrNotFound {
t.Error(err)
} else if chrgMigrator.stats[utils.Chargers] != 2 {
t.Errorf("Expected 2, recived: %v", chrgMigrator.stats[utils.Chargers])
}
}
}
2 changes: 2 additions & 0 deletions migrator/derived_chargers_it_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,8 @@ func testDCITMigrateAndMove(t *testing.T) {
utils.ConcatenatedKey("cgrates.org", utils.MetaChargers),
"", true, true); err == nil || err.Error() != utils.ErrNotFound.Error() {
t.Errorf("Expected error %v, recived: %v with reply: %v", utils.ErrNotFound, err, utils.ToJSON(dcidx))
} else if dcMigrator.stats[utils.DerivedChargersV] != 1 {
t.Errorf("Expected 1, recived: %v", dcMigrator.stats[utils.DerivedChargersV])
}

}
2 changes: 2 additions & 0 deletions migrator/dispatchers_it_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,5 +247,7 @@ func testDspITMigrateAndMove(t *testing.T) {
"ALL", false, false, utils.NonTransactional)
if err != utils.ErrNotFound {
t.Error(err)
} else if dspMigrator.stats[utils.Dispatchers] != 1 {
t.Errorf("Expected 1, recived: %v", dspMigrator.stats[utils.Dispatchers])
}
}
2 changes: 2 additions & 0 deletions migrator/filters_it_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -504,5 +504,7 @@ func testFltrITMigratev3(t *testing.T) {
result.Compile()
if !reflect.DeepEqual(*expFilters, *result) {
t.Errorf("Expecting: %+v, received: %+v", utils.ToJSON(expFilters), utils.ToJSON(result))
} else if fltrMigrator.stats[utils.RQF] != 5 {
t.Errorf("Expected 5, recived: %v", fltrMigrator.stats[utils.RQF])
}
}
2 changes: 2 additions & 0 deletions migrator/rating_plan_it_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,8 @@ func testRtPlITMigrateAndMove(t *testing.T) {
result, err = rtplMigrator.dmIN.DataManager().GetRatingPlan("RT_PLAN1", true, utils.NonTransactional)
if err != utils.ErrNotFound {
t.Error(err)
} else if rtplMigrator.stats[utils.RatingPlan] != 1 {
t.Errorf("Expected 1, recived: %v", rtplMigrator.stats[utils.RatingPlan])
}
}
}
2 changes: 2 additions & 0 deletions migrator/rating_profile_it_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,8 @@ func testRtPrfITMigrateAndMove(t *testing.T) {
result, err = rtprflMigrator.dmIN.DataManager().GetRatingProfile("RT_Profile", true, utils.NonTransactional)
if err != utils.ErrNotFound {
t.Error(err)
} else if rtprflMigrator.stats[utils.RatingProfile] != 1 {
t.Errorf("Expected 1, recived: %v", rtprflMigrator.stats[utils.RatingProfile])
}
}
}
2 changes: 2 additions & 0 deletions migrator/resource_it_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,8 @@ func testResITMigrateAndMove(t *testing.T) {
result, err = resMigrator.dmIN.DataManager().GetResourceProfile("cgrates.org", "RES1", false, false, utils.NonTransactional)
if err != utils.ErrNotFound {
t.Error(err)
} else if resMigrator.stats[utils.Resource] != 1 {
t.Errorf("Expected 1, recived: %v", resMigrator.stats[utils.Resource])
}
}
}
2 changes: 2 additions & 0 deletions migrator/routes_it_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,8 @@ func testSupITMigrateAndMove(t *testing.T) {
result, err = supMigrator.dmIN.DataManager().GetRouteProfile("cgrates.org", "SUP1", false, false, utils.NonTransactional)
if err != utils.ErrNotFound {
t.Error(err)
} else if supMigrator.stats[utils.Routes] != 1 {
t.Errorf("Expected 1, recived: %v", supMigrator.stats[utils.Routes])
}
}
}
2 changes: 2 additions & 0 deletions migrator/session_costs_it_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ func testSessionCostITRename(t *testing.T) {
t.Error(err)
} else if vrs[utils.SessionSCosts] != 2 {
t.Errorf("Unexpected version returned: %d", vrs[utils.SessionSCosts])
} else if sCostMigrator.stats[utils.SessionSCosts] != 0 {
t.Errorf("Expected 0, recived: %v", sCostMigrator.stats[utils.SessionSCosts])
}

}
Expand Down
1 change: 1 addition & 0 deletions migrator/sharedgroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ func (m *Migrator) migrateCurrentSharedGroups() (err error) {
if err := m.dmOut.DataManager().SetSharedGroup(sgs, utils.NonTransactional); err != nil {
return err
}
m.stats[utils.SharedGroups] += 1
}
return
}
Expand Down
4 changes: 4 additions & 0 deletions migrator/sharedgroup_it_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,8 @@ func testShrGrpITMigrateAndMove(t *testing.T) {
}
if !reflect.DeepEqual(shrGrp, result) {
t.Errorf("Expecting: %+v, received: %+v", shrGrp, result)
} else if shrGrpMigrator.stats[utils.SharedGroups] != 1 {
t.Errorf("Expected 1, recived: %v", shrGrpMigrator.stats[utils.SharedGroups])
}
case utils.Move:
if err := shrGrpMigrator.dmIN.DataManager().SetSharedGroup(shrGrp, utils.NonTransactional); err != nil {
Expand All @@ -242,6 +244,8 @@ func testShrGrpITMigrateAndMove(t *testing.T) {
}
if !reflect.DeepEqual(shrGrp, result) {
t.Errorf("Expecting: %+v, received: %+v", shrGrp, result)
} else if shrGrpMigrator.stats[utils.SharedGroups] != 1 {
t.Errorf("Expected 1, recived: %v", shrGrpMigrator.stats[utils.SharedGroups])
}
}
}
4 changes: 3 additions & 1 deletion migrator/thresholds_it_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,9 @@ func testTrsITMigrateAndMove(t *testing.T) {
if !reflect.DeepEqual(tresProf3, result) {
t.Errorf("Expecting: %+v,\nReceived: %+v", utils.ToJSON(tresProf3), utils.ToJSON(result))
}

if trsMigrator.stats[utils.Thresholds] != 4 {
t.Errorf("Expected 4, recived: %v", trsMigrator.stats[utils.Thresholds])
}
case utils.Move:
if err := trsMigrator.dmIN.DataManager().SetThresholdProfile(tresProf, false); err != nil {
t.Error("Error when setting Thresholds ", err.Error())
Expand Down

0 comments on commit b7b5c09

Please sign in to comment.