diff --git a/apier/apier_local_test.go b/apier/apier_local_test.go index 006791019..f0f7470e9 100644 --- a/apier/apier_local_test.go +++ b/apier/apier_local_test.go @@ -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 diff --git a/engine/storage_sql_local_test.go b/engine/storage_sql_local_test.go index e10b5b0c6..06b8dcd89 100644 --- a/engine/storage_sql_local_test.go +++ b/engine/storage_sql_local_test.go @@ -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) + } +}