Renamed GetCallCostLog to GetEventCost

This commit is contained in:
Trial97
2018-12-13 16:57:19 +02:00
committed by Dan Christian Bogos
parent 73a369080d
commit 390e56348a
4 changed files with 28 additions and 48 deletions

View File

@@ -1455,15 +1455,15 @@ func TestApierITProcessCdr(t *testing.T) {
// Test here ResponderGetCost
func TestApierGetCallCostLog(t *testing.T) {
var cc engine.SMCost
var cc engine.EventCost
var attrs utils.AttrGetCallCost
// Simple test that command is executed without errors
if err := rater.Call("ApierV1.GetCallCostLog", attrs, &cc); err == nil {
if err := rater.Call("ApierV1.GetEventCost", attrs, &cc); err == nil {
t.Error("Failed to detect missing fields in ApierV1.GetCallCostLog")
}
attrs.CgrId = "dummyid"
attrs.RunId = "default"
if err := rater.Call("ApierV1.GetCallCostLog", attrs, &cc); err == nil || err.Error() != utils.ErrNotFound.Error() {
if err := rater.Call("ApierV1.GetEventCost", attrs, &cc); err == nil || err.Error() != utils.ErrNotFound.Error() {
t.Error("ApierV1.GetCallCostLog: should return NOT_FOUND, got:", err)
}
tm := time.Now().Truncate(time.Millisecond)
@@ -1494,38 +1494,30 @@ func TestApierGetCallCostLog(t *testing.T) {
t.Error("Unexpected reply received: ", reply)
}
time.Sleep(100 * time.Millisecond)
expected := engine.SMCost{
CGRID: "Cdr1",
RunID: "*default",
OriginHost: "192.168.1.1",
OriginID: "OriginCDR1",
CostSource: "*cdrs",
Usage: 0 * time.Second,
CostDetails: &engine.EventCost{
CGRID: "Cdr1",
RunID: "*default",
StartTime: tm,
Usage: utils.DurationPointer(0),
Cost: utils.Float64Pointer(0),
Charges: []*engine.ChargingInterval{{
RatingID: "",
Increments: nil,
CompressFactor: 0,
}},
AccountSummary: nil,
Rating: engine.Rating{},
Accounting: engine.Accounting{},
RatingFilters: engine.RatingFilters{},
Rates: engine.ChargedRates{},
Timings: engine.ChargedTimings{},
},
expected := engine.EventCost{
CGRID: "Cdr1",
RunID: "*default",
StartTime: tm,
Usage: utils.DurationPointer(0),
Cost: utils.Float64Pointer(0),
Charges: []*engine.ChargingInterval{{
RatingID: "",
Increments: nil,
CompressFactor: 0,
}},
AccountSummary: nil,
Rating: engine.Rating{},
Accounting: engine.Accounting{},
RatingFilters: engine.RatingFilters{},
Rates: engine.ChargedRates{},
Timings: engine.ChargedTimings{},
}
attrs.CgrId = "Cdr1"
attrs.RunId = ""
if err := rater.Call("ApierV1.GetCallCostLog", attrs, &cc); err != nil {
if err := rater.Call("ApierV1.GetEventCost", attrs, &cc); err != nil {
t.Error(err)
} else if !reflect.DeepEqual(expected, cc) {
t.Errorf("Expecting %s ,recived %s", utils.ToJSON(expected.CostDetails), utils.ToJSON(cc.CostDetails))
t.Errorf("Expecting %s ,recived %s", utils.ToJSON(expected), utils.ToJSON(cc))
}
}

View File

@@ -27,7 +27,7 @@ import (
)
// Retrieves the callCost out of CGR logDb
func (apier *ApierV1) GetCallCostLog(attrs utils.AttrGetCallCost, reply *engine.SMCost) error {
func (apier *ApierV1) GetEventCost(attrs utils.AttrGetCallCost, reply *engine.EventCost) error {
if attrs.CgrId == "" {
return utils.NewErrMandatoryIeMissing("CgrId")
}
@@ -46,7 +46,7 @@ func (apier *ApierV1) GetCallCostLog(attrs utils.AttrGetCallCost, reply *engine.
} else if len(cdrs) == 0 {
return utils.ErrNotFound
} else {
*reply = *cdrs[0].AsSMCost()
*reply = *cdrs[0].CostDetails
}
return nil
}

View File

@@ -26,7 +26,7 @@ import (
func init() {
c := &CmdGetCostDetails{
name: "cost_details",
rpcMethod: "ApierV1.GetCallCostLog",
rpcMethod: "ApierV1.GetEventCost",
}
commands[c.Name()] = c
c.CommandExecuter = &CommandExecuter{c}
@@ -61,5 +61,5 @@ func (self *CmdGetCostDetails) PostprocessRpcParams() error {
}
func (self *CmdGetCostDetails) RpcResult() interface{} {
return &engine.SMCost{}
return &engine.EventCost{}
}

View File

@@ -102,8 +102,8 @@ type CDR struct {
Partial bool // Used for partial record processing by CDRC
PreRated bool // Mark the CDR as rated so we do not process it during rating
CostSource string // The source of this cost
Cost float64
CostDetails *EventCost // Attach the cost details to CDR when possible
Cost float64 //
CostDetails *EventCost // Attach the cost details to CDR when possible
}
// AddDefaults will add missing information based on other fields
@@ -468,18 +468,6 @@ func (cdr *CDR) AsExternalCDR() *ExternalCDR {
}
}
func (cdr *CDR) AsSMCost() *SMCost {
return &SMCost{
CGRID: cdr.CGRID,
RunID: cdr.RunID,
OriginHost: cdr.OriginHost,
OriginID: cdr.OriginID,
CostSource: cdr.CostSource,
Usage: cdr.Usage,
CostDetails: cdr.CostDetails,
}
}
func (cdr *CDR) String() string {
mrsh, _ := json.Marshal(cdr)
return string(mrsh)