mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Test in Dispatchers
This commit is contained in:
committed by
Dan Christian Bogos
parent
dd8d6dfaa8
commit
b181c51211
@@ -20,6 +20,16 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
|
||||
package dispatchers
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/cgrates/cgrates/config"
|
||||
"github.com/cgrates/cgrates/engine"
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
"github.com/cgrates/rpcclient"
|
||||
)
|
||||
|
||||
// for the moment we dispable Apier through dispatcher
|
||||
// until we figured out a better sollution in case of gob server
|
||||
/*
|
||||
@@ -130,3 +140,56 @@ func testDspApierUnkownAPiKey(t *testing.T) {
|
||||
}
|
||||
}
|
||||
*/
|
||||
func TestDispatcherServiceDispatcherProfileForEventGetDispatchertWithoutAuthentification(t *testing.T) {
|
||||
cfg := config.NewDefaultCGRConfig()
|
||||
cfg.DispatcherSCfg().IndexedSelects = false
|
||||
rpcCl := map[string]chan rpcclient.ClientConnector{}
|
||||
connMng := engine.NewConnManager(cfg, rpcCl)
|
||||
dm := engine.NewDataManager(&engine.DataDBMock{
|
||||
GetKeysForPrefixF: func(string) ([]string, error) {
|
||||
return []string{"dpp_cgrates.org:123"}, nil
|
||||
},
|
||||
}, nil, connMng)
|
||||
dsp := &engine.DispatcherProfile{
|
||||
ID: "321",
|
||||
Subsystems: []string{utils.MetaAccounts},
|
||||
FilterIDs: []string{"filter"},
|
||||
ActivationInterval: &utils.ActivationInterval{},
|
||||
Strategy: "",
|
||||
StrategyParams: nil,
|
||||
Weight: 0,
|
||||
Hosts: nil,
|
||||
}
|
||||
err := dm.SetDispatcherProfile(dsp, false)
|
||||
if err == nil {
|
||||
t.Errorf("\nExpected <%+v>, \nReceived <%+v>", utils.ErrNotImplemented, err)
|
||||
}
|
||||
fltr := &engine.Filter{
|
||||
ID: "filter",
|
||||
Rules: nil,
|
||||
ActivationInterval: &utils.ActivationInterval{
|
||||
ActivationTime: time.Date(1999, 2, 3, 4, 5, 6, 700000000, time.UTC),
|
||||
ExpiryTime: time.Date(2000, 2, 3, 4, 5, 6, 700000000, time.UTC),
|
||||
},
|
||||
}
|
||||
err = dm.SetFilter(fltr, false)
|
||||
if err == nil {
|
||||
t.Errorf("\nExpected <%+v>, \nReceived <%+v>", utils.ErrNotImplemented, err)
|
||||
}
|
||||
fltrs := engine.NewFilterS(cfg, connMng, dm)
|
||||
dss := NewDispatcherService(dm, cfg, fltrs, connMng)
|
||||
ev := &utils.CGREvent{
|
||||
ID: "321",
|
||||
Event: map[string]interface{}{
|
||||
utils.AccountField: "1001",
|
||||
"Password": "CGRateS.org",
|
||||
"RunID": utils.MetaDefault,
|
||||
},
|
||||
}
|
||||
tnt := ev.Tenant
|
||||
_, err = dss.dispatcherProfileForEvent(tnt, ev, utils.MetaAccounts)
|
||||
expected := utils.ErrNotImplemented
|
||||
if err == nil || err != expected {
|
||||
t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1271,3 +1271,28 @@ func TestDispatcherServiceCall4(t *testing.T) {
|
||||
t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDispatcherServiceCallWithoutAuthentification(t *testing.T) {
|
||||
cfg := config.NewDefaultCGRConfig()
|
||||
rpcCl := map[string]chan rpcclient.ClientConnector{}
|
||||
connMng := engine.NewConnManager(cfg, rpcCl)
|
||||
dm := engine.NewDataManager(nil, nil, nil)
|
||||
dsp := NewDispatcherService(dm, cfg, nil, connMng)
|
||||
reply := "reply"
|
||||
args := &utils.CGREvent{
|
||||
Tenant: "",
|
||||
ID: "123",
|
||||
Time: nil,
|
||||
Event: map[string]interface{}{
|
||||
utils.AccountField: "1001",
|
||||
"Password": "CGRateS.org",
|
||||
"RunID": utils.MetaDefault,
|
||||
},
|
||||
APIOpts: map[string]interface{}{},
|
||||
}
|
||||
err := dsp.Call("DispatcherService.Test3", args, &reply)
|
||||
expected := "SERVER_ERROR"
|
||||
if err == nil || err.Error() != expected {
|
||||
t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, err)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user