mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-24 00:28:44 +05:00
testing *cgr_rpc
This commit is contained in:
@@ -666,7 +666,6 @@ func cgrRPCAction(account *Account, sq *StatsQueueTriggered, a *Action, acs Acti
|
||||
if err := json.Unmarshal([]byte(a.ExtraParameters), &req); err != nil {
|
||||
return err
|
||||
}
|
||||
log.Printf("REQ: %+v", req)
|
||||
params, err := utils.GetRpcParams(req.Method)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -681,9 +680,12 @@ func cgrRPCAction(account *Account, sq *StatsQueueTriggered, a *Action, acs Acti
|
||||
}
|
||||
|
||||
in, out := params.InParam, params.OutParam
|
||||
log.Print("IN: ", reflect.TypeOf(in))
|
||||
log.Print(req.Param)
|
||||
if err := json.Unmarshal([]byte(req.Param), &in); err != nil {
|
||||
return err
|
||||
}
|
||||
log.Print("IN: ", reflect.TypeOf(in))
|
||||
return client.Call(req.Method, in, out)
|
||||
}
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"reflect"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@@ -2174,8 +2175,32 @@ func (trpcp *TestRPCParameters) Hopa(in Attr, out *float64) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (trpcp *TestRPCParameters) Call(string, interface{}, interface{}) error {
|
||||
return nil
|
||||
func (trpcp *TestRPCParameters) Call(serviceMethod string, args interface{}, reply interface{}) error {
|
||||
parts := strings.Split(serviceMethod, ".")
|
||||
if len(parts) != 2 {
|
||||
return utils.ErrNotImplemented
|
||||
}
|
||||
// get method
|
||||
method := reflect.ValueOf(trpcp).MethodByName(parts[1])
|
||||
if !method.IsValid() {
|
||||
return utils.ErrNotImplemented
|
||||
}
|
||||
|
||||
// construct the params
|
||||
params := []reflect.Value{reflect.ValueOf(args), reflect.ValueOf(reply)}
|
||||
|
||||
ret := method.Call(params)
|
||||
if len(ret) != 1 {
|
||||
return utils.ErrServerError
|
||||
}
|
||||
if ret[0].Interface() == nil {
|
||||
return nil
|
||||
}
|
||||
err, ok := ret[0].Interface().(error)
|
||||
if !ok {
|
||||
return utils.ErrServerError
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func TestCgrRpcAction(t *testing.T) {
|
||||
|
||||
@@ -33,7 +33,7 @@ func RegisterRpcParams(name string, obj rpcclient.RpcClientConnection) {
|
||||
if methodType.NumIn() == 3 { // if it has three parameters (one is self and two are rpc params)
|
||||
rpcParamsMap[name+"."+method.Name] = &RpcParams{
|
||||
Object: obj,
|
||||
InParam: reflect.New(methodType.In(1)).Interface(),
|
||||
InParam: reflect.Zero(methodType.In(1)).Interface(),
|
||||
OutParam: reflect.New(methodType.In(2).Elem()).Interface(),
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user