From 8b94da6bedb1a8517b799bb35ac4092b65580bc1 Mon Sep 17 00:00:00 2001 From: andronache Date: Wed, 27 Jan 2021 10:57:19 +0200 Subject: [PATCH] Coverage in console --- console/compute_filter_indexes_test.go | 2 +- console/load_ids_test.go | 1 + console/passive_sessions.go | 2 +- console/passive_sessions_test.go | 54 ++++++++++++++++++++++++++ console/set_stordb_versions_test.go | 2 +- console/sharedgroup_test.go | 49 +++++++++++++++++++++++ console/sleep.go | 4 +- console/sleep_test.go | 53 +++++++++++++++++++++++++ console/stordb_versions_test.go | 49 +++++++++++++++++++++++ 9 files changed, 211 insertions(+), 5 deletions(-) create mode 100644 console/passive_sessions_test.go create mode 100644 console/sharedgroup_test.go create mode 100644 console/sleep_test.go create mode 100644 console/stordb_versions_test.go diff --git a/console/compute_filter_indexes_test.go b/console/compute_filter_indexes_test.go index 3cb046e84..17947664b 100644 --- a/console/compute_filter_indexes_test.go +++ b/console/compute_filter_indexes_test.go @@ -27,7 +27,7 @@ import ( "github.com/cgrates/cgrates/utils" ) -func TestCmdComputeActionPlanIndexes(t *testing.T) { +func TestCmdComputeFilterIndexes(t *testing.T) { // commands map is initiated in init function command := commands["compute_filter_indexes"] // verify if ApierSv1 object has method on it diff --git a/console/load_ids_test.go b/console/load_ids_test.go index 3a6478dd9..03766fc14 100644 --- a/console/load_ids_test.go +++ b/console/load_ids_test.go @@ -18,6 +18,7 @@ along with this program. If not, see package console +//willfix /* func TestCmdLoadIDs(t *testing.T) { // commands map is initiated in init function diff --git a/console/passive_sessions.go b/console/passive_sessions.go index 430205e4b..ef37af134 100644 --- a/console/passive_sessions.go +++ b/console/passive_sessions.go @@ -62,7 +62,7 @@ func (self *CmdPassiveSessions) PostprocessRpcParams() error { } func (self *CmdPassiveSessions) RpcResult() interface{} { - var sessions *[]*sessions.ExternalSession + var sessions []*sessions.ExternalSession return &sessions } diff --git a/console/passive_sessions_test.go b/console/passive_sessions_test.go new file mode 100644 index 000000000..71f7f9411 --- /dev/null +++ b/console/passive_sessions_test.go @@ -0,0 +1,54 @@ +/* +Real-time Online/Offline Charging System (OCS) for Telecom & ISP environments +Copyright (C) ITsysCOM GmbH + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see +*/ + +package console + +import ( + "reflect" + "strings" + "testing" + + v1 "github.com/cgrates/cgrates/apier/v1" + + "github.com/cgrates/cgrates/utils" +) + +func TestCmdPassiveSessions(t *testing.T) { + // commands map is initiated in init function + command := commands["passive_sessions"] + // verify if ApierSv1 object has method on it + 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 ") + } + // verify the type of input parameter + if ok := m.Type.In(1).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { + t.Fatalf("cannot assign input parameter") + } + // 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) + } +} diff --git a/console/set_stordb_versions_test.go b/console/set_stordb_versions_test.go index c2ae379dc..0b71c22df 100644 --- a/console/set_stordb_versions_test.go +++ b/console/set_stordb_versions_test.go @@ -27,7 +27,7 @@ import ( "github.com/cgrates/cgrates/utils" ) -func TestCmdStorDBVersions(t *testing.T) { +func TestCmdSetStorDBVersions(t *testing.T) { // commands map is initiated in init function command := commands["set_stordb_versions"] // verify if ApierSv1 object has method on it diff --git a/console/sharedgroup_test.go b/console/sharedgroup_test.go new file mode 100644 index 000000000..a0491f662 --- /dev/null +++ b/console/sharedgroup_test.go @@ -0,0 +1,49 @@ +/* +Real-time Online/Offline Charging System (OCS) for Telecom & ISP environments +Copyright (C) ITsysCOM GmbH + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see +*/ + +package console + +//willfix +/* +func TestCmdSharedGroup(t *testing.T) { + // commands map is initiated in init function + command := commands["sharedgroup"] + // verify if ApierSv1 object has method on it + 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 ") + } + fmt.Println(m.Type.In(1)) + fmt.Println(reflect.TypeOf(command.RpcParams(true))) + // verify the type of input parameter + if ok := m.Type.In(1).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { + t.Fatalf("cannot assign input parameter") + } + // 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) + } +} +*/ diff --git a/console/sleep.go b/console/sleep.go index 965b5b629..6c02f23d6 100644 --- a/console/sleep.go +++ b/console/sleep.go @@ -46,7 +46,7 @@ func (cmd *CmdSleep) RpcMethod() string { func (cmd *CmdSleep) RpcParams(reset bool) interface{} { if reset || cmd.rpcParams == nil { - cmd.rpcParams = &StringWrapper{} + cmd.rpcParams = &utils.DurationArgs{} } return cmd.rpcParams } @@ -64,6 +64,6 @@ func (cmd *CmdSleep) PostprocessRpcParams() (err error) { } func (cmd *CmdSleep) RpcResult() interface{} { - var s *string + var s string return &s } diff --git a/console/sleep_test.go b/console/sleep_test.go new file mode 100644 index 000000000..3b5167867 --- /dev/null +++ b/console/sleep_test.go @@ -0,0 +1,53 @@ +/* +Real-time Online/Offline Charging System (OCS) for Telecom & ISP environments +Copyright (C) ITsysCOM GmbH + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see +*/ + +package console + +import ( + "reflect" + "strings" + "testing" + + v1 "github.com/cgrates/cgrates/apier/v1" + "github.com/cgrates/cgrates/utils" +) + +func TestCmdSleep(t *testing.T) { + // commands map is initiated in init function + command := commands["sleep"] + // verify if ApierSv1 object has method on it + m, ok := reflect.TypeOf(new(v1.CoreSv1)).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 ") + } + // verify the type of input parameter + if ok := m.Type.In(1).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { + t.Fatalf("cannot assign input parameter") + } + // 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) + } +} diff --git a/console/stordb_versions_test.go b/console/stordb_versions_test.go new file mode 100644 index 000000000..fe2150718 --- /dev/null +++ b/console/stordb_versions_test.go @@ -0,0 +1,49 @@ +/* +Real-time Online/Offline Charging System (OCS) for Telecom & ISP environments +Copyright (C) ITsysCOM GmbH + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see +*/ + +package console + +//willfix +/* +func TestCmdStorDBVersions(t *testing.T) { + // commands map is initiated in init function + command := commands["stordb_versions"] + // verify if ApierSv1 object has method on it + 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 ") + } + fmt.Println(m.Type.In(1)) + fmt.Println(reflect.TypeOf(command.RpcParams(true))) + // verify the type of input parameter + if ok := m.Type.In(1).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { + t.Fatalf("cannot assign input parameter") + } + // 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) + } +} +*/