From 926d4d2cd9db770b7fdf7dbd2ff86ca7f6ab1480 Mon Sep 17 00:00:00 2001 From: adragusin Date: Tue, 16 Jun 2020 17:56:15 +0300 Subject: [PATCH] Minor fixes in migrator --- migrator/thresholds.go | 7 +++++-- migrator/thresholds_it_test.go | 35 +++++++++++++++++++++------------- 2 files changed, 27 insertions(+), 15 deletions(-) diff --git a/migrator/thresholds.go b/migrator/thresholds.go index b10a8fe52..04f1c64ef 100644 --- a/migrator/thresholds.go +++ b/migrator/thresholds.go @@ -185,8 +185,11 @@ func (m *Migrator) migrateV2Thresholds() (err error) { if m.dryRun { return } - if err = m.removeV2Thresholds(); err != nil && err != utils.ErrNoMoreData { - return + + if !m.sameDataDB { + if err = m.removeV2Thresholds(); err != nil && err != utils.ErrNoMoreData { + return + } } // All done, update version wtih current one vrs := engine.Versions{utils.Thresholds: engine.CurrentDataDBVersions()[utils.Thresholds]} diff --git a/migrator/thresholds_it_test.go b/migrator/thresholds_it_test.go index c027970e8..6a0202252 100644 --- a/migrator/thresholds_it_test.go +++ b/migrator/thresholds_it_test.go @@ -157,9 +157,14 @@ func testTrsITConnect(t *testing.T) { if err != nil { log.Fatal(err) } - trsMigrator, err = NewMigrator(dataDBIn, dataDBOut, - nil, nil, - false, false, false, false) + if !reflect.DeepEqual(trsCfgIn, trsCfgOut) { + trsMigrator, err = NewMigrator(dataDBIn, dataDBOut, nil, nil, + false, true, false, false) + } else { + trsMigrator, err = NewMigrator(dataDBIn, dataDBOut, nil, nil, + false, false, false, false) + } + if err != nil { log.Fatal(err) } @@ -367,16 +372,20 @@ func testTrsITMigrateAndMove(t *testing.T) { if err != nil { t.Error("Error when getting Thresholds ", err.Error()) } - 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) + if result != nil { + 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) + } + } else { + t.Error("result is nil") } } }