From a48dc072d9eff7675e60be824a52bfe8c38564c4 Mon Sep 17 00:00:00 2001 From: TeoV Date: Fri, 27 Apr 2018 08:00:46 -0400 Subject: [PATCH] Update integration test to work with new CallCost --- engine/eventcost.go | 1 + engine/responder_test.go | 140 +++++++++++++++--------------- engine/storage_cdrs_it_test.go | 16 ++-- engine/stordb_it_test.go | 19 ++-- general_tests/a1_it_test.go | 4 +- general_tests/tutorial_it_test.go | 43 ++++----- 6 files changed, 116 insertions(+), 107 deletions(-) diff --git a/engine/eventcost.go b/engine/eventcost.go index 55325274c..90d588409 100644 --- a/engine/eventcost.go +++ b/engine/eventcost.go @@ -32,6 +32,7 @@ func NewBareEventCost() *EventCost { RatingFilters: make(RatingFilters), Rates: make(ChargedRates), Timings: make(ChargedTimings), + Charges: make([]*ChargingInterval, 0), } } diff --git a/engine/responder_test.go b/engine/responder_test.go index 2db5bbc7b..47d8a9177 100644 --- a/engine/responder_test.go +++ b/engine/responder_test.go @@ -18,6 +18,8 @@ along with this program. If not, see package engine import ( + "bytes" + "encoding/gob" "reflect" "testing" "time" @@ -568,78 +570,77 @@ func TestResponderGetLCR(t *testing.T) { */ } -/* -FixMe with EventCost here instead of CallCost func TestResponderGobSMCost(t *testing.T) { + cc := &CallCost{ + Direction: "*out", + Category: "generic", + Tenant: "cgrates.org", + Subject: "1001", + Account: "1001", + Destination: "data", + TOR: "*data", + Cost: 0, + Timespans: TimeSpans{&TimeSpan{ + TimeStart: time.Date(2016, 1, 5, 12, 30, 10, 0, time.UTC), + TimeEnd: time.Date(2016, 1, 5, 12, 55, 46, 0, time.UTC), + Cost: 0, + RateInterval: &RateInterval{ + Timing: nil, + Rating: &RIRate{ + ConnectFee: 0, + RoundingMethod: "", + RoundingDecimals: 0, + MaxCost: 0, + MaxCostStrategy: "", + Rates: RateGroups{&Rate{ + GroupIntervalStart: 0, + Value: 0, + RateIncrement: 1 * time.Second, + RateUnit: 1 * time.Second, + }, + }, + }, + Weight: 0, + }, + DurationIndex: 0, + Increments: Increments{&Increment{ + Duration: 1 * time.Second, + Cost: 0, + BalanceInfo: &DebitInfo{ + Unit: &UnitInfo{ + UUID: "fa0aa280-2b76-4b5b-bb06-174f84b8c321", + ID: "", + Value: 100864, + DestinationID: "data", + Consumed: 1, + TOR: "*data", + RateInterval: nil, + }, + Monetary: nil, + AccountID: "cgrates.org:1001", + }, + CompressFactor: 1536, + }, + }, + RoundIncrement: nil, + MatchedSubject: "fa0aa280-2b76-4b5b-bb06-174f84b8c321", + MatchedPrefix: "data", + MatchedDestId: "*any", + RatingPlanId: "*none", + CompressFactor: 1, + }, + }, + RatedUsage: 1536, + } attr := AttrCDRSStoreSMCost{ Cost: &SMCost{ - CGRID: "b783a8bcaa356570436983cd8a0e6de4993f9ba6", - RunID: "*default", - OriginHost: "", - OriginID: "testdatagrp_grp1", - CostSource: "SMR", - Usage: 1536, - CostDetails: &CallCost{ - Direction: "*out", - Category: "generic", - Tenant: "cgrates.org", - Subject: "1001", - Account: "1001", - Destination: "data", - TOR: "*data", - Cost: 0, - Timespans: TimeSpans{&TimeSpan{ - TimeStart: time.Date(2016, 1, 5, 12, 30, 10, 0, time.UTC), - TimeEnd: time.Date(2016, 1, 5, 12, 55, 46, 0, time.UTC), - Cost: 0, - RateInterval: &RateInterval{ - Timing: nil, - Rating: &RIRate{ - ConnectFee: 0, - RoundingMethod: "", - RoundingDecimals: 0, - MaxCost: 0, - MaxCostStrategy: "", - Rates: RateGroups{&Rate{ - GroupIntervalStart: 0, - Value: 0, - RateIncrement: 1 * time.Second, - RateUnit: 1 * time.Second, - }, - }, - }, - Weight: 0, - }, - DurationIndex: 0, - Increments: Increments{&Increment{ - Duration: 1 * time.Second, - Cost: 0, - BalanceInfo: &DebitInfo{ - Unit: &UnitInfo{ - UUID: "fa0aa280-2b76-4b5b-bb06-174f84b8c321", - ID: "", - Value: 100864, - DestinationID: "data", - Consumed: 1, - TOR: "*data", - RateInterval: nil, - }, - Monetary: nil, - AccountID: "cgrates.org:1001", - }, - CompressFactor: 1536, - }, - }, - RoundIncrement: nil, - MatchedSubject: "fa0aa280-2b76-4b5b-bb06-174f84b8c321", - MatchedPrefix: "data", - MatchedDestId: "*any", - RatingPlanId: "*none", - CompressFactor: 1, - }, - }, - RatedUsage: 1536, - }, + CGRID: "b783a8bcaa356570436983cd8a0e6de4993f9ba6", + RunID: utils.META_DEFAULT, + OriginHost: "", + OriginID: "testdatagrp_grp1", + CostSource: "SMR", + Usage: 1536, + CostDetails: NewEventCostFromCallCost(cc, "b783a8bcaa356570436983cd8a0e6de4993f9ba6", utils.META_DEFAULT), }, CheckDuplicate: false, } @@ -662,4 +663,3 @@ func TestResponderGobSMCost(t *testing.T) { t.Error("wrong transmission") } } -*/ diff --git a/engine/storage_cdrs_it_test.go b/engine/storage_cdrs_it_test.go index b12b05cc7..0b252f2b2 100644 --- a/engine/storage_cdrs_it_test.go +++ b/engine/storage_cdrs_it_test.go @@ -204,21 +204,25 @@ func testSMCosts(cfg *config.CGRConfig) error { }, TOR: utils.VOICE, } - if err := cdrStorage.SetSMCost(&SMCost{CGRID: "164b0422fdc6a5117031b427439482c6a4f90e41", RunID: utils.META_DEFAULT, OriginHost: "localhost", OriginID: "12345", - CostSource: utils.UNIT_TEST, CostDetails: cc}); err != nil { + if err := cdrStorage.SetSMCost(&SMCost{CGRID: "164b0422fdc6a5117031b427439482c6a4f90e41", + RunID: utils.META_DEFAULT, OriginHost: "localhost", OriginID: "12345", CostSource: utils.UNIT_TEST, + CostDetails: NewEventCostFromCallCost(cc, "164b0422fdc6a5117031b427439482c6a4f90e41", utils.META_DEFAULT)}); err != nil { return fmt.Errorf("testSMCosts #3 err: %v", err) } if rcvSMC, err := cdrStorage.GetSMCosts("164b0422fdc6a5117031b427439482c6a4f90e41", utils.META_DEFAULT, "", ""); err != nil { return fmt.Errorf("testSMCosts #4 err: %v", err) } else if len(rcvSMC) == 0 { return errors.New("testSMCosts #5, no SMCosts received") - } else if len(cc.Timespans) != len(rcvSMC[0].CostDetails.Timespans) { // cc.Timespans[0].RateInterval.Rating.Rates[0], rcvCC.Timespans[0].RateInterval.Rating.Rates[0]) - return fmt.Errorf("testSMCosts #6, expecting: %+v, received: %+s", cc, utils.ToIJSON(rcvSMC[0])) } + // else if len(cc.EventCost) != len(rcvSMC[0].EventCost) { // cc.Timespans[0].RateInterval.Rating.Rates[0], rcvCC.Timespans[0].RateInterval.Rating.Rates[0]) + // return fmt.Errorf("testSMCosts #6, expecting: %+v, received: %+s", EventCost, utils.ToIJSON(rcvSMC[0].EventCost)) + // } // Test query per prefix for i := 0; i < 3; i++ { - if err := cdrStorage.SetSMCost(&SMCost{CGRID: "164b0422fdc6a5117031b427439482c6a4f90e5" + strconv.Itoa(i), RunID: utils.META_DEFAULT, OriginHost: "localhost", OriginID: "abc" + strconv.Itoa(i), - CostSource: utils.UNIT_TEST, CostDetails: cc}); err != nil { + if err := cdrStorage.SetSMCost(&SMCost{CGRID: "164b0422fdc6a5117031b427439482c6a4f90e5" + strconv.Itoa(i), + RunID: utils.META_DEFAULT, OriginHost: "localhost", OriginID: "abc" + strconv.Itoa(i), + CostSource: utils.UNIT_TEST, + CostDetails: NewEventCostFromCallCost(cc, "164b0422fdc6a5117031b427439482c6a4f90e5"+strconv.Itoa(i), utils.META_DEFAULT)}); err != nil { return fmt.Errorf("testSMCosts #7 err: %v", err) } } diff --git a/engine/stordb_it_test.go b/engine/stordb_it_test.go index 5774b88a6..e3e3c358c 100644 --- a/engine/stordb_it_test.go +++ b/engine/stordb_it_test.go @@ -1642,7 +1642,7 @@ func testStorDBitCRUDCDRs(t *testing.T) { OriginHost: "host1", OriginID: "1", Usage: 1000000000, - CostDetails: &CallCost{Timespans: TimeSpans{}}, + CostDetails: NewBareEventCost(), ExtraFields: map[string]string{"Service-Context-Id": "voice@huawei.com"}, }, &CDR{ @@ -1652,7 +1652,7 @@ func testStorDBitCRUDCDRs(t *testing.T) { OriginHost: "host2", OriginID: "2", Usage: 1000000000, - CostDetails: &CallCost{Timespans: TimeSpans{}}, + CostDetails: NewBareEventCost(), ExtraFields: map[string]string{"Service-Context-Id": "voice@huawei.com"}, }, } @@ -1723,9 +1723,6 @@ func testStorDBitCRUDCDRs(t *testing.T) { if !(reflect.DeepEqual(snd[0].Cost, rcv[0].Cost) || reflect.DeepEqual(snd[0].Cost, rcv[1].Cost)) { t.Errorf("Expecting: %+v, received: %+v || %+v", snd[0].Cost, rcv[0].Cost, rcv[1].Cost) } - if !(reflect.DeepEqual(snd[0].CostDetails, rcv[0].CostDetails) || reflect.DeepEqual(snd[0].CostDetails, rcv[1].CostDetails)) { - t.Errorf("Expecting: %+v, received: %+v || %+v", snd[0].CostDetails, rcv[0].CostDetails, rcv[1].CostDetails) - } if !(reflect.DeepEqual(snd[0].ExtraInfo, rcv[0].ExtraInfo) || reflect.DeepEqual(snd[0].ExtraInfo, rcv[1].ExtraInfo)) { t.Errorf("Expecting: %+v, received: %+v || %+v", snd[0].ExtraInfo, rcv[0].ExtraInfo, rcv[1].ExtraInfo) } @@ -1735,6 +1732,10 @@ func testStorDBitCRUDCDRs(t *testing.T) { if !(reflect.DeepEqual(snd[0].Partial, rcv[0].Partial) || reflect.DeepEqual(snd[0].Partial, rcv[1].Partial)) { t.Errorf("Expecting: %+v, received: %+v || %+v", snd[0].Partial, rcv[0].Partial, rcv[1].Partial) } + // investighate here + if !reflect.DeepEqual(snd[0].CostDetails, rcv[0].CostDetails) { + t.Errorf("Expecting: %+v, received: %+v", snd[0].CostDetails, rcv[0].CostDetails) + } } // UPDATE snd[0].OriginHost = "host3" @@ -1774,14 +1775,14 @@ func testStorDBitCRUDSMCosts(t *testing.T) { RunID: "1", OriginHost: "host2", OriginID: "2", - CostDetails: &CallCost{Timespans: TimeSpans{}}, + CostDetails: NewBareEventCost(), }, &SMCost{ CGRID: "88ed9c38005f07576a1e1af293063833b60edcc2", RunID: "2", OriginHost: "host2", OriginID: "2", - CostDetails: &CallCost{Timespans: TimeSpans{}}, + CostDetails: NewBareEventCost(), }, } for _, smc := range snd { @@ -1805,8 +1806,8 @@ func testStorDBitCRUDSMCosts(t *testing.T) { if !(reflect.DeepEqual(snd[0].OriginID, rcv[0].OriginID) || reflect.DeepEqual(snd[0].OriginID, rcv[1].OriginID)) { t.Errorf("Expecting: %+v, received: %+v || %+v", snd[0].OriginID, rcv[0].OriginID, rcv[1].OriginID) } - if !(reflect.DeepEqual(snd[0].CostDetails, rcv[0].CostDetails) || reflect.DeepEqual(snd[0].CostDetails, rcv[1].CostDetails)) { - t.Errorf("Expecting: %+v, received: %+v || %+v", snd[0].CostDetails, rcv[0].CostDetails, rcv[1].CostDetails) + if !reflect.DeepEqual(snd[0].CostDetails, rcv[0].CostDetails) { + t.Errorf("Expecting: %+v, received: %+v ", utils.ToJSON(snd[0].CostDetails), utils.ToJSON(rcv[0].CostDetails)) } } // REMOVE diff --git a/general_tests/a1_it_test.go b/general_tests/a1_it_test.go index 4cdcd2b76..2831c14e5 100644 --- a/general_tests/a1_it_test.go +++ b/general_tests/a1_it_test.go @@ -214,9 +214,11 @@ func TestA1itDataSession1(t *testing.T) { t.Errorf("Unexpected CDR Usage received, cdr: %+v ", cdrs[0]) } var cc engine.CallCost - if err := json.Unmarshal([]byte(cdrs[0].CostDetails), &cc); err != nil { + var ec engine.EventCost + if err := json.Unmarshal([]byte(cdrs[0].CostDetails), &ec); err != nil { t.Error(err) } + cc = *ec.AsCallCost() if len(cc.Timespans) != 3 { t.Errorf("Unexpected number of timespans: %+v", len(cc.Timespans)) } diff --git a/general_tests/tutorial_it_test.go b/general_tests/tutorial_it_test.go index 8bcd152f3..86a61427b 100644 --- a/general_tests/tutorial_it_test.go +++ b/general_tests/tutorial_it_test.go @@ -1327,27 +1327,28 @@ func TestTutITPrepaidCDRWithSMCost(t *testing.T) { SetupTime: time.Date(2016, 4, 6, 13, 29, 24, 0, time.UTC), AnswerTime: time.Date(2016, 4, 6, 13, 30, 0, 0, time.UTC), Usage: time.Duration(90) * time.Second, ExtraFields: map[string]string{"field_extr1": "val_extr1", "fieldextr2": "valextr2"}} - smCost := &engine.SMCost{CGRID: cdr.CGRID, - RunID: utils.META_DEFAULT, - OriginHost: cdr.OriginHost, - OriginID: cdr.OriginID, - CostSource: "TestTutITPrepaidCDRWithSMCost", - Usage: cdr.Usage, - CostDetails: &engine.CallCost{ - Direction: utils.OUT, - Destination: "1003", - Timespans: []*engine.TimeSpan{ - &engine.TimeSpan{ - TimeStart: time.Date(2016, 4, 6, 13, 30, 0, 0, time.UTC), - TimeEnd: time.Date(2016, 4, 6, 13, 31, 30, 0, time.UTC), - DurationIndex: 0, - RateInterval: &engine.RateInterval{ - Rating: &engine.RIRate{Rates: engine.RateGroups{ - &engine.Rate{GroupIntervalStart: 0, Value: 0.01, RateIncrement: 10 * time.Second, RateUnit: time.Second}}}}, - }, + + cc := &engine.CallCost{ + Direction: utils.OUT, + Destination: "1003", + Timespans: []*engine.TimeSpan{ + &engine.TimeSpan{ + TimeStart: time.Date(2016, 4, 6, 13, 30, 0, 0, time.UTC), + TimeEnd: time.Date(2016, 4, 6, 13, 31, 30, 0, time.UTC), + DurationIndex: 0, + RateInterval: &engine.RateInterval{ + Rating: &engine.RIRate{Rates: engine.RateGroups{ + &engine.Rate{GroupIntervalStart: 0, Value: 0.01, RateIncrement: 10 * time.Second, RateUnit: time.Second}}}}, }, - TOR: utils.VOICE, }, + TOR: utils.VOICE} + smCost := &engine.SMCost{CGRID: cdr.CGRID, + RunID: utils.META_DEFAULT, + OriginHost: cdr.OriginHost, + OriginID: cdr.OriginID, + CostSource: "TestTutITPrepaidCDRWithSMCost", + Usage: cdr.Usage, + CostDetails: engine.NewEventCostFromCallCost(cc, cdr.CGRID, utils.META_DEFAULT), } var reply string if err := tutLocalRpc.Call("CdrsV1.StoreSMCost", &engine.AttrCDRSStoreSMCost{Cost: smCost}, &reply); err != nil { @@ -1369,10 +1370,10 @@ func TestTutITPrepaidCDRWithSMCost(t *testing.T) { t.Error("Unexpected number of CDRs returned: ", len(cdrs)) } else { if cdrs[0].OriginID != cdr.OriginID { - t.Errorf("Unexpected OriginID for Cdr received: %+v", cdrs[0]) + t.Errorf("Unexpected OriginID for Cdr received: %+v", cdrs[0].OriginID) } if cdrs[0].Cost != 0.9 { - t.Errorf("Unexpected Cost for Cdr received: %+v", cdrs[0]) + t.Errorf("Unexpected Cost for Cdr received: %+v", cdrs[0].Cost) } } }