mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-21 23:28:44 +05:00
Added tests for DispatcherSv1 Responder methods
This commit is contained in:
committed by
Dan Christian Bogos
parent
16603a8c30
commit
4aadf61f14
@@ -1,12 +1,12 @@
|
||||
#Tenant,ID,Contexts,FilterIDs,ActivationInterval,AttributeFilterIDs,FieldName,Substitute,Blocker,Weight
|
||||
cgrates.org,ATTR_1001_SIMPLEAUTH,simpleauth,*string:~Account:1001,,,Password,CGRateS.org,false,20
|
||||
cgrates.org,ATTR_API_ATTR_FAKE_AUTH,*auth,*string:~APIKey:12345,,,APIMethods,,false,20
|
||||
cgrates.org,ATTR_API_ATTR_AUTH,*auth,*string:~APIKey:attr12345,,,APIMethods,AttributeSv1.Ping&AttributeSv1.GetAttributeForEvent&AttributeSv1.ProcessEvent,false,20
|
||||
cgrates.org,ATTR_API_CHRG_AUTH,*auth,*string:~APIKey:chrg12345,,,APIMethods,ChargerSv1.Ping&ChargerSv1.GetChargersForEvent&ChargerSv1.ProcessEvent,false,20
|
||||
cgrates.org,ATTR_API_THR_AUTH,*auth,*string:~APIKey:thr12345,,,APIMethods,ThresholdSv1.Ping&ThresholdSv1.GetThresholdsForEvent&ThresholdSv1.ProcessEvent&ThresholdSv1.GetThreshold&ThresholdSv1.GetThresholdIDs,false,20
|
||||
cgrates.org,ATTR_API_SUP_AUTH,*auth,*string:~APIKey:sup12345,,,APIMethods,SupplierSv1.Ping&SupplierSv1.GetSuppliers,false,20
|
||||
cgrates.org,ATTR_API_STAT_AUTH,*auth,*string:~APIKey:stat12345,,,APIMethods,StatSv1.Ping&StatSv1.GetStatQueuesForEvent&StatSv1.GetQueueStringMetrics&StatSv1.ProcessEvent&StatSv1.GetQueueIDs&StatSv1.GetQueueFloatMetrics,false,20
|
||||
cgrates.org,ATTR_API_RES_AUTH,*auth,*string:~APIKey:res12345,,,APIMethods,ResourceSv1.Ping&ResourceSv1.GetResourcesForEvent&ResourceSv1.AuthorizeResources&ResourceSv1.AllocateResources&ResourceSv1.ReleaseResources,false,20
|
||||
cgrates.org,ATTR_API_SES_AUTH,*auth,*string:~APIKey:ses12345,,,APIMethods,SessionSv1.Ping&SessionSv1.AuthorizeEventWithDigest&SessionSv1.InitiateSessionWithDigest&SessionSv1.UpdateSession&SessionSv1.TerminateSession&SessionSv1.ProcessCDR&SessionSv1.ProcessEvent&SessionSv1.GetActiveSessions&SessionSv1.GetActiveSessionsCount&SessionSv1.ForceDisconnect&SessionSv1.GetPassiveSessions&SessionSv1.GetPassiveSessionsCount&SessionSv1.SetPassiveSession&SessionSv1.ReplicateSessions,false,20
|
||||
cgrates.org,ATTR_API_RSP_AUTH,*auth,*string:~APIKey:rsp12345,,,APIMethods,Responder.Status,false,20
|
||||
#Tenant,ID,Contexts,FilterIDs,ActivationInterval,FieldName,Initial,Substitute,Append,Blocker,Weight
|
||||
cgrates.org,ATTR_1001_SIMPLEAUTH,simpleauth,*string:~Account:1001,,Password,*any,CGRateS.org,true,false,20
|
||||
cgrates.org,ATTR_API_ATTR_FAKE_AUTH,*auth,*string:~APIKey:12345,,APIMethods,*any,,true,false,20
|
||||
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&ThresholdSv1.GetThreshold&ThresholdSv1.GetThresholdIDs,true,false,20
|
||||
cgrates.org,ATTR_API_SUP_AUTH,*auth,*string:~APIKey:sup12345,,APIMethods,*any,SupplierSv1.Ping&SupplierSv1.GetSuppliers,true,false,20
|
||||
cgrates.org,ATTR_API_STAT_AUTH,*auth,*string:~APIKey:stat12345,,APIMethods,*any,StatSv1.Ping&StatSv1.GetStatQueuesForEvent&StatSv1.GetQueueStringMetrics&StatSv1.ProcessEvent&StatSv1.GetQueueIDs&StatSv1.GetQueueFloatMetrics,true,false,20
|
||||
cgrates.org,ATTR_API_RES_AUTH,*auth,*string:~APIKey:res12345,,APIMethods,*any,ResourceSv1.Ping&ResourceSv1.GetResourcesForEvent&ResourceSv1.AuthorizeResources&ResourceSv1.AllocateResources&ResourceSv1.ReleaseResources,true,false,20
|
||||
cgrates.org,ATTR_API_SES_AUTH,*auth,*string:~APIKey:ses12345,,APIMethods,*any,SessionSv1.Ping&SessionSv1.AuthorizeEventWithDigest&SessionSv1.InitiateSessionWithDigest&SessionSv1.UpdateSession&SessionSv1.TerminateSession&SessionSv1.ProcessCDR&SessionSv1.ProcessEvent&SessionSv1.GetActiveSessions&SessionSv1.GetActiveSessionsCount&SessionSv1.ForceDisconnect&SessionSv1.GetPassiveSessions&SessionSv1.GetPassiveSessionsCount&SessionSv1.SetPassiveSession&SessionSv1.ReplicateSessions,true,false,20
|
||||
cgrates.org,ATTR_API_RSP_AUTH,*auth,*string:~APIKey:rsp12345,,APIMethods,*any,Responder.Status&Responder.GetTimeout&Responder.Shutdown,true,false,20
|
||||
|
||||
|
||||
|
@@ -22,13 +22,17 @@ package dispatchers
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
)
|
||||
|
||||
var sTestsDspRsp = []func(t *testing.T){
|
||||
testDspResponderStatus,
|
||||
testDspResponderGetTimeout,
|
||||
testDspResponderShutdown,
|
||||
|
||||
testDspResponderRandom,
|
||||
}
|
||||
@@ -116,3 +120,63 @@ func testDspResponderRandom(t *testing.T) {
|
||||
}
|
||||
t.Errorf("Random strategy fail with 0.0009765625%% probability")
|
||||
}
|
||||
|
||||
func testDspResponderGetTimeout(t *testing.T) {
|
||||
var reply time.Duration
|
||||
expected := time.Duration(0)
|
||||
if err := allEngine.RCP.Call(utils.ResponderGetTimeout, 0, &reply); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(expected, reply) {
|
||||
t.Errorf("Expected: %s ,received: %s", expected, reply)
|
||||
}
|
||||
ev := TntWithApiKey{
|
||||
TenantArg: utils.TenantArg{
|
||||
Tenant: "cgrates.org",
|
||||
},
|
||||
DispatcherResource: DispatcherResource{
|
||||
APIKey: "rsp12345",
|
||||
},
|
||||
}
|
||||
if err := dispEngine.RCP.Call(utils.ResponderGetTimeout, &ev, &reply); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(expected, reply) {
|
||||
t.Errorf("Expected: %s ,received: %s", expected, reply)
|
||||
}
|
||||
allEngine.stopEngine(t)
|
||||
if err := dispEngine.RCP.Call(utils.ResponderGetTimeout, &ev, &reply); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(expected, reply) {
|
||||
t.Errorf("Expected: %s ,received: %s", expected, reply)
|
||||
}
|
||||
allEngine.startEngine(t)
|
||||
}
|
||||
|
||||
func testDspResponderShutdown(t *testing.T) {
|
||||
var reply string
|
||||
var statusReply map[string]interface{}
|
||||
ev := TntWithApiKey{
|
||||
TenantArg: utils.TenantArg{
|
||||
Tenant: "cgrates.org",
|
||||
},
|
||||
DispatcherResource: DispatcherResource{
|
||||
APIKey: "rsp12345",
|
||||
},
|
||||
}
|
||||
if err := dispEngine.RCP.Call(utils.ResponderShutdown, &ev, &reply); err != nil {
|
||||
t.Error(err)
|
||||
} else if reply != "Done!" {
|
||||
t.Errorf("Received: %s", utils.ToJSON(reply))
|
||||
}
|
||||
if err := dispEngine.RCP.Call(utils.ResponderStatus, &ev, &statusReply); err != nil {
|
||||
t.Error(err)
|
||||
} else if statusReply[utils.NodeID] != "ALL2" {
|
||||
t.Errorf("Received: %s", utils.ToJSON(statusReply))
|
||||
}
|
||||
if err := dispEngine.RCP.Call(utils.ResponderShutdown, &ev, &reply); err != nil {
|
||||
t.Error(err)
|
||||
} else if reply != "Done!" {
|
||||
t.Errorf("Received: %s", utils.ToJSON(reply))
|
||||
}
|
||||
allEngine.startEngine(t)
|
||||
allEngine2.startEngine(t)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user