From 8f0a3b50b8cc75e2968177efec909522d295e267 Mon Sep 17 00:00:00 2001 From: edwardro22 Date: Mon, 4 Dec 2017 04:24:58 +0000 Subject: [PATCH] fixed failing integration tests --- apier/v1/stats_it_test.go | 4 +-- apier/v1/suppliers_it_test.go | 17 +++++++----- apier/v1/thresholds_it_test.go | 4 +-- utils/cgrevent_test.go | 48 +++++++++++++++++++++++++++++++++- 4 files changed, 61 insertions(+), 12 deletions(-) diff --git a/apier/v1/stats_it_test.go b/apier/v1/stats_it_test.go index 55ba3e544..ce5566b6b 100644 --- a/apier/v1/stats_it_test.go +++ b/apier/v1/stats_it_test.go @@ -279,8 +279,8 @@ func testV1STSSetStatQueueProfile(t *testing.T) { ID: "TEST_PROFILE1", FilterIDs: []string{"FLTR_1"}, ActivationInterval: &utils.ActivationInterval{ - ActivationTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC), - ExpiryTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC), + ActivationTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC).Local(), + ExpiryTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC).Local(), }, QueueLength: 10, TTL: time.Duration(10) * time.Second, diff --git a/apier/v1/suppliers_it_test.go b/apier/v1/suppliers_it_test.go index 291817990..0e9622e38 100644 --- a/apier/v1/suppliers_it_test.go +++ b/apier/v1/suppliers_it_test.go @@ -156,7 +156,7 @@ func testV1SplSGetWeightSuppliers(t *testing.T) { } func testV1SplSGetLeastCostSuppliers(t *testing.T) { - ev := &engine.SupplierEvent{ + ev := &utils.CGREvent{ Tenant: "cgrates.org", ID: "testV1SplSGetLeastCostSuppliers", Event: map[string]interface{}{ @@ -174,22 +174,25 @@ func testV1SplSGetLeastCostSuppliers(t *testing.T) { &engine.SortedSupplier{ SupplierID: "supplier3", SortingData: map[string]interface{}{ - utils.Cost: 0.02, - utils.Weight: 15.0, + utils.Cost: 0.02, + utils.RatingPlanID: "RP_SPECIAL_1002", + utils.Weight: 15.0, }, }, &engine.SortedSupplier{ SupplierID: "supplier1", SortingData: map[string]interface{}{ - utils.Cost: 0.02, - utils.Weight: 10.0, + utils.Cost: 0.02, + utils.RatingPlanID: "RP_SPECIAL_1002", + utils.Weight: 10.0, }, }, &engine.SortedSupplier{ SupplierID: "supplier2", SortingData: map[string]interface{}{ - utils.Cost: 0.46666, - utils.Weight: 20.0, + utils.Cost: 0.46666, + utils.RatingPlanID: "RP_RETAIL1", + utils.Weight: 20.0, }, }, }, diff --git a/apier/v1/thresholds_it_test.go b/apier/v1/thresholds_it_test.go index 762c99c19..49063fcce 100644 --- a/apier/v1/thresholds_it_test.go +++ b/apier/v1/thresholds_it_test.go @@ -356,8 +356,8 @@ func testV1TSSetThresholdProfile(t *testing.T) { ID: "TEST_PROFILE1", FilterIDs: []string{"FilterID1", "FilterID2"}, ActivationInterval: &utils.ActivationInterval{ - ActivationTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC), - ExpiryTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC), + ActivationTime: time.Date(2014, 7, 14, 14, 35, 0, 0, time.UTC).Local(), + ExpiryTime: time.Date(2014, 7, 14, 14, 35, 0, 0, time.UTC).Local(), }, Recurrent: true, MinSleep: time.Duration(5 * time.Minute), diff --git a/utils/cgrevent_test.go b/utils/cgrevent_test.go index 478d1fc12..6cb4a8c18 100644 --- a/utils/cgrevent_test.go +++ b/utils/cgrevent_test.go @@ -18,6 +18,8 @@ along with this program. If not, see package utils import ( + "fmt" + "reflect" "testing" "time" ) @@ -115,4 +117,48 @@ func TestCGREventFieldAsString(t *testing.T) { } } -//float , float in string time duration +func TestCGREventFieldAsFloat64(t *testing.T) { + err1 := fmt.Errorf("cannot cast %s to string", ANSWER_TIME) + event := make(map[string]interface{}) + event[ANSWER_TIME] = time.Now().Local() + event["supplierprofile1"] = "Supplier" + event["UsageInterval"] = "54.2" + event["PddInterval"] = "1s" + event["Weight"] = 20.0 + se := &CGREvent{ + Tenant: "cgrates.org", + ID: "supplierevent1", + Event: event, + } + answ, err := se.FieldAsFloat64("UsageInterval") + if err != nil { + t.Error(err) + } + if answ != float64(54.2) { + t.Errorf("Expecting: %+v, received: %+v", event["UsageInterval"], answ) + } + answ, err = se.FieldAsFloat64("Weight") + if err != nil { + t.Error(err) + } + if answ != float64(20.0) { + t.Errorf("Expecting: %+v, received: %+v", event["Weight"], answ) + } + answ, err = se.FieldAsFloat64("PddInterval") + //TODO: Make an error to be expected : + // cgrevent_test.go:149: strconv.ParseFloat: parsing "1s": invalid syntax + // if err != nil { + // t.Error(err) + // } + if answ != 0 { + t.Errorf("Expecting: %+v, received: %+v", 0, answ) + } + + answ, err = se.FieldAsFloat64(ANSWER_TIME) + if !reflect.DeepEqual(err, err1) { + t.Error(err) + } + if answ != 0 { + t.Errorf("Expecting: %+v, received: %+v", 0, answ) + } +}