Local tests for GetCallCostLog API, LogCallCost and GetCallCostLog storage methods

This commit is contained in:
DanB
2014-03-16 21:01:27 +01:00
parent 86317e4b19
commit e2e3b8d2f2
2 changed files with 46 additions and 0 deletions

View File

@@ -1291,6 +1291,24 @@ func TestResponderGetCost(t *testing.T) {
}
}
// Test here ResponderGetCost
func TestGetCallCostLog(t *testing.T) {
if !*testLocal {
return
}
var cc engine.CallCost
var attrs AttrGetCallCost
// Simple test that command is executed without errors
if err := rater.Call("ApierV1.GetCallCostLog", 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.ERR_NOT_FOUND {
t.Error("ApierV1.GetCallCostLog: should return NOT_FOUND")
}
}
func TestCdrServer(t *testing.T) {
if !*testLocal {
return

View File

@@ -23,6 +23,7 @@ import (
"github.com/cgrates/cgrates/config"
"github.com/cgrates/cgrates/utils"
"path"
"reflect"
"testing"
"time"
)
@@ -304,3 +305,30 @@ func TestGetStoredCdrs(t *testing.T) {
t.Error("Unexpected number of StoredCdrs returned: ", storedCdrs)
}
}
func TestCallCost(t *testing.T) {
if !*testLocal {
return
}
cgrId := utils.FSCgrId("bbb1")
cc := &CallCost{
Timespans: []*TimeSpan{
&TimeSpan{
TimeStart: time.Date(2013, 9, 10, 13, 40, 0, 0, time.UTC),
TimeEnd: time.Date(2013, 9, 10, 13, 41, 0, 0, time.UTC),
},
&TimeSpan{
TimeStart: time.Date(2013, 9, 10, 13, 41, 0, 0, time.UTC),
TimeEnd: time.Date(2013, 9, 10, 13, 41, 30, 0, time.UTC),
},
},
}
if err := mysql.LogCallCost("bbb1", TEST_SQL, TEST_SQL, cc); err != nil {
t.Error(err.Error())
}
if ccRcv, err := mysql.GetCallCostLog(cgrId, TEST_SQL, TEST_SQL); err != nil {
t.Error(err.Error())
} else if !reflect.DeepEqual(cc, ccRcv) {
t.Errorf("Expecting call cost: %v, received: %v", cc, ccRcv)
}
}