mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Updated tests and methods for dispatchers.go with default tenant value
This commit is contained in:
committed by
Dan Christian Bogos
parent
7116697831
commit
b1bcd30d48
@@ -61,6 +61,8 @@ var (
|
||||
testDispatcherSUpdateDispatcherHost,
|
||||
testDispatcherSGetDispatcherHostCache,
|
||||
testDispatcherSRemDispatcherHost,
|
||||
testDispatcherSSetDispatcherHostWithoutTenant,
|
||||
testDispatcherSRemDispatcherHostWithoutTenant,
|
||||
|
||||
testDispatcherSKillEngine,
|
||||
}
|
||||
@@ -420,3 +422,53 @@ func testDispatcherSRemDispatcherProfileWithoutTenant(t *testing.T) {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func testDispatcherSSetDispatcherHostWithoutTenant(t *testing.T) {
|
||||
dispatcherHost = &DispatcherHostWithCache{
|
||||
DispatcherHost: &engine.DispatcherHost{
|
||||
ID: "DspHst7",
|
||||
Conns: []*config.RemoteHost{
|
||||
{
|
||||
Address: "*internal",
|
||||
},
|
||||
{
|
||||
Address: ":2012",
|
||||
Transport: utils.MetaJSON,
|
||||
TLS: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
var reply string
|
||||
if err := dispatcherRPC.Call(utils.APIerSv1SetDispatcherHost, dispatcherHost, &reply); err != nil {
|
||||
t.Error(err)
|
||||
} else if reply != utils.OK {
|
||||
t.Error("Unexpected reply returned", reply)
|
||||
}
|
||||
dispatcherHost.DispatcherHost.Tenant = "cgrates.org"
|
||||
var result *engine.DispatcherHost
|
||||
if err := dispatcherRPC.Call(utils.APIerSv1GetDispatcherHost,
|
||||
&utils.TenantID{ID: "DspHst7"},
|
||||
&result); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(result, dispatcherHost.DispatcherHost) {
|
||||
t.Errorf("Expected %+v, received %+v", utils.ToJSON(dispatcherHost.DispatcherHost), utils.ToJSON(result))
|
||||
}
|
||||
}
|
||||
|
||||
func testDispatcherSRemDispatcherHostWithoutTenant(t *testing.T) {
|
||||
var reply string
|
||||
if err := dispatcherRPC.Call(utils.APIerSv1RemoveDispatcherHost,
|
||||
&utils.TenantIDWithCache{ID: "DspHst7"},
|
||||
&reply); err != nil {
|
||||
t.Error(err)
|
||||
} else if reply != utils.OK {
|
||||
t.Error("Unexpected reply returned", reply)
|
||||
}
|
||||
var result *engine.DispatcherHost
|
||||
if err := dispatcherRPC.Call(utils.APIerSv1GetDispatcherHost,
|
||||
&utils.TenantID{ID: "DspHst7"},
|
||||
&result); err == nil || err.Error() != utils.ErrNotFound.Error() {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -180,6 +180,26 @@ func testDspDspv1GetProfileForEvent(t *testing.T) {
|
||||
if !reflect.DeepEqual(expected, reply) {
|
||||
t.Errorf("expected: %s ,\n received: %s", utils.ToJSON(expected), utils.ToJSON(reply))
|
||||
}
|
||||
|
||||
arg2 := utils.CGREventWithOpts{
|
||||
CGREvent: &utils.CGREvent{
|
||||
ID: "testDspvWithoutTenant",
|
||||
Event: map[string]interface{}{
|
||||
utils.EVENT_NAME: "Event1",
|
||||
},
|
||||
},
|
||||
Opts: map[string]interface{}{
|
||||
utils.Subsys: utils.META_ANY,
|
||||
},
|
||||
}
|
||||
expected.Hosts.Sort()
|
||||
if err := dspRPC.Call(utils.DispatcherSv1GetProfileForEvent, &arg2, &reply); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
reply.Hosts.Sort()
|
||||
if !reflect.DeepEqual(expected, reply) {
|
||||
t.Errorf("expected: %s ,\n received: %s", utils.ToJSON(expected), utils.ToJSON(reply))
|
||||
}
|
||||
}
|
||||
|
||||
func testDspDspv1GetProfileForEventWithMethod(t *testing.T) {
|
||||
|
||||
@@ -113,13 +113,13 @@ func (dS *DispatcherService) authorize(method, tenant string, apiKey string, evT
|
||||
|
||||
// dispatcherForEvent returns a dispatcher instance configured for specific event
|
||||
// or utils.ErrNotFound if none present
|
||||
func (dS *DispatcherService) dispatcherProfileForEvent(ev *utils.CGREventWithOpts,
|
||||
func (dS *DispatcherService) dispatcherProfileForEvent(tnt string, ev *utils.CGREventWithOpts,
|
||||
subsys string) (dPrlf *engine.DispatcherProfile, err error) {
|
||||
// find out the matching profiles
|
||||
anyIdxPrfx := utils.ConcatenatedKey(ev.Tenant, utils.META_ANY)
|
||||
anyIdxPrfx := utils.ConcatenatedKey(tnt, utils.META_ANY)
|
||||
idxKeyPrfx := anyIdxPrfx
|
||||
if subsys != "" {
|
||||
idxKeyPrfx = utils.ConcatenatedKey(ev.Tenant, subsys)
|
||||
idxKeyPrfx = utils.ConcatenatedKey(tnt, subsys)
|
||||
}
|
||||
evNm := utils.MapStorage{
|
||||
utils.MetaReq: ev.CGREvent.Event,
|
||||
@@ -151,7 +151,7 @@ func (dS *DispatcherService) dispatcherProfileForEvent(ev *utils.CGREventWithOpt
|
||||
}
|
||||
}
|
||||
for prflID := range prflIDs {
|
||||
prfl, err := dS.dm.GetDispatcherProfile(ev.Tenant, prflID, true, true, utils.NonTransactional)
|
||||
prfl, err := dS.dm.GetDispatcherProfile(tnt, prflID, true, true, utils.NonTransactional)
|
||||
if err != nil {
|
||||
if err != utils.ErrNotFound {
|
||||
return nil, err
|
||||
@@ -166,7 +166,7 @@ func (dS *DispatcherService) dispatcherProfileForEvent(ev *utils.CGREventWithOpt
|
||||
!prfl.ActivationInterval.IsActiveAtTime(*ev.Time) { // not active
|
||||
continue
|
||||
}
|
||||
if pass, err := dS.fltrS.Pass(ev.Tenant, prfl.FilterIDs,
|
||||
if pass, err := dS.fltrS.Pass(tnt, prfl.FilterIDs,
|
||||
evNm); err != nil {
|
||||
return nil, err
|
||||
} else if !pass {
|
||||
@@ -185,7 +185,11 @@ func (dS *DispatcherService) dispatcherProfileForEvent(ev *utils.CGREventWithOpt
|
||||
// Dispatch is the method forwarding the request towards the right connection
|
||||
func (dS *DispatcherService) Dispatch(ev *utils.CGREventWithOpts, subsys string,
|
||||
serviceMethod string, args interface{}, reply interface{}) (err error) {
|
||||
dPrfl, errDsp := dS.dispatcherProfileForEvent(ev, subsys)
|
||||
tnt := ev.Tenant
|
||||
if tnt == utils.EmptyString {
|
||||
tnt = dS.cfg.GeneralCfg().DefaultTenant
|
||||
}
|
||||
dPrfl, errDsp := dS.dispatcherProfileForEvent(tnt, ev, subsys)
|
||||
if errDsp != nil {
|
||||
return utils.NewErrDispatcherS(errDsp)
|
||||
}
|
||||
@@ -206,7 +210,11 @@ func (dS *DispatcherService) Dispatch(ev *utils.CGREventWithOpts, subsys string,
|
||||
|
||||
func (dS *DispatcherService) V1GetProfileForEvent(ev *utils.CGREventWithOpts,
|
||||
dPfl *engine.DispatcherProfile) (err error) {
|
||||
retDPfl, errDpfl := dS.dispatcherProfileForEvent(ev, utils.IfaceAsString(ev.Opts[utils.Subsys]))
|
||||
tnt := ev.Tenant
|
||||
if tnt == utils.EmptyString {
|
||||
tnt = dS.cfg.GeneralCfg().DefaultTenant
|
||||
}
|
||||
retDPfl, errDpfl := dS.dispatcherProfileForEvent(tnt, ev, utils.IfaceAsString(ev.Opts[utils.Subsys]))
|
||||
if errDpfl != nil {
|
||||
return utils.NewErrDispatcherS(errDpfl)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user