Update integration tests

This commit is contained in:
TeoV
2019-05-02 15:28:01 +03:00
committed by Dan Christian Bogos
parent a7fb5315db
commit 63ba0ffca7
14 changed files with 57 additions and 36 deletions

View File

@@ -60,16 +60,8 @@ func (rsv1 *ResourceSv1) ReleaseResources(args utils.ArgRSv1ResourceUsage, reply
}
// GetResource returns a resource configuration
func (apierV1 *ApierV1) GetResource(arg utils.TenantID, reply *engine.Resource) error {
if missing := utils.MissingStructFields(&arg, []string{"Tenant", "ID"}); len(missing) != 0 { //Params missing
return utils.NewErrMandatoryIeMissing(missing...)
}
if res, err := apierV1.DataManager.GetResource(arg.Tenant, arg.ID, true, true, utils.NonTransactional); err != nil {
return utils.APIErrorHandler(err)
} else {
*reply = *res
}
return nil
func (rsv1 *ResourceSv1) GetResource(args *utils.TenantID, reply *engine.Resource) error {
return rsv1.rls.V1GetResource(args, reply)
}
// GetResourceProfile returns a resource configuration

View File

@@ -164,6 +164,7 @@ func TestSSv1ItAuth(t *testing.T) {
eSplrs := &engine.SortedSuppliers{
ProfileID: "SPL_ACNT_1001",
Sorting: utils.MetaWeight,
Count: 2,
SortedSuppliers: []*engine.SortedSupplier{
{
SupplierID: "supplier1",
@@ -180,7 +181,7 @@ func TestSSv1ItAuth(t *testing.T) {
},
}
if !reflect.DeepEqual(eSplrs, rply.Suppliers) {
t.Errorf("expecting: %+v, received: %+v", utils.ToJSON(eSplrs), utils.ToJSON(rply.Suppliers))
t.Errorf("expecting: %+v,\n received: %+v", utils.ToJSON(eSplrs), utils.ToJSON(rply.Suppliers))
}
eAttrs := &engine.AttrSProcessEventReply{
MatchedProfiles: []string{"ATTR_ACNT_1001"},
@@ -316,7 +317,7 @@ func TestSSv1ItInitiateSession(t *testing.T) {
if err := sSv1BiRpc.Call(utils.SessionSv1GetActiveSessions, nil, &aSessions); err != nil {
t.Error(err)
} else if len(aSessions) != 2 {
t.Errorf("wrong active sessions: %s", utils.ToJSON(aSessions))
t.Errorf("wrong active sessions: %s \n , and len(aSessions) %+v", utils.ToJSON(aSessions), len(aSessions))
}
}

View File

@@ -144,6 +144,7 @@ func testV1SplSGetWeightSuppliers(t *testing.T) {
eSpls := engine.SortedSuppliers{
ProfileID: "SPL_WEIGHT_1",
Sorting: utils.MetaWeight,
Count: 2,
SortedSuppliers: []*engine.SortedSupplier{
{
SupplierID: "supplier2",
@@ -186,6 +187,7 @@ func testV1SplSGetLeastCostSuppliers(t *testing.T) {
eSpls := engine.SortedSuppliers{
ProfileID: "SPL_LEASTCOST_1",
Sorting: utils.MetaLeastCost,
Count: 3,
SortedSuppliers: []*engine.SortedSupplier{
{
SupplierID: "supplier3",
@@ -241,6 +243,7 @@ func testV1SplSGetLeastCostSuppliersWithMaxCost(t *testing.T) {
eSpls := engine.SortedSuppliers{
ProfileID: "SPL_LEASTCOST_1",
Sorting: utils.MetaLeastCost,
Count: 2,
SortedSuppliers: []*engine.SortedSupplier{
{
SupplierID: "supplier3",
@@ -311,6 +314,7 @@ func testV1SplSGetLeastCostSuppliersWithMaxCost2(t *testing.T) {
eSpls := engine.SortedSuppliers{
ProfileID: "SPL_LEASTCOST_1",
Sorting: utils.MetaLeastCost,
Count: 2,
SortedSuppliers: []*engine.SortedSupplier{
{
SupplierID: "supplier3",
@@ -357,6 +361,7 @@ func testV1SplSGetHighestCostSuppliers(t *testing.T) {
eSpls := engine.SortedSuppliers{
ProfileID: "SPL_HIGHESTCOST_1",
Sorting: utils.MetaHighestCost,
Count: 3,
SortedSuppliers: []*engine.SortedSupplier{
{
SupplierID: "supplier2",
@@ -712,6 +717,7 @@ func testV1SplSGetSupplierWithoutFilter(t *testing.T) {
eSpls := engine.SortedSuppliers{
ProfileID: "SPL_WEIGHT_2",
Sorting: utils.MetaWeight,
Count: 1,
SortedSuppliers: []*engine.SortedSupplier{
{
SupplierID: "supplier1",

View File

@@ -58,7 +58,7 @@ func (self *CmdChargersProcessEvent) RpcParams(reset bool) interface{} {
}
func (self *CmdChargersProcessEvent) PostprocessRpcParams() error {
if self.rpcParams.Time == nil {
if self.rpcParams.CGREvent != nil && self.rpcParams.Time == nil {
self.rpcParams.Time = utils.TimePointer(time.Now())
}
return nil

View File

@@ -34,7 +34,7 @@ func init() {
type CmdDebit struct {
name string
rpcMethod string
rpcParams *engine.CallDescriptor
rpcParams *engine.CallDescriptorWithArgDispatcher
clientArgs []string
*CommandExecuter
}
@@ -49,7 +49,7 @@ func (self *CmdDebit) RpcMethod() string {
func (self *CmdDebit) RpcParams(reset bool) interface{} {
if reset || self.rpcParams == nil {
self.rpcParams = new(engine.CallDescriptor)
self.rpcParams = new(engine.CallDescriptorWithArgDispatcher)
}
return self.rpcParams
}

View File

@@ -34,7 +34,7 @@ func init() {
type CmdMaxDebit struct {
name string
rpcMethod string
rpcParams *engine.CallDescriptor
rpcParams *engine.CallDescriptorWithArgDispatcher
clientArgs []string
*CommandExecuter
}
@@ -49,7 +49,7 @@ func (self *CmdMaxDebit) RpcMethod() string {
func (self *CmdMaxDebit) RpcParams(reset bool) interface{} {
if reset || self.rpcParams == nil {
self.rpcParams = new(engine.CallDescriptor)
self.rpcParams = new(engine.CallDescriptorWithArgDispatcher)
}
return self.rpcParams
}

View File

@@ -38,7 +38,7 @@ func init() {
type CmdGetMaxDuration struct {
name string
rpcMethod string
rpcParams *engine.CallDescriptor
rpcParams *engine.CallDescriptorWithArgDispatcher
clientArgs []string
*CommandExecuter
}
@@ -53,7 +53,7 @@ func (self *CmdGetMaxDuration) RpcMethod() string {
func (self *CmdGetMaxDuration) RpcParams(reset bool) interface{} {
if reset || self.rpcParams == nil {
self.rpcParams = new(engine.CallDescriptor)
self.rpcParams = new(engine.CallDescriptorWithArgDispatcher)
}
return self.rpcParams
}

View File

@@ -110,6 +110,7 @@ func testDspSupGetSupFailover(t *testing.T) {
eRpl1 := &engine.SortedSuppliers{
ProfileID: "SPL_WEIGHT_2",
Sorting: utils.MetaWeight,
Count: 1,
SortedSuppliers: []*engine.SortedSupplier{
{
SupplierID: "supplier1",
@@ -123,6 +124,7 @@ func testDspSupGetSupFailover(t *testing.T) {
eRpl := &engine.SortedSuppliers{
ProfileID: "SPL_ACNT_1002",
Sorting: utils.MetaLeastCost,
Count: 2,
SortedSuppliers: []*engine.SortedSupplier{
{
SupplierID: "supplier1",
@@ -208,6 +210,7 @@ func testDspSupTestAuthKey2(t *testing.T) {
eRpl := &engine.SortedSuppliers{
ProfileID: "SPL_ACNT_1002",
Sorting: utils.MetaLeastCost,
Count: 2,
SortedSuppliers: []*engine.SortedSupplier{
{
SupplierID: "supplier1",
@@ -259,6 +262,7 @@ func testDspSupGetSupRoundRobin(t *testing.T) {
eRpl1 := &engine.SortedSuppliers{
ProfileID: "SPL_WEIGHT_2",
Sorting: utils.MetaWeight,
Count: 1,
SortedSuppliers: []*engine.SortedSupplier{
{
SupplierID: "supplier1",
@@ -272,6 +276,7 @@ func testDspSupGetSupRoundRobin(t *testing.T) {
eRpl := &engine.SortedSuppliers{
ProfileID: "SPL_ACNT_1002",
Sorting: utils.MetaLeastCost,
Count: 2,
SortedSuppliers: []*engine.SortedSupplier{
{
SupplierID: "supplier1",

View File

@@ -152,7 +152,7 @@ func (cS *ChargerService) processEvent(cgrEv *utils.CGREventWithArgDispatcher) (
// V1ProcessEvent will process the event received via API and return list of events forked
func (cS *ChargerService) V1ProcessEvent(args *utils.CGREventWithArgDispatcher,
reply *[]*ChrgSProcessEventReply) (err error) {
if args.Event == nil {
if args.CGREvent == nil || args.Event == nil {
return utils.NewErrMandatoryIeMissing("Event")
}
rply, err := cS.processEvent(args)

View File

@@ -550,8 +550,8 @@ func (fltr *FilterRule) passResourceS(dP config.DataProvider,
}
for _, resItem := range fltr.resourceItems {
//take total usage for resource
var reply *Resource
if err := resourceS.Call(utils.ApierV1GetResource,
var reply Resource
if err := resourceS.Call(utils.ResourceSv1GetResource,
&utils.TenantID{Tenant: tenant, ID: resItem.ItemID}, &reply); err != nil {
return false, err
}

View File

@@ -721,3 +721,16 @@ func (rS *ResourceService) V1ReleaseResource(args utils.ArgRSv1ResourceUsage, re
*reply = utils.OK
return
}
// GetResource returns a resource configuration
func (rS *ResourceService) V1GetResource(arg *utils.TenantID, reply *Resource) error {
if missing := utils.MissingStructFields(arg, []string{"Tenant", "ID"}); len(missing) != 0 { //Params missing
return utils.NewErrMandatoryIeMissing(missing...)
}
if res, err := rS.dm.GetResource(arg.Tenant, arg.ID, true, true, utils.NonTransactional); err != nil {
return err
} else {
*reply = *res
}
return nil
}

View File

@@ -299,12 +299,13 @@ func (spS *SupplierService) statMetrics(statIDs []string, tenant string) (stsMet
func (spS *SupplierService) resourceUsage(resIDs []string, tenant string) (tUsage float64, err error) {
if spS.resourceS != nil {
for _, resID := range resIDs {
var res *Resource
if err = spS.resourceS.Call(utils.ApierV1GetResource,
var res Resource
if err = spS.resourceS.Call(utils.ResourceSv1GetResource,
&utils.TenantID{Tenant: tenant, ID: resID}, &res); err != nil &&
err.Error() != utils.ErrNotFound.Error() {
utils.Logger.Warning(
fmt.Sprintf("<SupplierS> error: %s getting resource for ID : %s", err.Error(), resID))
continue
}
tUsage += res.totalUsage()
}

View File

@@ -471,8 +471,9 @@ func (sS *SessionS) debitSession(s *Session, sRunIdx int, dur time.Duration,
argDsp := s.ArgDispatcher
s.Unlock()
cc := new(engine.CallCost)
if err := sS.ralS.Call(utils.ResponderMaxDebit, &engine.CallDescriptorWithArgDispatcher{CallDescriptor: cd,
ArgDispatcher: argDsp}, cc); err != nil {
if err := sS.ralS.Call(utils.ResponderMaxDebit,
&engine.CallDescriptorWithArgDispatcher{CallDescriptor: cd,
ArgDispatcher: argDsp}, cc); err != nil {
s.Lock()
sr.ExtraDuration += dbtRsrv
s.Unlock()
@@ -606,8 +607,9 @@ func (sS *SessionS) refundSession(s *Session, sRunIdx int, rUsage time.Duration)
Increments: incrmts,
}
var acnt engine.Account
if err = sS.ralS.Call(utils.ResponderRefundIncrements, &engine.CallDescriptorWithArgDispatcher{CallDescriptor: cd,
ArgDispatcher: s.ArgDispatcher}, &acnt); err != nil {
if err = sS.ralS.Call(utils.ResponderRefundIncrements,
&engine.CallDescriptorWithArgDispatcher{CallDescriptor: cd,
ArgDispatcher: s.ArgDispatcher}, &acnt); err != nil {
return
}
if acnt.ID != "" { // Account info updated, update also cached AccountSummary
@@ -913,15 +915,14 @@ func (sS *SessionS) asActiveSessions(fltrs map[string]string,
if len(fltrs) == 0 { // no filters applied
ss := sS.getSessions(utils.EmptyString, psv)
if count {
return nil, len(ss), nil
}
aSs = make([]*ActiveSession, len(ss))
for _, s := range ss {
aSs = append(aSs,
s.AsActiveSessions(sS.cgrCfg.GeneralCfg().DefaultTimezone,
sS.cgrCfg.GeneralCfg().NodeID)...) // Expensive for large number of sessions
}
if count {
return nil, len(aSs), nil
}
return
}
@@ -1330,8 +1331,9 @@ func (sS *SessionS) endSession(s *Session, tUsage, lastUsage *time.Duration) (er
sr.CD.TimeEnd = sr.CD.TimeStart.Add(notCharged)
sr.CD.DurationIndex += notCharged
cc := new(engine.CallCost)
if err = sS.ralS.Call(utils.ResponderDebit, &engine.CallDescriptorWithArgDispatcher{CallDescriptor: sr.CD,
ArgDispatcher: s.ArgDispatcher}, cc); err == nil {
if err = sS.ralS.Call(utils.ResponderDebit,
&engine.CallDescriptorWithArgDispatcher{CallDescriptor: sr.CD,
ArgDispatcher: s.ArgDispatcher}, cc); err == nil {
sr.EventCost.Merge(
engine.NewEventCostFromCallCost(cc, s.CGRID,
sr.Event.GetStringIgnoreErrors(utils.RunID)))
@@ -2401,7 +2403,8 @@ func (sS *SessionS) BiRPCv1ProcessCDR(clnt rpcclient.RpcClientConnection,
}
if s == nil { // no cached session, CDR will be handled by CDRs
return sS.cdrS.Call(utils.CDRsV1ProcessEvent,
&engine.ArgV1ProcessEvent{CGREvent: *cgrEvWithArgDisp.CGREvent,
&engine.ArgV1ProcessEvent{
CGREvent: *cgrEvWithArgDisp.CGREvent,
ArgDispatcher: cgrEvWithArgDisp.ArgDispatcher}, rply)
}

View File

@@ -727,7 +727,6 @@ const (
ApierV1GetDispatcherHost = "ApierV1.GetDispatcherHost"
ApierV1GetDispatcherHostIDs = "ApierV1.GetDispatcherHostIDs"
ApierV1RemoveDispatcherHost = "ApierV1.RemoveDispatcherHost"
ApierV1GetResource = "ApierV1.GetResource"
ApierV1GetEventCost = "ApierV1.GetEventCost"
ApierV1LoadTariffPlanFromFolder = "ApierV1.LoadTariffPlanFromFolder"
ApierV1GetCost = "ApierV1.GetCost"
@@ -833,6 +832,7 @@ const (
ResourceSv1AllocateResources = "ResourceSv1.AllocateResources"
ResourceSv1ReleaseResources = "ResourceSv1.ReleaseResources"
ResourceSv1Ping = "ResourceSv1.Ping"
ResourceSv1GetResource = "ResourceSv1.GetResource"
ApierV1SetResourceProfile = "ApierV1.SetResourceProfile"
ApierV1RemoveResourceProfile = "ApierV1.RemoveResourceProfile"
ApierV1GetResourceProfile = "ApierV1.GetResourceProfile"