mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Aded tests for DispatcherService SupplierSv1
This commit is contained in:
committed by
Dan Christian Bogos
parent
70c0c233d6
commit
fa80474afd
@@ -1944,7 +1944,7 @@ func TestApierPing(t *testing.T) {
|
||||
var reply string
|
||||
for _, method := range []string{utils.StatSv1Ping, utils.ResourceSv1Ping,
|
||||
utils.SupplierSv1Ping, utils.ThresholdSv1Ping, utils.AttributeSv1Ping} {
|
||||
if err := rater.Call(method, utils.CGREvent{}, &reply); err != nil {
|
||||
if err := rater.Call(method, &utils.CGREvent{}, &reply); err != nil {
|
||||
t.Error(err)
|
||||
} else if reply != utils.Pong {
|
||||
t.Errorf("Received: %s", reply)
|
||||
|
||||
@@ -109,7 +109,6 @@ func (dT *DispatcherThresholdSv1) ProcessEvent(args *dispatchers.ArgsProcessEven
|
||||
return dT.dS.ThresholdSv1ProcessEvent(args, tIDs)
|
||||
}
|
||||
|
||||
/*
|
||||
func NewDispatcherStatSv1(dps *dispatchers.DispatcherService) *DispatcherStatSv1 {
|
||||
return &DispatcherStatSv1{dS: dps}
|
||||
}
|
||||
@@ -120,8 +119,8 @@ type DispatcherStatSv1 struct {
|
||||
}
|
||||
|
||||
// Ping implements StatSv1Ping
|
||||
func (dSts *DispatcherStatSv1) Ping(ign string, reply *string) error {
|
||||
return dSts.dS.StatSv1Ping(ign, reply)
|
||||
func (dSts *DispatcherStatSv1) Ping(args *dispatchers.CGREvWithApiKey, reply *string) error {
|
||||
return dSts.dS.StatSv1Ping(args, reply)
|
||||
}
|
||||
|
||||
// GetStatQueuesForEvent implements StatSv1GetStatQueuesForEvent
|
||||
@@ -140,6 +139,7 @@ func (dSts *DispatcherStatSv1) ProcessEvent(args *dispatchers.ArgsStatProcessEve
|
||||
return dSts.dS.StatSv1ProcessEvent(args, reply)
|
||||
}
|
||||
|
||||
/*
|
||||
func NewDispatcherResourceSv1(dps *dispatchers.DispatcherService) *DispatcherResourceSv1 {
|
||||
return &DispatcherResourceSv1{dRs: dps}
|
||||
}
|
||||
@@ -159,7 +159,7 @@ func (dRs *DispatcherResourceSv1) GetResourcesForEvent(args *dispatchers.ArgsV1R
|
||||
reply *engine.Resources) error {
|
||||
return dRs.dRs.ResourceSv1GetResourcesForEvent(args, reply)
|
||||
}
|
||||
|
||||
*/
|
||||
func NewDispatcherSupplierSv1(dps *dispatchers.DispatcherService) *DispatcherSupplierSv1 {
|
||||
return &DispatcherSupplierSv1{dSup: dps}
|
||||
}
|
||||
@@ -170,15 +170,15 @@ type DispatcherSupplierSv1 struct {
|
||||
}
|
||||
|
||||
// Ping implements SupplierSv1Ping
|
||||
func (dSup *DispatcherSupplierSv1) Ping(ign string, reply *string) error {
|
||||
return dSup.dSup.SupplierSv1Ping(ign, reply)
|
||||
func (dSup *DispatcherSupplierSv1) Ping(args *dispatchers.CGREvWithApiKey, reply *string) error {
|
||||
return dSup.dSup.SupplierSv1Ping(args, reply)
|
||||
}
|
||||
|
||||
// GetSuppliers implements SupplierSv1GetSuppliers
|
||||
func (dSup *DispatcherSupplierSv1) GetSuppliers(args *dispatchers.ArgsGetSuppliersWithApiKey,
|
||||
reply *engine.SortedSuppliers) error {
|
||||
return dSup.dSup.SupplierSv1GetSuppliers(args, reply)
|
||||
}*/
|
||||
}
|
||||
|
||||
func NewDispatcherAttributeSv1(dps *dispatchers.DispatcherService) *DispatcherAttributeSv1 {
|
||||
return &DispatcherAttributeSv1{dA: dps}
|
||||
|
||||
@@ -130,7 +130,7 @@ func (stsv1 *StatSv1) GetQueueFloatMetrics(args *utils.TenantID, reply *map[stri
|
||||
return stsv1.sS.V1GetQueueFloatMetrics(args, reply)
|
||||
}
|
||||
|
||||
func (stSv1 *StatSv1) Ping(ign string, reply *string) error {
|
||||
func (stSv1 *StatSv1) Ping(ign *utils.CGREvent, reply *string) error {
|
||||
*reply = utils.Pong
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -421,7 +421,7 @@ func testV1STSRemoveStatQueueProfile(t *testing.T) {
|
||||
|
||||
func testV1STSStatsPing(t *testing.T) {
|
||||
var resp string
|
||||
if err := stsV1Rpc.Call(utils.StatSv1Ping, "", &resp); err != nil {
|
||||
if err := stsV1Rpc.Call(utils.StatSv1Ping, &utils.CGREvent{}, &resp); err != nil {
|
||||
t.Error(err)
|
||||
} else if resp != utils.Pong {
|
||||
t.Error("Unexpected reply returned", resp)
|
||||
|
||||
@@ -102,7 +102,7 @@ func (splv1 *SupplierSv1) GetSuppliers(args *engine.ArgsGetSuppliers,
|
||||
return splv1.splS.V1GetSuppliers(args, reply)
|
||||
}
|
||||
|
||||
func (splv1 *SupplierSv1) Ping(ign string, reply *string) error {
|
||||
func (splv1 *SupplierSv1) Ping(ign *utils.CGREvent, reply *string) error {
|
||||
*reply = utils.Pong
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -973,7 +973,7 @@ func testV1SplSRemSupplierProfiles(t *testing.T) {
|
||||
|
||||
func testV1SplSupplierPing(t *testing.T) {
|
||||
var resp string
|
||||
if err := splSv1Rpc.Call(utils.SupplierSv1Ping, "", &resp); err != nil {
|
||||
if err := splSv1Rpc.Call(utils.SupplierSv1Ping, &utils.CGREvent{}, &resp); err != nil {
|
||||
t.Error(err)
|
||||
} else if resp != utils.Pong {
|
||||
t.Error("Unexpected reply returned", resp)
|
||||
|
||||
@@ -1026,20 +1026,18 @@ func startDispatcherService(internalDispatcherSChan chan *dispatchers.Dispatcher
|
||||
|
||||
server.RpcRegisterName(utils.ThresholdSv1,
|
||||
v1.NewDispatcherThresholdSv1(dspS))
|
||||
|
||||
server.RpcRegisterName(utils.StatSv1,
|
||||
v1.NewDispatcherStatSv1(dspS))
|
||||
/*
|
||||
if !cfg.StatSCfg().Enabled && len(cfg.DispatcherSCfg().StatSConns) != 0 {
|
||||
server.RpcRegisterName(utils.StatSv1,
|
||||
v1.NewDispatcherStatSv1(dspS))
|
||||
}
|
||||
if !cfg.ResourceSCfg().Enabled && len(cfg.DispatcherSCfg().ResSConns) != 0 {
|
||||
server.RpcRegisterName(utils.ResourceSv1,
|
||||
v1.NewDispatcherResourceSv1(dspS))
|
||||
}
|
||||
if !cfg.SupplierSCfg().Enabled && len(cfg.DispatcherSCfg().SupplSConns) != 0 {
|
||||
server.RpcRegisterName(utils.SupplierSv1,
|
||||
v1.NewDispatcherSupplierSv1(dspS))
|
||||
}
|
||||
*/
|
||||
server.RpcRegisterName(utils.SupplierSv1,
|
||||
v1.NewDispatcherSupplierSv1(dspS))
|
||||
|
||||
server.RpcRegisterName(utils.AttributeSv1,
|
||||
v1.NewDispatcherAttributeSv1(dspS))
|
||||
/*
|
||||
|
||||
@@ -44,5 +44,11 @@
|
||||
"enabled": true,
|
||||
},
|
||||
|
||||
"suppliers": {
|
||||
"enabled": true,
|
||||
// "stats_conns": [
|
||||
// {"address": "*internal"},
|
||||
// ],
|
||||
},
|
||||
|
||||
}
|
||||
|
||||
@@ -44,4 +44,11 @@
|
||||
"enabled": true,
|
||||
},
|
||||
|
||||
"suppliers": {
|
||||
"enabled": true,
|
||||
// "stats_conns": [
|
||||
// {"address": "*internal"},
|
||||
// ],
|
||||
},
|
||||
|
||||
}
|
||||
|
||||
@@ -4,5 +4,6 @@ cgrates.org,ATTR_API_ATTR_FAKE_AUTH,*auth,*string:APIKey:12345,,APIMethods,*any,
|
||||
cgrates.org,ATTR_API_ATTR_AUTH,*auth,*string:APIKey:attr12345,,APIMethods,*any,AttributeSv1.Ping&AttributeSv1.GetAttributeForEvent&AttributeSv1.ProcessEvent,true,false,20
|
||||
cgrates.org,ATTR_API_CHRG_AUTH,*auth,*string:APIKey:chrg12345,,APIMethods,*any,ChargerSv1.Ping&ChargerSv1.GetChargersForEvent&ChargerSv1.ProcessEvent,true,false,20
|
||||
cgrates.org,ATTR_API_THR_AUTH,*auth,*string:APIKey:thr12345,,APIMethods,*any,ThresholdSv1.Ping&ThresholdSv1.GetThresholdsForEvent&ThresholdSv1.ProcessEvent,true,false,20
|
||||
cgrates.org,ATTR_API_SUP_AUTH,*auth,*string:APIKey:sup12345,,APIMethods,*any,SupplierSv1.Ping&SupplierSv1.GetSuppliers,true,false,20
|
||||
|
||||
|
||||
|
||||
|
@@ -18,54 +18,62 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
|
||||
package dispatchers
|
||||
|
||||
/*
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
)
|
||||
|
||||
func (dS *DispatcherService) StatSv1Ping(ign string, reply *string) error {
|
||||
if dS.statS == nil {
|
||||
return utils.NewErrNotConnected(utils.StatS)
|
||||
func (dS *DispatcherService) StatSv1Ping(args *CGREvWithApiKey, reply *string) (err error) {
|
||||
if dS.attrS != nil {
|
||||
if err = dS.authorize(utils.StatSv1Ping,
|
||||
args.CGREvent.Tenant,
|
||||
args.APIKey, args.CGREvent.Time); err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
return dS.statS.Call(utils.StatSv1Ping, ign, reply)
|
||||
return dS.Dispatch(&args.CGREvent, utils.MetaStats,
|
||||
utils.StatSv1Ping, args.CGREvent, reply)
|
||||
}
|
||||
|
||||
func (dS *DispatcherService) StatSv1GetStatQueuesForEvent(args *ArgsStatProcessEventWithApiKey,
|
||||
reply *[]string) (err error) {
|
||||
if dS.statS == nil {
|
||||
return utils.NewErrNotConnected(utils.StatS)
|
||||
if dS.attrS != nil {
|
||||
if err = dS.authorize(utils.StatSv1GetStatQueuesForEvent,
|
||||
args.CGREvent.Tenant,
|
||||
args.APIKey, args.CGREvent.Time); err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
if err = dS.authorize(utils.StatSv1GetStatQueuesForEvent, args.CGREvent.Tenant,
|
||||
args.APIKey, args.CGREvent.Time); err != nil {
|
||||
return
|
||||
}
|
||||
return dS.statS.Call(utils.StatSv1GetStatQueuesForEvent, args, reply)
|
||||
return dS.Dispatch(&args.CGREvent, utils.MetaStats,
|
||||
utils.StatSv1GetStatQueuesForEvent, args.StatsArgsProcessEvent, reply)
|
||||
}
|
||||
|
||||
func (dS *DispatcherService) StatSv1GetQueueStringMetrics(args *TntIDWithApiKey,
|
||||
reply *map[string]string) (err error) {
|
||||
if dS.statS == nil {
|
||||
return utils.NewErrNotConnected(utils.StatS)
|
||||
if dS.attrS != nil {
|
||||
if err = dS.authorize(utils.StatSv1GetQueueStringMetrics,
|
||||
args.TenantID.Tenant,
|
||||
args.APIKey, utils.TimePointer(time.Now())); err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
nowTime := time.Now()
|
||||
if err = dS.authorize(utils.StatSv1GetQueueStringMetrics, args.TenantID.Tenant,
|
||||
args.APIKey, &nowTime); err != nil {
|
||||
return
|
||||
}
|
||||
return dS.statS.Call(utils.StatSv1GetQueueStringMetrics, args.TenantID, reply)
|
||||
return dS.Dispatch(&utils.CGREvent{
|
||||
Tenant: args.Tenant,
|
||||
ID: args.ID,
|
||||
}, utils.MetaStats, utils.StatSv1GetQueueStringMetrics,
|
||||
args.TenantID, reply)
|
||||
}
|
||||
|
||||
func (dS *DispatcherService) StatSv1ProcessEvent(args *ArgsStatProcessEventWithApiKey,
|
||||
reply *[]string) (err error) {
|
||||
if dS.statS == nil {
|
||||
return utils.NewErrNotConnected(utils.StatS)
|
||||
if dS.attrS != nil {
|
||||
if err = dS.authorize(utils.StatSv1ProcessEvent,
|
||||
args.CGREvent.Tenant,
|
||||
args.APIKey, args.CGREvent.Time); err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
if err = dS.authorize(utils.StatSv1ProcessEvent, args.CGREvent.Tenant,
|
||||
args.APIKey, args.CGREvent.Time); err != nil {
|
||||
return
|
||||
}
|
||||
return dS.statS.Call(utils.StatSv1ProcessEvent, args, reply)
|
||||
return dS.Dispatch(&args.CGREvent, utils.MetaStats,
|
||||
utils.StatSv1ProcessEvent, args.StatsArgsProcessEvent, reply)
|
||||
}
|
||||
*/
|
||||
|
||||
@@ -18,29 +18,32 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
|
||||
package dispatchers
|
||||
|
||||
/*
|
||||
import (
|
||||
"github.com/cgrates/cgrates/engine"
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
)
|
||||
|
||||
func (dS *DispatcherService) SupplierSv1Ping(ign string, reply *string) error {
|
||||
if dS.splS == nil {
|
||||
return utils.NewErrNotConnected(utils.SupplierS)
|
||||
func (dS *DispatcherService) SupplierSv1Ping(args *CGREvWithApiKey, reply *string) (err error) {
|
||||
if dS.attrS != nil {
|
||||
if err = dS.authorize(utils.SupplierSv1Ping,
|
||||
args.CGREvent.Tenant,
|
||||
args.APIKey, args.CGREvent.Time); err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
return dS.splS.Call(utils.SupplierSv1Ping, ign, reply)
|
||||
return dS.Dispatch(&args.CGREvent, utils.MetaSuppliers,
|
||||
utils.SupplierSv1Ping, args.CGREvent, reply)
|
||||
}
|
||||
|
||||
func (dS *DispatcherService) SupplierSv1GetSuppliers(args *ArgsGetSuppliersWithApiKey,
|
||||
reply *engine.SortedSuppliers) (err error) {
|
||||
if dS.splS == nil {
|
||||
return utils.NewErrNotConnected(utils.SupplierS)
|
||||
if dS.attrS != nil {
|
||||
if err = dS.authorize(utils.SupplierSv1GetSuppliers,
|
||||
args.ArgsGetSuppliers.CGREvent.Tenant,
|
||||
args.APIKey, args.ArgsGetSuppliers.CGREvent.Time); err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
if err = dS.authorize(utils.SupplierSv1GetSuppliers, args.ArgsGetSuppliers.CGREvent.Tenant,
|
||||
args.APIKey, args.ArgsGetSuppliers.CGREvent.Time); err != nil {
|
||||
return
|
||||
}
|
||||
return dS.splS.Call(utils.SupplierSv1GetSuppliers, args.ArgsGetSuppliers, reply)
|
||||
|
||||
return dS.Dispatch(&args.CGREvent, utils.MetaSuppliers,
|
||||
utils.SupplierSv1GetSuppliers, args.ArgsGetSuppliers, reply)
|
||||
}
|
||||
*/
|
||||
|
||||
@@ -21,163 +21,147 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
package dispatchers
|
||||
|
||||
import (
|
||||
"net/rpc"
|
||||
"net/rpc/jsonrpc"
|
||||
"path"
|
||||
"reflect"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/cgrates/cgrates/config"
|
||||
"github.com/cgrates/cgrates/engine"
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
)
|
||||
|
||||
var (
|
||||
dspSupCfgPath string
|
||||
dspSupCfg *config.CGRConfig
|
||||
dspSupRPC *rpc.Client
|
||||
instSupCfgPath string
|
||||
instSupCfg *config.CGRConfig
|
||||
instSupRPC *rpc.Client
|
||||
)
|
||||
|
||||
var sTestsDspSup = []func(t *testing.T){
|
||||
testDspSupInitCfg,
|
||||
testDspSupInitDataDb,
|
||||
testDspSupResetStorDb,
|
||||
testDspSupStartEngine,
|
||||
testDspSupRPCConn,
|
||||
testDspSupPing,
|
||||
testDspSupLoadData,
|
||||
testDspSupAddAttributesWithPermision,
|
||||
testDspSupTestAuthKey,
|
||||
testDspSupAddAttributesWithPermision2,
|
||||
testDspSupTestAuthKey2,
|
||||
testDspSupKillEngine,
|
||||
}
|
||||
|
||||
//Test start here
|
||||
func TestDspSupplierS(t *testing.T) {
|
||||
allEngine = newTestEngine(t, path.Join(dspDataDir, "conf", "samples", "dispatchers", "all"), true, true)
|
||||
allEngine2 = newTestEngine(t, path.Join(dspDataDir, "conf", "samples", "dispatchers", "all2"), true, true)
|
||||
attrEngine = newTestEngine(t, path.Join(dspDataDir, "conf", "samples", "dispatchers", "attributes"), true, true)
|
||||
dispEngine = newTestEngine(t, path.Join(dspDataDir, "conf", "samples", "dispatchers", "dispatchers"), true, true)
|
||||
allEngine.loadData(t, path.Join(dspDataDir, "tariffplans", "tutorial"))
|
||||
allEngine2.loadData(t, path.Join(dspDataDir, "tariffplans", "oldtutorial"))
|
||||
attrEngine.loadData(t, path.Join(dspDataDir, "tariffplans", "dispatchers"))
|
||||
time.Sleep(500 * time.Millisecond)
|
||||
for _, stest := range sTestsDspSup {
|
||||
t.Run("", stest)
|
||||
}
|
||||
}
|
||||
|
||||
func testDspSupInitCfg(t *testing.T) {
|
||||
var err error
|
||||
dspSupCfgPath = path.Join(dspDataDir, "conf", "samples", "dispatcher")
|
||||
dspSupCfg, err = config.NewCGRConfigFromFolder(dspSupCfgPath)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
dspSupCfg.DataFolderPath = dspDataDir // Share DataFolderPath through config towards StoreDb for Flush()
|
||||
config.SetCgrConfig(dspSupCfg)
|
||||
instSupCfgPath = path.Join(dspDataDir, "conf", "samples", "tutmysql")
|
||||
instSupCfg, err = config.NewCGRConfigFromFolder(instSupCfgPath)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
instSupCfg.DataFolderPath = dspDataDir // Share DataFolderPath through config towards StoreDb for Flush()
|
||||
config.SetCgrConfig(instSupCfg)
|
||||
}
|
||||
|
||||
func testDspSupInitDataDb(t *testing.T) {
|
||||
if err := engine.InitDataDb(instSupCfg); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
// Wipe out the cdr database
|
||||
func testDspSupResetStorDb(t *testing.T) {
|
||||
if err := engine.InitStorDb(instSupCfg); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
// Start CGR Engine
|
||||
func testDspSupStartEngine(t *testing.T) {
|
||||
if _, err := engine.StartEngine(instSupCfgPath, dspDelay); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := engine.StartEngine(dspSupCfgPath, dspDelay); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
// Connect rpc client to rater
|
||||
func testDspSupRPCConn(t *testing.T) {
|
||||
var err error
|
||||
instSupRPC, err = jsonrpc.Dial("tcp", instSupCfg.ListenCfg().RPCJSONListen) // We connect over JSON so we can also troubleshoot if needed
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
dspSupRPC, err = jsonrpc.Dial("tcp", dspSupCfg.ListenCfg().RPCJSONListen) // We connect over JSON so we can also troubleshoot if needed
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
attrEngine.stopEngine(t)
|
||||
dispEngine.stopEngine(t)
|
||||
allEngine.stopEngine(t)
|
||||
allEngine2.stopEngine(t)
|
||||
}
|
||||
|
||||
func testDspSupPing(t *testing.T) {
|
||||
var reply string
|
||||
if err := instSupRPC.Call(utils.SupplierSv1Ping, "", &reply); err != nil {
|
||||
if err := allEngine.RCP.Call(utils.SupplierSv1Ping, &utils.CGREvent{}, &reply); err != nil {
|
||||
t.Error(err)
|
||||
} else if reply != utils.Pong {
|
||||
t.Errorf("Received: %s", reply)
|
||||
}
|
||||
if err := dspSupRPC.Call(utils.SupplierSv1Ping, "", &reply); err != nil {
|
||||
t.Error(err)
|
||||
} else if reply != utils.Pong {
|
||||
t.Errorf("Received: %s", reply)
|
||||
}
|
||||
}
|
||||
|
||||
func testDspSupLoadData(t *testing.T) {
|
||||
var reply string
|
||||
attrs := &utils.AttrLoadTpFromFolder{
|
||||
FolderPath: path.Join(dspDataDir, "tariffplans", "tutorial")}
|
||||
if err := instSupRPC.Call("ApierV1.LoadTariffPlanFromFolder", attrs, &reply); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
time.Sleep(500 * time.Millisecond)
|
||||
}
|
||||
|
||||
func testDspSupAddAttributesWithPermision(t *testing.T) {
|
||||
alsPrf := &engine.AttributeProfile{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "AuthKey",
|
||||
Contexts: []string{utils.MetaAuth},
|
||||
FilterIDs: []string{"*string:APIKey:12345"},
|
||||
ActivationInterval: &utils.ActivationInterval{
|
||||
ActivationTime: time.Date(2014, 7, 14, 14, 35, 0, 0, time.UTC),
|
||||
if err := dispEngine.RCP.Call(utils.SupplierSv1Ping, &CGREvWithApiKey{
|
||||
CGREvent: utils.CGREvent{
|
||||
Tenant: "cgrates.org",
|
||||
},
|
||||
Attributes: []*engine.Attribute{
|
||||
APIKey: "sup12345",
|
||||
}, &reply); err != nil {
|
||||
t.Error(err)
|
||||
} else if reply != utils.Pong {
|
||||
t.Errorf("Received: %s", reply)
|
||||
}
|
||||
}
|
||||
|
||||
func testDspSupPingFailover(t *testing.T) {
|
||||
var reply string
|
||||
if err := allEngine.RCP.Call(utils.SupplierSv1Ping, &utils.CGREvent{}, &reply); err != nil {
|
||||
t.Error(err)
|
||||
} else if reply != utils.Pong {
|
||||
t.Errorf("Received: %s", reply)
|
||||
}
|
||||
ev := CGREvWithApiKey{
|
||||
CGREvent: utils.CGREvent{
|
||||
Tenant: "cgrates.org",
|
||||
},
|
||||
APIKey: "sup12345",
|
||||
}
|
||||
if err := dispEngine.RCP.Call(utils.SupplierSv1Ping, &ev, &reply); err != nil {
|
||||
t.Error(err)
|
||||
} else if reply != utils.Pong {
|
||||
t.Errorf("Received: %s", reply)
|
||||
}
|
||||
allEngine.stopEngine(t)
|
||||
if err := dispEngine.RCP.Call(utils.SupplierSv1Ping, &ev, &reply); err != nil {
|
||||
t.Error(err)
|
||||
} else if reply != utils.Pong {
|
||||
t.Errorf("Received: %s", reply)
|
||||
}
|
||||
allEngine2.stopEngine(t)
|
||||
if err := dispEngine.RCP.Call(utils.SupplierSv1Ping, &ev, &reply); err == nil {
|
||||
t.Errorf("Expected error but recived %v and reply %v\n", err, reply)
|
||||
}
|
||||
allEngine.startEngine(t)
|
||||
allEngine2.startEngine(t)
|
||||
}
|
||||
|
||||
func testDspSupGetSupFailover(t *testing.T) {
|
||||
var rpl *engine.SortedSuppliers
|
||||
eRpl := &engine.SortedSuppliers{
|
||||
ProfileID: "SPL_ACNT_1002",
|
||||
Sorting: utils.MetaLeastCost,
|
||||
SortedSuppliers: []*engine.SortedSupplier{
|
||||
{
|
||||
FieldName: utils.APIMethods,
|
||||
Initial: utils.META_ANY,
|
||||
Substitute: config.NewRSRParsersMustCompile("ThresholdSv1.GetThresholdsForEvent", true, utils.INFIELD_SEP),
|
||||
Append: true,
|
||||
SupplierID: "supplier1",
|
||||
SupplierParameters: "",
|
||||
SortingData: map[string]interface{}{
|
||||
utils.Cost: 0.1166,
|
||||
utils.RatingPlanID: "RP_1002_LOW",
|
||||
utils.Weight: 10.0,
|
||||
},
|
||||
},
|
||||
{
|
||||
SupplierID: "supplier2",
|
||||
SupplierParameters: "",
|
||||
SortingData: map[string]interface{}{
|
||||
utils.Cost: 0.2334,
|
||||
utils.RatingPlanID: "RP_1002",
|
||||
utils.Weight: 20.0,
|
||||
},
|
||||
},
|
||||
},
|
||||
Weight: 20,
|
||||
}
|
||||
var result string
|
||||
if err := instSupRPC.Call("ApierV1.SetAttributeProfile", alsPrf, &result); err != nil {
|
||||
args := &ArgsGetSuppliersWithApiKey{
|
||||
APIKey: "sup12345",
|
||||
ArgsGetSuppliers: engine.ArgsGetSuppliers{
|
||||
CGREvent: utils.CGREvent{
|
||||
Tenant: "cgrates.org",
|
||||
ID: utils.UUIDSha1Prefix(),
|
||||
Time: &nowTime,
|
||||
Event: map[string]interface{}{
|
||||
utils.EVENT_NAME: "Event1",
|
||||
utils.Account: "1002",
|
||||
utils.Subject: "1002",
|
||||
utils.Destination: "1001",
|
||||
utils.SetupTime: time.Date(2017, 12, 1, 14, 25, 0, 0, time.UTC),
|
||||
utils.Usage: "1m20s",
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
if err := dispEngine.RCP.Call(utils.SupplierSv1GetSuppliers,
|
||||
args, &rpl); err == nil || err.Error() != utils.ErrNotFound.Error() {
|
||||
t.Errorf("Expected error NOT_FOUND but recived %v and reply %v\n", err, rpl)
|
||||
}
|
||||
allEngine2.stopEngine(t)
|
||||
if err := dispEngine.RCP.Call(utils.SupplierSv1GetSuppliers,
|
||||
args, &rpl); err != nil {
|
||||
t.Error(err)
|
||||
} else if result != utils.OK {
|
||||
t.Error("Unexpected reply returned", result)
|
||||
}
|
||||
alsPrf.Compile()
|
||||
var reply *engine.AttributeProfile
|
||||
if err := instSupRPC.Call("ApierV1.GetAttributeProfile",
|
||||
&utils.TenantID{Tenant: "cgrates.org", ID: "AuthKey"}, &reply); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
reply.Compile()
|
||||
if !reflect.DeepEqual(alsPrf, reply) {
|
||||
t.Errorf("Expecting : %+v, received: %+v", alsPrf, reply)
|
||||
} else if !reflect.DeepEqual(eRpl, rpl) {
|
||||
t.Errorf("Expecting : %+v, received: %+v", utils.ToJSON(eRpl), utils.ToJSON(rpl))
|
||||
}
|
||||
allEngine2.startEngine(t)
|
||||
}
|
||||
|
||||
func testDspSupTestAuthKey(t *testing.T) {
|
||||
@@ -199,49 +183,12 @@ func testDspSupTestAuthKey(t *testing.T) {
|
||||
},
|
||||
},
|
||||
}
|
||||
if err := dspSupRPC.Call(utils.SupplierSv1GetSuppliers,
|
||||
if err := dispEngine.RCP.Call(utils.SupplierSv1GetSuppliers,
|
||||
args, &rpl); err == nil || err.Error() != utils.ErrUnauthorizedApi.Error() {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func testDspSupAddAttributesWithPermision2(t *testing.T) {
|
||||
alsPrf := &engine.AttributeProfile{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "AuthKey",
|
||||
Contexts: []string{utils.MetaAuth},
|
||||
FilterIDs: []string{"*string:APIKey:12345"},
|
||||
ActivationInterval: &utils.ActivationInterval{
|
||||
ActivationTime: time.Date(2014, 7, 14, 14, 35, 0, 0, time.UTC),
|
||||
},
|
||||
Attributes: []*engine.Attribute{
|
||||
{
|
||||
FieldName: utils.APIMethods,
|
||||
Initial: utils.META_ANY,
|
||||
Substitute: config.NewRSRParsersMustCompile("ThresholdSv1.ProcessEvent&SupplierSv1.GetSuppliers", true, utils.INFIELD_SEP),
|
||||
Append: true,
|
||||
},
|
||||
},
|
||||
Weight: 20,
|
||||
}
|
||||
var result string
|
||||
if err := instSupRPC.Call("ApierV1.SetAttributeProfile", alsPrf, &result); err != nil {
|
||||
t.Error(err)
|
||||
} else if result != utils.OK {
|
||||
t.Error("Unexpected reply returned", result)
|
||||
}
|
||||
alsPrf.Compile()
|
||||
var reply *engine.AttributeProfile
|
||||
if err := instSupRPC.Call("ApierV1.GetAttributeProfile",
|
||||
&utils.TenantID{Tenant: "cgrates.org", ID: "AuthKey"}, &reply); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
reply.Compile()
|
||||
if !reflect.DeepEqual(alsPrf, reply) {
|
||||
t.Errorf("Expecting : %+v, received: %+v", alsPrf, reply)
|
||||
}
|
||||
}
|
||||
|
||||
func testDspSupTestAuthKey2(t *testing.T) {
|
||||
var rpl *engine.SortedSuppliers
|
||||
eRpl := &engine.SortedSuppliers{
|
||||
@@ -269,7 +216,7 @@ func testDspSupTestAuthKey2(t *testing.T) {
|
||||
},
|
||||
}
|
||||
args := &ArgsGetSuppliersWithApiKey{
|
||||
APIKey: "12345",
|
||||
APIKey: "sup12345",
|
||||
ArgsGetSuppliers: engine.ArgsGetSuppliers{
|
||||
CGREvent: utils.CGREvent{
|
||||
Tenant: "cgrates.org",
|
||||
@@ -285,19 +232,10 @@ func testDspSupTestAuthKey2(t *testing.T) {
|
||||
},
|
||||
},
|
||||
}
|
||||
if err := dspSupRPC.Call(utils.SupplierSv1GetSuppliers,
|
||||
if err := dispEngine.RCP.Call(utils.SupplierSv1GetSuppliers,
|
||||
args, &rpl); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(eRpl, rpl) {
|
||||
t.Errorf("Expecting : %+v, received: %+v", utils.ToJSON(eRpl), utils.ToJSON(rpl))
|
||||
}
|
||||
}
|
||||
|
||||
func testDspSupKillEngine(t *testing.T) {
|
||||
if err := engine.KillEngine(dspDelay); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if err := engine.KillEngine(dspDelay); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user