本文整理汇总了Golang中github.com/cgrates/cgrates/engine.CallCost.AsJSON方法的典型用法代码示例。如果您正苦于以下问题:Golang CallCost.AsJSON方法的具体用法?Golang CallCost.AsJSON怎么用?Golang CallCost.AsJSON使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/cgrates/cgrates/engine.CallCost
的用法示例。
在下文中一共展示了CallCost.AsJSON方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestTutLocalGetCosts
//.........这里部分代码省略.........
t.Errorf("Calling Responder.GetCost got callcost: %v", cc.Cost)
}
tStart, _ = utils.ParseDate("2014-08-04T13:00:00Z")
tEnd, _ = utils.ParseDate("2014-08-04T13:00:20Z")
cd = engine.CallDescriptor{
Direction: "*out",
Category: "call",
Tenant: "cgrates.org",
Subject: "1001",
Account: "1001",
Destination: "1004",
DurationIndex: 0,
TimeStart: tStart,
TimeEnd: tEnd,
}
if err := tutLocalRpc.Call("Responder.GetCost", cd, &cc); err != nil {
t.Error("Got error on Responder.GetCost: ", err.Error())
} else if cc.Cost != 1 {
t.Errorf("Calling Responder.GetCost got callcost: %v", cc.Cost)
}
tStart, _ = utils.ParseDate("2014-08-04T13:00:00Z")
tEnd, _ = utils.ParseDate("2014-08-04T13:01:25Z")
cd = engine.CallDescriptor{
Direction: "*out",
Category: "call",
Tenant: "cgrates.org",
Subject: "1001",
Account: "1001",
Destination: "1004",
DurationIndex: 0,
TimeStart: tStart,
TimeEnd: tEnd,
}
if err := tutLocalRpc.Call("Responder.GetCost", cd, &cc); err != nil {
t.Error("Got error on Responder.GetCost: ", err.Error())
} else if cc.Cost != 1.3 {
t.Errorf("Calling Responder.GetCost got callcost: %v", cc.Cost)
}
tStart = time.Date(2014, 8, 4, 13, 0, 0, 0, time.UTC)
cd = engine.CallDescriptor{
Direction: "*out",
Category: "call",
Tenant: "cgrates.org",
Subject: "1001",
Account: "1001",
Destination: "1007",
TimeStart: tStart,
TimeEnd: tStart.Add(time.Duration(50) * time.Second),
}
if err := tutLocalRpc.Call("Responder.GetCost", cd, &cc); err != nil {
t.Error("Got error on Responder.GetCost: ", err.Error())
} else if cc.Cost != 0.5 {
t.Errorf("Calling Responder.GetCost got callcost: %s", cc.AsJSON())
}
cd = engine.CallDescriptor{
Direction: "*out",
Category: "call",
Tenant: "cgrates.org",
Subject: "1001",
Account: "1001",
Destination: "1007",
TimeStart: tStart,
TimeEnd: tStart.Add(time.Duration(70) * time.Second),
}
if err := tutLocalRpc.Call("Responder.GetCost", cd, &cc); err != nil {
t.Error("Got error on Responder.GetCost: ", err.Error())
} else if cc.Cost != 0.62 {
t.Errorf("Calling Responder.GetCost got callcost: %v", cc.Cost)
}
cd = engine.CallDescriptor{
Direction: "*out",
Category: "call",
Tenant: "cgrates.org",
Subject: "1002",
Account: "1002",
Destination: "1007",
TimeStart: tStart,
TimeEnd: tStart.Add(time.Duration(50) * time.Second),
}
if err := tutLocalRpc.Call("Responder.GetCost", cd, &cc); err != nil {
t.Error("Got error on Responder.GetCost: ", err.Error())
} else if cc.Cost != 0.5 {
t.Errorf("Calling Responder.GetCost got callcost: %s", cc.AsJSON())
}
cd = engine.CallDescriptor{
Direction: "*out",
Category: "call",
Tenant: "cgrates.org",
Subject: "1002",
Account: "1002",
Destination: "1007",
TimeStart: tStart,
TimeEnd: tStart.Add(time.Duration(70) * time.Second),
}
if err := tutLocalRpc.Call("Responder.GetCost", cd, &cc); err != nil {
t.Error("Got error on Responder.GetCost: ", err.Error())
} else if cc.Cost != 0.7 { // In case of *disconnect strategy, it will not be applied so we can go on negative costs
t.Errorf("Calling Responder.GetCost got callcost: %s", cc.AsJSON())
}
}