From f458cc665f10cb627ec751cda6a0cd726cb78402 Mon Sep 17 00:00:00 2001 From: Radu Ioan Fericean Date: Tue, 6 Oct 2015 19:04:03 +0300 Subject: [PATCH] redis passing normal tests --- engine/actions_test.go | 2 +- engine/calldesc.go | 2 -- engine/responder_test.go | 20 ++++++++++---------- engine/storage_mongo.go | 25 +------------------------ 4 files changed, 12 insertions(+), 37 deletions(-) diff --git a/engine/actions_test.go b/engine/actions_test.go index 216db7bd1..c54c3df08 100644 --- a/engine/actions_test.go +++ b/engine/actions_test.go @@ -1079,7 +1079,7 @@ func TestRemoveAction(t *testing.T) { at.Execute() afterUb, err := accountingStorage.GetAccount("*out:cgrates.org:remo") - if err != utils.ErrNotFound || afterUb != nil { + if err == nil || afterUb != nil { t.Error("error removing account: ", err) } } diff --git a/engine/calldesc.go b/engine/calldesc.go index 24774fb34..994899ad3 100644 --- a/engine/calldesc.go +++ b/engine/calldesc.go @@ -777,7 +777,6 @@ func (cd *CallDescriptor) GetLCR(stats StatsInterface, p *utils.Paginator) (*LCR } // sort by activation time lcr.Sort() - // find if one ore more entries apply to this cd (create lcr timespans) // create timespans and attach lcr entries to them lcrCost := &LCRCost{} @@ -819,7 +818,6 @@ func (cd *CallDescriptor) GetLCR(stats StatsInterface, p *utils.Paginator) (*LCR cc, err = lcrCD.debit(cd.account, true, true) } else { cc, err = lcrCD.GetCost() - } //log.Printf("CC: %+v", cc.Timespans[0].ratingInfo.RateIntervals[0].Rating.Rates[0]) if err != nil || cc == nil { diff --git a/engine/responder_test.go b/engine/responder_test.go index b7c4db05e..212a8812c 100644 --- a/engine/responder_test.go +++ b/engine/responder_test.go @@ -54,7 +54,7 @@ func TestResponderGetDerivedChargers(t *testing.T) { } } -func TestGetDerivedMaxSessionTime(t *testing.T) { +func TestResponderGetDerivedMaxSessionTime(t *testing.T) { testTenant := "vdf" cdr := &StoredCdr{CgrId: utils.Sha1("dsafdsaf", time.Date(2013, 11, 7, 8, 42, 26, 0, time.UTC).String()), OrderId: 123, TOR: utils.VOICE, AccId: "dsafdsaf", CdrHost: "192.168.1.1", CdrSource: "test", ReqType: utils.META_RATED, Direction: "*out", Tenant: testTenant, Category: "call", Account: "dan", Subject: "dan", @@ -120,7 +120,7 @@ func TestGetDerivedMaxSessionTime(t *testing.T) { } } -func TestGetSessionRuns(t *testing.T) { +func TestResponderGetSessionRuns(t *testing.T) { testTenant := "vdf" cdr := &StoredCdr{CgrId: utils.Sha1("dsafdsaf", time.Date(2013, 11, 7, 8, 42, 26, 0, time.UTC).String()), OrderId: 123, TOR: utils.VOICE, AccId: "dsafdsaf", CdrHost: "192.168.1.1", CdrSource: "test", ReqType: utils.META_PREPAID, Direction: "*out", Tenant: testTenant, Category: "call", Account: "dan2", Subject: "dan2", @@ -162,7 +162,7 @@ func TestGetSessionRuns(t *testing.T) { } } -func TestGetLCR(t *testing.T) { +func TestResponderGetLCR(t *testing.T) { rsponder.Stats = NewStats(ratingStorage, accountingStorage, 0) // Load stats instance dstDe := &Destination{Id: "GERMANY", Prefixes: []string{"+49"}} if err := ratingStorage.SetDestination(dstDe); err != nil { @@ -368,8 +368,8 @@ func TestGetLCR(t *testing.T) { } if err := ratingStorage.CacheRatingPrefixValues(map[string][]string{ utils.DESTINATION_PREFIX: []string{utils.DESTINATION_PREFIX + dstDe.Id}, - utils.RATING_PLAN_PREFIX: []string{utils.RATING_PLAN_PREFIX + rp1.Id, utils.RATING_PLAN_PREFIX + rp2.Id}, - utils.RATING_PROFILE_PREFIX: []string{utils.RATING_PROFILE_PREFIX + danRpfl.Id, utils.RATING_PROFILE_PREFIX + rifRpfl.Id}, + utils.RATING_PLAN_PREFIX: []string{utils.RATING_PLAN_PREFIX + rp1.Id, utils.RATING_PLAN_PREFIX + rp2.Id, utils.RATING_PLAN_PREFIX + rp3.Id}, + utils.RATING_PROFILE_PREFIX: []string{utils.RATING_PROFILE_PREFIX + danRpfl.Id, utils.RATING_PROFILE_PREFIX + rifRpfl.Id, utils.RATING_PROFILE_PREFIX + ivoRpfl.Id}, utils.LCR_PREFIX: []string{utils.LCR_PREFIX + lcrStatic.GetId(), utils.LCR_PREFIX + lcrLowestCost.GetId()}, }); err != nil { t.Error(err) @@ -398,7 +398,7 @@ func TestGetLCR(t *testing.T) { } else if !reflect.DeepEqual(eStLcr.Entry, lcr.Entry) { t.Errorf("Expecting: %+v, received: %+v", eStLcr.Entry, lcr.Entry) } else if !reflect.DeepEqual(eStLcr.SupplierCosts, lcr.SupplierCosts) { - t.Errorf("Expecting: %+v, received: %+v", eStLcr.SupplierCosts[0], lcr.SupplierCosts[0]) + t.Errorf("Expecting: %+v, received: %+v", eStLcr.SupplierCosts, lcr.SupplierCosts) } // Test *least_cost strategy here cdLowestCost := &CallDescriptor{ @@ -426,7 +426,7 @@ func TestGetLCR(t *testing.T) { t.Errorf("Expecting: %+v, received: %+v", eLcLcr.Entry, lcrLc.Entry) } else if !reflect.DeepEqual(eLcLcr.SupplierCosts, lcrLc.SupplierCosts) { - t.Errorf("Expecting: %+v, received: %+v", eLcLcr.SupplierCosts[1], lcrLc.SupplierCosts[1]) + t.Errorf("Expecting: %+v, received: %+v", eLcLcr.SupplierCosts, lcrLc.SupplierCosts) } bRif12 := &Balance{Value: 40, Weight: 10, DestinationIds: dstDe.Id} bIvo12 := &Balance{Value: 60, Weight: 10, DestinationIds: dstDe.Id} @@ -480,7 +480,7 @@ func TestGetLCR(t *testing.T) { t.Errorf("Expecting: %+v, received: %+v", eQTLcr.Entry, lcrQT.Entry) } else if !reflect.DeepEqual(eQTLcr.SupplierCosts, lcrQT.SupplierCosts) { - t.Errorf("Expecting: %+v, received: %+v", eQTLcr.SupplierCosts[0], lcrQT.SupplierCosts[0]) + t.Errorf("Expecting: %+v, received: %+v", eQTLcr.SupplierCosts, lcrQT.SupplierCosts) } cdr := &StoredCdr{Supplier: "rif12", AnswerTime: time.Now(), Usage: 3 * time.Minute, Cost: 1} rsponder.Stats.AppendCDR(cdr, nil) @@ -499,7 +499,7 @@ func TestGetLCR(t *testing.T) { t.Errorf("Expecting: %+v, received: %+v", eQTLcr.Entry, lcrQT.Entry) } else if !reflect.DeepEqual(eQTLcr.SupplierCosts, lcrQT.SupplierCosts) { - t.Errorf("Expecting: %+v, received: %+v", eQTLcr.SupplierCosts[1], lcrQT.SupplierCosts[1]) + t.Errorf("Expecting: %+v, received: %+v", eQTLcr.SupplierCosts, lcrQT.SupplierCosts) } // Test *qos strategy here @@ -528,6 +528,6 @@ func TestGetLCR(t *testing.T) { t.Errorf("Expecting: %+v, received: %+v", eQosLcr.Entry, lcrQ.Entry) } else if !reflect.DeepEqual(eQosLcr.SupplierCosts, lcrQ.SupplierCosts) { - t.Errorf("Expecting: %+v, %+v, %+v, received: %+v, %+v, %+v", eQosLcr.SupplierCosts[0], eQosLcr.SupplierCosts[1], eQosLcr.SupplierCosts[2], lcrQ.SupplierCosts[0], lcrQ.SupplierCosts[1], lcrQ.SupplierCosts[2]) + t.Errorf("Expecting: %+v, received: %+v", eQosLcr.SupplierCosts, lcrQ.SupplierCosts) } } diff --git a/engine/storage_mongo.go b/engine/storage_mongo.go index b18ca86bf..76a238dc7 100644 --- a/engine/storage_mongo.go +++ b/engine/storage_mongo.go @@ -69,30 +69,7 @@ func (ms *MongoStorage) GetKeysForPrefix(prefix string) ([]string, error) { } func (ms *MongoStorage) Flush(ignore string) (err error) { - err = ms.db.C("ratingprofiles").DropCollection() - if err != nil { - return - } - err = ms.db.C("ratingplans").DropCollection() - if err != nil { - return - } - err = ms.db.C("destinations").DropCollection() - if err != nil { - return - } - err = ms.db.C("actions").DropCollection() - if err != nil { - return - } - err = ms.db.C("userbalances").DropCollection() - if err != nil { - return - } - err = ms.db.C("actiontimings").DropCollection() - if err != nil { - return - } + ms.db.DropDatabase() return nil }