From 64dad8ec54fe2761b0daec92725dc0afb1b5c9e9 Mon Sep 17 00:00:00 2001 From: andronache Date: Thu, 28 Jan 2021 15:56:03 +0200 Subject: [PATCH] Tests in console --- apier/v1/dispatcher.go | 5 + console/ping_test.go | 513 ++++++++++++++++++++++++++++++++++++++++- 2 files changed, 517 insertions(+), 1 deletion(-) diff --git a/apier/v1/dispatcher.go b/apier/v1/dispatcher.go index 0b264ad7f..ea63e0332 100755 --- a/apier/v1/dispatcher.go +++ b/apier/v1/dispatcher.go @@ -1361,3 +1361,8 @@ type DispatcherAccountSv1 struct { func (dR *DispatcherAccountSv1) Ping(args *utils.CGREvent, reply *string) error { return dR.dR.AccountSv1Ping(args, reply) } + +func (rS *DispatcherSv1) Ping(ign *utils.CGREvent, reply *string) error { + *reply = utils.Pong + return nil +} diff --git a/console/ping_test.go b/console/ping_test.go index 56010d9ff..8f0789963 100644 --- a/console/ping_test.go +++ b/console/ping_test.go @@ -108,7 +108,7 @@ func TestCmdPingChargerSLow(t *testing.T) { if !reflect.DeepEqual(result2, utils.ChargerSv1Ping) { t.Errorf("Expected <%+v>, Received <%+v>", utils.ChargerSv1Ping, result2) } - m, ok := reflect.TypeOf(new(v1.AttributeSv1)).MethodByName(strings.Split(command.RpcMethod(), utils.NestingSep)[1]) + m, ok := reflect.TypeOf(new(v1.ChargerSv1)).MethodByName(strings.Split(command.RpcMethod(), utils.NestingSep)[1]) if !ok { t.Fatal("method not found") } @@ -130,3 +130,514 @@ func TestCmdPingChargerSLow(t *testing.T) { } } + +func TestCmdPingResourcesLow(t *testing.T) { + // commands map is initiated in init function + command := commands["ping"] + castCommand, canCast := command.(*CmdApierPing) + if !canCast { + t.Fatalf("cannot cast") + } + castCommand.item = utils.ResourcesLow + result2 := command.RpcMethod() + if !reflect.DeepEqual(result2, utils.ResourceSv1Ping) { + t.Errorf("Expected <%+v>, Received <%+v>", utils.ResourceSv1Ping, result2) + } + m, ok := reflect.TypeOf(new(v1.ResourceSv1)).MethodByName(strings.Split(command.RpcMethod(), utils.NestingSep)[1]) + if !ok { + t.Fatal("method not found") + } + if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs + t.Fatalf("invalid number of input parameters ") + } + // for coverage purpose + result := command.RpcParams(true) + if !reflect.DeepEqual(result, new(StringWrapper)) { + t.Errorf("Expected <%T>, Received <%T>", new(StringWrapper), result) + } + // verify the type of output parameter + if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { + t.Fatalf("cannot assign output parameter") + } + // for coverage purpose + if err := command.PostprocessRpcParams(); err != nil { + t.Fatal(err) + } + +} + +func TestCmdPingStatServiceLow(t *testing.T) { + // commands map is initiated in init function + command := commands["ping"] + castCommand, canCast := command.(*CmdApierPing) + if !canCast { + t.Fatalf("cannot cast") + } + castCommand.item = utils.StatServiceLow + result2 := command.RpcMethod() + if !reflect.DeepEqual(result2, utils.StatSv1Ping) { + t.Errorf("Expected <%+v>, Received <%+v>", utils.StatSv1Ping, result2) + } + m, ok := reflect.TypeOf(new(v1.StatSv1)).MethodByName(strings.Split(command.RpcMethod(), utils.NestingSep)[1]) + if !ok { + t.Fatal("method not found") + } + if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs + t.Fatalf("invalid number of input parameters ") + } + // for coverage purpose + result := command.RpcParams(true) + if !reflect.DeepEqual(result, new(StringWrapper)) { + t.Errorf("Expected <%T>, Received <%T>", new(StringWrapper), result) + } + // verify the type of output parameter + if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { + t.Fatalf("cannot assign output parameter") + } + // for coverage purpose + if err := command.PostprocessRpcParams(); err != nil { + t.Fatal(err) + } +} + +func TestCmdPingThresholdsLow(t *testing.T) { + // commands map is initiated in init function + command := commands["ping"] + castCommand, canCast := command.(*CmdApierPing) + if !canCast { + t.Fatalf("cannot cast") + } + castCommand.item = utils.ThresholdsLow + result2 := command.RpcMethod() + if !reflect.DeepEqual(result2, utils.ThresholdSv1Ping) { + t.Errorf("Expected <%+v>, Received <%+v>", utils.ThresholdSv1Ping, result2) + } + m, ok := reflect.TypeOf(new(v1.ThresholdSv1)).MethodByName(strings.Split(command.RpcMethod(), utils.NestingSep)[1]) + if !ok { + t.Fatal("method not found") + } + if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs + t.Fatalf("invalid number of input parameters ") + } + // for coverage purpose + result := command.RpcParams(true) + if !reflect.DeepEqual(result, new(StringWrapper)) { + t.Errorf("Expected <%T>, Received <%T>", new(StringWrapper), result) + } + // verify the type of output parameter + if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { + t.Fatalf("cannot assign output parameter") + } + // for coverage purpose + if err := command.PostprocessRpcParams(); err != nil { + t.Fatal(err) + } +} + +func TestCmdPingSessionsLow(t *testing.T) { + // commands map is initiated in init function + command := commands["ping"] + castCommand, canCast := command.(*CmdApierPing) + if !canCast { + t.Fatalf("cannot cast") + } + castCommand.item = utils.SessionsLow + result2 := command.RpcMethod() + if !reflect.DeepEqual(result2, utils.SessionSv1Ping) { + t.Errorf("Expected <%+v>, Received <%+v>", utils.SessionSv1Ping, result2) + } + m, ok := reflect.TypeOf(new(v1.SessionSv1)).MethodByName(strings.Split(command.RpcMethod(), utils.NestingSep)[1]) + if !ok { + t.Fatal("method not found") + } + if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs + t.Fatalf("invalid number of input parameters ") + } + // for coverage purpose + result := command.RpcParams(true) + if !reflect.DeepEqual(result, new(StringWrapper)) { + t.Errorf("Expected <%T>, Received <%T>", new(StringWrapper), result) + } + // verify the type of output parameter + if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { + t.Fatalf("cannot assign output parameter") + } + // for coverage purpose + if err := command.PostprocessRpcParams(); err != nil { + t.Fatal(err) + } +} + +func TestCmdPingLoaderSLow(t *testing.T) { + // commands map is initiated in init function + command := commands["ping"] + castCommand, canCast := command.(*CmdApierPing) + if !canCast { + t.Fatalf("cannot cast") + } + castCommand.item = utils.LoaderSLow + result2 := command.RpcMethod() + if !reflect.DeepEqual(result2, utils.LoaderSv1Ping) { + t.Errorf("Expected <%+v>, Received <%+v>", utils.LoaderSv1Ping, result2) + } + m, ok := reflect.TypeOf(new(v1.LoaderSv1)).MethodByName(strings.Split(command.RpcMethod(), utils.NestingSep)[1]) + if !ok { + t.Fatal("method not found") + } + if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs + t.Fatalf("invalid number of input parameters ") + } + // for coverage purpose + result := command.RpcParams(true) + if !reflect.DeepEqual(result, new(StringWrapper)) { + t.Errorf("Expected <%T>, Received <%T>", new(StringWrapper), result) + } + // verify the type of output parameter + if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { + t.Fatalf("cannot assign output parameter") + } + // for coverage purpose + if err := command.PostprocessRpcParams(); err != nil { + t.Fatal(err) + } +} + +func TestCmdPingDispatcherSLow(t *testing.T) { + // commands map is initiated in init function + command := commands["ping"] + castCommand, canCast := command.(*CmdApierPing) + if !canCast { + t.Fatalf("cannot cast") + } + castCommand.item = utils.DispatcherSLow + result2 := command.RpcMethod() + if !reflect.DeepEqual(result2, utils.DispatcherSv1Ping) { + t.Errorf("Expected <%+v>, Received <%+v>", utils.DispatcherSv1Ping, result2) + } + m, ok := reflect.TypeOf(new(v1.DispatcherSv1)).MethodByName(strings.Split(command.RpcMethod(), utils.NestingSep)[1]) + if !ok { + t.Fatal("method not found") + } + if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs + t.Fatalf("invalid number of input parameters ") + } + // for coverage purpose + result := command.RpcParams(true) + if !reflect.DeepEqual(result, new(StringWrapper)) { + t.Errorf("Expected <%T>, Received <%T>", new(StringWrapper), result) + } + // verify the type of output parameter + if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { + t.Fatalf("cannot assign output parameter") + } + // for coverage purpose + if err := command.PostprocessRpcParams(); err != nil { + t.Fatal(err) + } +} + +func TestCmdPingAnalyzerSLow(t *testing.T) { + // commands map is initiated in init function + command := commands["ping"] + castCommand, canCast := command.(*CmdApierPing) + if !canCast { + t.Fatalf("cannot cast") + } + castCommand.item = utils.AnalyzerSLow + result2 := command.RpcMethod() + if !reflect.DeepEqual(result2, utils.AnalyzerSv1Ping) { + t.Errorf("Expected <%+v>, Received <%+v>", utils.AnalyzerSv1Ping, result2) + } + m, ok := reflect.TypeOf(new(v1.AnalyzerSv1)).MethodByName(strings.Split(command.RpcMethod(), utils.NestingSep)[1]) + if !ok { + t.Fatal("method not found") + } + if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs + t.Fatalf("invalid number of input parameters ") + } + // for coverage purpose + result := command.RpcParams(true) + if !reflect.DeepEqual(result, new(StringWrapper)) { + t.Errorf("Expected <%T>, Received <%T>", new(StringWrapper), result) + } + // verify the type of output parameter + if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { + t.Fatalf("cannot assign output parameter") + } + // for coverage purpose + if err := command.PostprocessRpcParams(); err != nil { + t.Fatal(err) + } +} + +func TestCmdPingSchedulerSLow(t *testing.T) { + // commands map is initiated in init function + command := commands["ping"] + castCommand, canCast := command.(*CmdApierPing) + if !canCast { + t.Fatalf("cannot cast") + } + castCommand.item = utils.SchedulerSLow + result2 := command.RpcMethod() + if !reflect.DeepEqual(result2, utils.SchedulerSv1Ping) { + t.Errorf("Expected <%+v>, Received <%+v>", utils.SchedulerSv1Ping, result2) + } + m, ok := reflect.TypeOf(new(v1.SchedulerSv1)).MethodByName(strings.Split(command.RpcMethod(), utils.NestingSep)[1]) + if !ok { + t.Fatal("method not found") + } + if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs + t.Fatalf("invalid number of input parameters ") + } + // for coverage purpose + result := command.RpcParams(true) + if !reflect.DeepEqual(result, new(StringWrapper)) { + t.Errorf("Expected <%T>, Received <%T>", new(StringWrapper), result) + } + // verify the type of output parameter + if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { + t.Fatalf("cannot assign output parameter") + } + // for coverage purpose + if err := command.PostprocessRpcParams(); err != nil { + t.Fatal(err) + } +} + +func TestCmdPingRALsLow(t *testing.T) { + // commands map is initiated in init function + command := commands["ping"] + castCommand, canCast := command.(*CmdApierPing) + if !canCast { + t.Fatalf("cannot cast") + } + castCommand.item = utils.RALsLow + result2 := command.RpcMethod() + if !reflect.DeepEqual(result2, utils.RALsV1Ping) { + t.Errorf("Expected <%+v>, Received <%+v>", utils.RALsV1Ping, result2) + } + m, ok := reflect.TypeOf(new(v1.RALsV1)).MethodByName(strings.Split(command.RpcMethod(), utils.NestingSep)[1]) + if !ok { + t.Fatal("method not found") + } + if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs + t.Fatalf("invalid number of input parameters ") + } + // for coverage purpose + result := command.RpcParams(true) + if !reflect.DeepEqual(result, new(StringWrapper)) { + t.Errorf("Expected <%T>, Received <%T>", new(StringWrapper), result) + } + // verify the type of output parameter + if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { + t.Fatalf("cannot assign output parameter") + } + // for coverage purpose + if err := command.PostprocessRpcParams(); err != nil { + t.Fatal(err) + } +} + +func TestCmdPingReplicatorLow(t *testing.T) { + // commands map is initiated in init function + command := commands["ping"] + castCommand, canCast := command.(*CmdApierPing) + if !canCast { + t.Fatalf("cannot cast") + } + castCommand.item = utils.ReplicatorLow + result2 := command.RpcMethod() + if !reflect.DeepEqual(result2, utils.ReplicatorSv1Ping) { + t.Errorf("Expected <%+v>, Received <%+v>", utils.RALsV1Ping, result2) + } + m, ok := reflect.TypeOf(new(v1.ReplicatorSv1)).MethodByName(strings.Split(command.RpcMethod(), utils.NestingSep)[1]) + if !ok { + t.Fatal("method not found") + } + if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs + t.Fatalf("invalid number of input parameters ") + } + // for coverage purpose + result := command.RpcParams(true) + if !reflect.DeepEqual(result, new(StringWrapper)) { + t.Errorf("Expected <%T>, Received <%T>", new(StringWrapper), result) + } + // verify the type of output parameter + if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { + t.Fatalf("cannot assign output parameter") + } + // for coverage purpose + if err := command.PostprocessRpcParams(); err != nil { + t.Fatal(err) + } +} + +func TestCmdPingApierSLow(t *testing.T) { + // commands map is initiated in init function + command := commands["ping"] + castCommand, canCast := command.(*CmdApierPing) + if !canCast { + t.Fatalf("cannot cast") + } + castCommand.item = utils.ApierSLow + result2 := command.RpcMethod() + if !reflect.DeepEqual(result2, utils.APIerSv1Ping) { + t.Errorf("Expected <%+v>, Received <%+v>", utils.APIerSv1Ping, result2) + } + m, ok := reflect.TypeOf(new(v1.APIerSv1)).MethodByName(strings.Split(command.RpcMethod(), utils.NestingSep)[1]) + if !ok { + t.Fatal("method not found") + } + if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs + t.Fatalf("invalid number of input parameters ") + } + // for coverage purpose + result := command.RpcParams(true) + if !reflect.DeepEqual(result, new(StringWrapper)) { + t.Errorf("Expected <%T>, Received <%T>", new(StringWrapper), result) + } + // verify the type of output parameter + if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { + t.Fatalf("cannot assign output parameter") + } + // for coverage purpose + if err := command.PostprocessRpcParams(); err != nil { + t.Fatal(err) + } +} + +func TestCmdPingEEsLow(t *testing.T) { + // commands map is initiated in init function + command := commands["ping"] + castCommand, canCast := command.(*CmdApierPing) + if !canCast { + t.Fatalf("cannot cast") + } + castCommand.item = utils.EEsLow + result2 := command.RpcMethod() + if !reflect.DeepEqual(result2, utils.EeSv1Ping) { + t.Errorf("Expected <%+v>, Received <%+v>", utils.EeSv1Ping, result2) + } + m, ok := reflect.TypeOf(new(v1.EeSv1)).MethodByName(strings.Split(command.RpcMethod(), utils.NestingSep)[1]) + if !ok { + t.Fatal("method not found") + } + if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs + t.Fatalf("invalid number of input parameters ") + } + // for coverage purpose + result := command.RpcParams(true) + if !reflect.DeepEqual(result, new(StringWrapper)) { + t.Errorf("Expected <%T>, Received <%T>", new(StringWrapper), result) + } + // verify the type of output parameter + if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { + t.Fatalf("cannot assign output parameter") + } + // for coverage purpose + if err := command.PostprocessRpcParams(); err != nil { + t.Fatal(err) + } +} + +func TestCmdPingRateSLow(t *testing.T) { + // commands map is initiated in init function + command := commands["ping"] + castCommand, canCast := command.(*CmdApierPing) + if !canCast { + t.Fatalf("cannot cast") + } + castCommand.item = utils.RateSLow + result2 := command.RpcMethod() + if !reflect.DeepEqual(result2, utils.RateSv1Ping) { + t.Errorf("Expected <%+v>, Received <%+v>", utils.RateSv1Ping, result2) + } + m, ok := reflect.TypeOf(new(v1.RateSv1)).MethodByName(strings.Split(command.RpcMethod(), utils.NestingSep)[1]) + if !ok { + t.Fatal("method not found") + } + if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs + t.Fatalf("invalid number of input parameters ") + } + // for coverage purpose + result := command.RpcParams(true) + if !reflect.DeepEqual(result, new(StringWrapper)) { + t.Errorf("Expected <%T>, Received <%T>", new(StringWrapper), result) + } + // verify the type of output parameter + if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { + t.Fatalf("cannot assign output parameter") + } + // for coverage purpose + if err := command.PostprocessRpcParams(); err != nil { + t.Fatal(err) + } +} + +func TestCmdPingAccountSLow(t *testing.T) { + // commands map is initiated in init function + command := commands["ping"] + castCommand, canCast := command.(*CmdApierPing) + if !canCast { + t.Fatalf("cannot cast") + } + castCommand.item = utils.AccountSLow + result2 := command.RpcMethod() + if !reflect.DeepEqual(result2, utils.AccountSv1Ping) { + t.Errorf("Expected <%+v>, Received <%+v>", utils.AccountSv1Ping, result2) + } + m, ok := reflect.TypeOf(new(v1.AccountSv1)).MethodByName(strings.Split(command.RpcMethod(), utils.NestingSep)[1]) + if !ok { + t.Fatal("method not found") + } + if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs + t.Fatalf("invalid number of input parameters ") + } + // for coverage purpose + result := command.RpcParams(true) + if !reflect.DeepEqual(result, new(StringWrapper)) { + t.Errorf("Expected <%T>, Received <%T>", new(StringWrapper), result) + } + // verify the type of output parameter + if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { + t.Fatalf("cannot assign output parameter") + } + // for coverage purpose + if err := command.PostprocessRpcParams(); err != nil { + t.Fatal(err) + } +} + +func TestCmdPingActionSLow(t *testing.T) { + // commands map is initiated in init function + command := commands["ping"] + castCommand, canCast := command.(*CmdApierPing) + if !canCast { + t.Fatalf("cannot cast") + } + castCommand.item = utils.ActionSLow + result2 := command.RpcMethod() + if !reflect.DeepEqual(result2, utils.ActionSv1Ping) { + t.Errorf("Expected <%+v>, Received <%+v>", utils.ActionSv1Ping, result2) + } + m, ok := reflect.TypeOf(new(v1.ActionSv1)).MethodByName(strings.Split(command.RpcMethod(), utils.NestingSep)[1]) + if !ok { + t.Fatal("method not found") + } + if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs + t.Fatalf("invalid number of input parameters ") + } + // for coverage purpose + result := command.RpcParams(true) + if !reflect.DeepEqual(result, new(StringWrapper)) { + t.Errorf("Expected <%T>, Received <%T>", new(StringWrapper), result) + } + // verify the type of output parameter + if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { + t.Fatalf("cannot assign output parameter") + } + // for coverage purpose + if err := command.PostprocessRpcParams(); err != nil { + t.Fatal(err) + } +}