From 9d18e8adbcdf8980bb4e031a85099f2f8f08c1c0 Mon Sep 17 00:00:00 2001 From: Trial97 Date: Thu, 22 Nov 2018 11:03:03 +0200 Subject: [PATCH] Modified new mongo driver tests --- engine/onstor_it_test.go | 99 +++++++++++++++++++++--------- engine/storage_mongo_datadb_new.go | 1 + 2 files changed, 70 insertions(+), 30 deletions(-) diff --git a/engine/onstor_it_test.go b/engine/onstor_it_test.go index 4314e82e3..f32d932f6 100644 --- a/engine/onstor_it_test.go +++ b/engine/onstor_it_test.go @@ -44,12 +44,12 @@ var ( var sTestsOnStorIT = []func(t *testing.T){ testOnStorITFlush, testOnStorITIsDBEmpty, - // testOnStorITSetGetDerivedCharges, - // testOnStorITCacheDestinations, - // testOnStorITCacheReverseDestinations, - // testOnStorITCacheActionPlan, - // testOnStorITCacheAccountActionPlans, - // testOnStorITCacheDerivedChargers, + testOnStorITSetGetDerivedCharges, + testOnStorITCacheDestinations, + testOnStorITCacheReverseDestinations, + testOnStorITCacheActionPlan, + testOnStorITCacheAccountActionPlans, + testOnStorITCacheDerivedChargers, // ToDo: test cache flush for a prefix // ToDo: testOnStorITLoadAccountingCache @@ -59,11 +59,13 @@ var sTestsOnStorIT = []func(t *testing.T){ testOnStorITRatingProfile, testOnStorITCRUDDestinations, testOnStorITCRUDReverseDestinations, + testOnStorITLCR, testOnStorITActions, testOnStorITSharedGroup, testOnStorITCRUDActionPlan, testOnStorITCRUDAccountActionPlans, testOnStorITCRUDAccount, + testOnStorITCRUDCdrStatsQueue, testOnStorITCRUDSubscribers, testOnStorITResource, testOnStorITResourceProfile, @@ -73,14 +75,15 @@ var sTestsOnStorIT = []func(t *testing.T){ testOnStorITStatQueueProfile, testOnStorITStatQueue, testOnStorITThresholdProfile, - // testOnStorITThreshold, - // testOnStorITFilter, - // testOnStorITSupplierProfile, - // testOnStorITAttributeProfile, - // testOnStorITFlush, - // testOnStorITIsDBEmpty, - // testOnStorITTestAttributeSubstituteIface, - // testOnStorITChargerProfile,//aici + testOnStorITThreshold, + testOnStorITFilter, + testOnStorITSupplierProfile, + testOnStorITAttributeProfile, + testOnStorITFlush, + testOnStorITIsDBEmpty, + testOnStorITTestAttributeSubstituteIface, + testOnStorITChargerProfile, + //testOnStorITCacheActionTriggers, //testOnStorITCacheAlias, //testOnStorITCacheReverseAlias, @@ -714,15 +717,23 @@ func testOnStorITRatingProfile(t *testing.T) { if rcv, err := onStor.GetRatingProfile(rpf.Id, false, utils.NonTransactional); err != nil { t.Error(err) - } else if !reflect.DeepEqual(rpf, rcv) { - t.Errorf("Expecting: %v, received: %v", utils.ToJSON(rpf), utils.ToJSON(rcv)) + } else { + //convert to UTC for mongo that stores the Date as ISODate + rcv.RatingPlanActivations[0].ActivationTime = rcv.RatingPlanActivations[0].ActivationTime.UTC() + if !reflect.DeepEqual(rpf, rcv) { + t.Errorf("Expecting: %v, received: %v", utils.ToJSON(rpf), utils.ToJSON(rcv)) + } } //get from database if rcv, err := onStor.GetRatingProfile(rpf.Id, true, utils.NonTransactional); err != nil { t.Error(err) - } else if !reflect.DeepEqual(rpf, rcv) { - t.Errorf("Expecting: %v, received: %v", rpf, rcv) + } else { + //convert to UTC for mongo that stores the Date as ISODate + rcv.RatingPlanActivations[0].ActivationTime = rcv.RatingPlanActivations[0].ActivationTime.UTC() + if !reflect.DeepEqual(rpf, rcv) { + t.Errorf("Expecting: %v, received: %v", utils.ToJSON(rpf), utils.ToJSON(rcv)) + } } expectedCRPl := []string{"rpf_*out:test:1:trp"} if itm, err := onStor.DataDB().GetKeysForPrefix(utils.RATING_PROFILE_PREFIX); err != nil { @@ -747,15 +758,23 @@ func testOnStorITRatingProfile(t *testing.T) { if rcv, err := onStor.GetRatingProfile(rpf.Id, false, utils.NonTransactional); err != nil { t.Error(err) - } else if !reflect.DeepEqual(rpf, rcv) { - t.Errorf("Expecting: %v, received: %v", rpf, rcv) + } else { + //convert to UTC for mongo that stores the Date as ISODate + rcv.RatingPlanActivations[0].ActivationTime = rcv.RatingPlanActivations[0].ActivationTime.UTC() + if !reflect.DeepEqual(rpf, rcv) { + t.Errorf("Expecting: %v, received: %v", utils.ToJSON(rpf), utils.ToJSON(rcv)) + } } //get from database if rcv, err := onStor.GetRatingProfile(rpf.Id, true, utils.NonTransactional); err != nil { t.Error(err) - } else if !reflect.DeepEqual(rpf, rcv) { - t.Errorf("Expecting: %v, received: %v", rpf, rcv) + } else { + //convert to UTC for mongo that stores the Date as ISODate + rcv.RatingPlanActivations[0].ActivationTime = rcv.RatingPlanActivations[0].ActivationTime.UTC() + if !reflect.DeepEqual(rpf, rcv) { + t.Errorf("Expecting: %v, received: %v", utils.ToJSON(rpf), utils.ToJSON(rcv)) + } } if err = onStor.RemoveRatingProfile(rpf.Id, utils.NonTransactional); err != nil { t.Error(err) @@ -2024,15 +2043,25 @@ func testOnStorITThresholdProfile(t *testing.T) { if rcv, err := onStor.GetThresholdProfile(th.Tenant, th.ID, true, false, utils.NonTransactional); err != nil { t.Error(err) - } else if !reflect.DeepEqual(th, rcv) { - t.Errorf("Expecting: %v, received: %v", utils.ToJSON(th), utils.ToJSON(rcv)) + } else { + //convert to UTC for mongo that stores the Date as ISODate + rcv.ActivationInterval.ActivationTime = rcv.ActivationInterval.ActivationTime.UTC() + rcv.ActivationInterval.ExpiryTime = rcv.ActivationInterval.ExpiryTime.UTC() + if !reflect.DeepEqual(th, rcv) { + t.Errorf("Expecting: %v, received: %v", utils.ToJSON(th), utils.ToJSON(rcv)) + } } //get from database if rcv, err := onStor.GetThresholdProfile(th.Tenant, th.ID, false, false, utils.NonTransactional); err != nil { t.Error(err) - } else if !reflect.DeepEqual(th, rcv) { - t.Errorf("Expecting: %v, received: %v", utils.ToJSON(th), utils.ToJSON(rcv)) + } else { + //convert to UTC for mongo that stores the Date as ISODate + rcv.ActivationInterval.ActivationTime = rcv.ActivationInterval.ActivationTime.UTC() + rcv.ActivationInterval.ExpiryTime = rcv.ActivationInterval.ExpiryTime.UTC() + if !reflect.DeepEqual(th, rcv) { + t.Errorf("Expecting: %v, received: %v", utils.ToJSON(th), utils.ToJSON(rcv)) + } } expectedR := []string{"thp_cgrates.org:test"} if itm, err := onStor.DataDB().GetKeysForPrefix(utils.ThresholdProfilePrefix); err != nil { @@ -2050,15 +2079,25 @@ func testOnStorITThresholdProfile(t *testing.T) { if rcv, err := onStor.GetThresholdProfile(th.Tenant, th.ID, true, false, utils.NonTransactional); err != nil { t.Error(err) - } else if !reflect.DeepEqual(th, rcv) { - t.Errorf("Expecting: %v, received: %v", utils.ToJSON(th), utils.ToJSON(rcv)) + } else { + //convert to UTC for mongo that stores the Date as ISODate + rcv.ActivationInterval.ActivationTime = rcv.ActivationInterval.ActivationTime.UTC() + rcv.ActivationInterval.ExpiryTime = rcv.ActivationInterval.ExpiryTime.UTC() + if !reflect.DeepEqual(th, rcv) { + t.Errorf("Expecting: %v, received: %v", utils.ToJSON(th), utils.ToJSON(rcv)) + } } //get from database if rcv, err := onStor.GetThresholdProfile(th.Tenant, th.ID, false, false, utils.NonTransactional); err != nil { t.Error(err) - } else if !reflect.DeepEqual(th, rcv) { - t.Errorf("Expecting: %v, received: %v", utils.ToJSON(th), utils.ToJSON(rcv)) + } else { + //convert to UTC for mongo that stores the Date as ISODate + rcv.ActivationInterval.ActivationTime = rcv.ActivationInterval.ActivationTime.UTC() + rcv.ActivationInterval.ExpiryTime = rcv.ActivationInterval.ExpiryTime.UTC() + if !reflect.DeepEqual(th, rcv) { + t.Errorf("Expecting: %v, received: %v", utils.ToJSON(th), utils.ToJSON(rcv)) + } } if err := onStor.RemoveThresholdProfile(th.Tenant, th.ID, utils.NonTransactional, false); err != nil { diff --git a/engine/storage_mongo_datadb_new.go b/engine/storage_mongo_datadb_new.go index 8080e6ba7..8e500c347 100644 --- a/engine/storage_mongo_datadb_new.go +++ b/engine/storage_mongo_datadb_new.go @@ -818,6 +818,7 @@ func (ms *MongoStorageNew) UpdateReverseDestination(oldDest, newDest *Destinatio if err = ms.client.UseSession(ms.ctx, func(sctx mongo.SessionContext) (err error) { _, err = ms.getCol(colRds).UpdateOne(sctx, bson.M{"key": addedPrefix}, bson.M{"$addToSet": bson.M{"value": newDest.Id}}, + options.Update().SetUpsert(true), ) return err }); err != nil {