Testing tutfscsv including maxDebit and unitsCounter for general usage

This commit is contained in:
DanB
2014-02-25 20:52:11 +01:00
parent 670b748b01
commit 1a8e7f4631
3 changed files with 64 additions and 4 deletions

View File

@@ -88,7 +88,7 @@ type AttrAddBalance struct {
Direction string
Value float64
ExpirationDate time.Time
RateSubject string
RatingSubject string
DestinationId string
Weight float64
Overwrite bool // When true it will reset if the balance is already there
@@ -125,7 +125,7 @@ func (self *ApierV1) AddBalance(attr *AttrAddBalance, reply *string) error {
Balance: &engine.Balance{
Value: attr.Value,
ExpirationDate: attr.ExpirationDate,
RateSubject: attr.RateSubject,
RateSubject: attr.RatingSubject,
DestinationId: attr.DestinationId,
Weight: attr.Weight,
},

View File

@@ -23,6 +23,7 @@ import (
"fmt"
"net/http"
"net/rpc"
"net/rpc/jsonrpc"
"net/url"
"os/exec"
"path"
@@ -136,7 +137,8 @@ func TestRpcConn(t *testing.T) {
return
}
var err error
rater, err = rpc.Dial("tcp", "127.0.0.1:2013") //ToDo: Fix with automatic config
rater, err = jsonrpc.Dial("tcp", fscsvCfg.RPCJSONListen)
//rater, err = rpc.Dial("tcp", "127.0.0.1:2013") //ToDo: Fix with automatic config
if err != nil {
t.Fatal("Could not connect to rater: ", err.Error())
}

View File

@@ -162,6 +162,19 @@ func TestFsCsvLoadTariffPlans(t *testing.T) {
}
}
func TestFsCsvGetAccount(t *testing.T) {
if !*testLocal {
return
}
var reply *engine.Account
attrs := &AttrGetAccount{Tenant: "cgrates.org", Account: "1001", BalanceType: "*monetary", Direction: "*out"}
if err := rater.Call("ApierV1.GetAccount", attrs, &reply); err != nil {
t.Error("Got error on ApierV1.GetAccount: ", err.Error())
} else if reply.BalanceMap[attrs.BalanceType+attrs.Direction].GetTotalValue() != 10.0 { // We expect 11.5 since we have added in the previous test 1.5
t.Errorf("Calling ApierV1.GetBalance expected: 10.0, received: %f", reply.BalanceMap[attrs.BalanceType+attrs.Direction].GetTotalValue())
}
}
func TestFsCsvCall1(t *testing.T) {
if !*testLocal {
return
@@ -180,12 +193,57 @@ func TestFsCsvCall1(t *testing.T) {
CallDuration: 35,
}
var cc engine.CallCost
// Simple test that command is executed without errors
// Make sure the cost is what we expect it is
if err := rater.Call("Responder.GetCost", cd, &cc); err != nil {
t.Error("Got error on Responder.GetCost: ", err.Error())
} else if cc.GetConnectFee() != 0.4 && cc.Cost != 0.6 {
t.Errorf("Calling Responder.GetCost got callcost: %v", cc)
}
// Make sure debit charges what cost returned
if err := rater.Call("Responder.MaxDebit", cd, &cc); err != nil {
t.Error("Got error on Responder.MaxDebit: ", err.Error())
} else if cc.GetConnectFee() != 0.4 && cc.Cost != 0.6 {
t.Errorf("Calling Responder.MaxDebit got callcost: %v", cc)
}
// Make sure the account was debited correctly for the first loop index (ConnectFee included)
var reply *engine.Account
attrs := &AttrGetAccount{Tenant: "cgrates.org", Account: "1001", BalanceType: "*monetary", Direction: "*out"}
if err := rater.Call("ApierV1.GetAccount", attrs, &reply); err != nil {
t.Error("Got error on ApierV1.GetAccount: ", err.Error())
} else if reply.BalanceMap[attrs.BalanceType+attrs.Direction].GetTotalValue() != 9.4 { // We expect 11.5 since we have added in the previous test 1.5
t.Errorf("Calling ApierV1.GetAccount expected: 9.4, received: %f", reply.BalanceMap[attrs.BalanceType+attrs.Direction].GetTotalValue())
} else if len(reply.UnitCounters) != 1 ||
utils.Round(reply.UnitCounters[0].Balances[0].Value, 2, utils.ROUNDING_MIDDLE) != 0.6 { // Make sure we correctly count usage
t.Errorf("Received unexpected UnitCounters: %v", reply.UnitCounters)
}
cd = engine.CallDescriptor{
Direction: "*out",
TOR: "call",
Tenant: "cgrates.org",
Subject: "1001",
Account: "1001",
Destination: "1002",
TimeStart: tStart,
TimeEnd: tEnd,
CallDuration: 35,
LoopIndex: 1, // Should not charge ConnectFee
}
// Make sure debit charges what cost returned
if err := rater.Call("Responder.MaxDebit", cd, &cc); err != nil {
t.Error("Got error on Responder.MaxDebit: ", err.Error())
} else if cc.GetConnectFee() != 0.4 && cc.Cost != 0.2 { // Does not contain connectFee, however connectFee should be correctly reported
t.Errorf("Calling Responder.MaxDebit got callcost: %v", cc)
}
// Make sure the account was debited correctly for the first loop index (ConnectFee included)
var reply2 *engine.Account
if err := rater.Call("ApierV1.GetAccount", attrs, &reply2); err != nil {
t.Error("Got error on ApierV1.GetAccount: ", err.Error())
} else if utils.Round(reply2.BalanceMap[attrs.BalanceType+attrs.Direction].GetTotalValue(), 2, utils.ROUNDING_MIDDLE) != 9.20 {
t.Errorf("Calling ApierV1.GetAccount expected: 9.2, received: %f", reply2.BalanceMap[attrs.BalanceType+attrs.Direction].GetTotalValue())
} else if len(reply2.UnitCounters) != 1 ||
utils.Round(reply2.UnitCounters[0].Balances[0].Value, 2, utils.ROUNDING_MIDDLE) != 0.8 { // Make sure we correctly count usage
t.Errorf("Received unexpected UnitCounters: %v", reply2.UnitCounters)
}
}
// Simply kill the engine after we are done with tests within this file