mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Refactoring and coverage tests in console
This commit is contained in:
committed by
Dan Christian Bogos
parent
83d7b952f5
commit
19e20ccbca
@@ -118,8 +118,8 @@ type AttrRemoveAccountActionTriggers struct {
|
||||
UniqueID string
|
||||
}
|
||||
|
||||
func (apierSv1 *APIerSv1) RemoveAccountActionTriggers(attr AttrRemoveAccountActionTriggers, reply *string) error {
|
||||
if missing := utils.MissingStructFields(&attr, []string{utils.AccountField}); len(missing) != 0 {
|
||||
func (apierSv1 *APIerSv1) RemoveAccountActionTriggers(attr *AttrRemoveAccountActionTriggers, reply *string) error {
|
||||
if missing := utils.MissingStructFields(attr, []string{utils.AccountField}); len(missing) != 0 {
|
||||
return utils.NewErrMandatoryIeMissing(missing...)
|
||||
}
|
||||
tnt := attr.Tenant
|
||||
|
||||
@@ -18,8 +18,15 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
|
||||
package console
|
||||
|
||||
//willfix
|
||||
/*
|
||||
import (
|
||||
"reflect"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
v1 "github.com/cgrates/cgrates/apier/v1"
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
)
|
||||
|
||||
func TestCmdAccountTriggerRemove(t *testing.T) {
|
||||
// commands map is initiated in init function
|
||||
command := commands["account_triggers_remove"]
|
||||
@@ -44,4 +51,3 @@ func TestCmdAccountTriggerRemove(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
@@ -68,6 +68,6 @@ func (self *CmdSessionsAuthorize) PostprocessRpcParams() error {
|
||||
}
|
||||
|
||||
func (self *CmdSessionsAuthorize) RpcResult() interface{} {
|
||||
var atr *sessions.V1AuthorizeReplyWithDigest
|
||||
var atr sessions.V1AuthorizeReplyWithDigest
|
||||
return &atr
|
||||
}
|
||||
|
||||
54
console/session_authorize_event_test.go
Normal file
54
console/session_authorize_event_test.go
Normal file
@@ -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 <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
|
||||
package console
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
v1 "github.com/cgrates/cgrates/apier/v1"
|
||||
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
)
|
||||
|
||||
func TestCmdSessionAuthorizeEvent(t *testing.T) {
|
||||
// commands map is initiated in init function
|
||||
command := commands["session_authorize_event"]
|
||||
// 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)
|
||||
}
|
||||
}
|
||||
@@ -68,7 +68,7 @@ func (self *CmdSessionsInitiate) PostprocessRpcParams() error {
|
||||
}
|
||||
|
||||
func (self *CmdSessionsInitiate) RpcResult() interface{} {
|
||||
var atr *sessions.V1InitSessionReply
|
||||
var atr sessions.V1InitReplyWithDigest
|
||||
return &atr
|
||||
}
|
||||
|
||||
|
||||
54
console/session_initiate_test.go
Normal file
54
console/session_initiate_test.go
Normal file
@@ -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 <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
|
||||
package console
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
v1 "github.com/cgrates/cgrates/apier/v1"
|
||||
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
)
|
||||
|
||||
func TestCmdSessionInitiate(t *testing.T) {
|
||||
// commands map is initiated in init function
|
||||
command := commands["session_initiate"]
|
||||
// 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)
|
||||
}
|
||||
}
|
||||
@@ -64,6 +64,6 @@ func (self *CmdSessionsProcessCDR) PostprocessRpcParams() error {
|
||||
}
|
||||
|
||||
func (self *CmdSessionsProcessCDR) RpcResult() interface{} {
|
||||
var atr *string
|
||||
var atr string
|
||||
return &atr
|
||||
}
|
||||
|
||||
54
console/session_process_cdr_test.go
Normal file
54
console/session_process_cdr_test.go
Normal file
@@ -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 <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
|
||||
package console
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
v1 "github.com/cgrates/cgrates/apier/v1"
|
||||
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
)
|
||||
|
||||
func TestCmdSessionProcessCDR(t *testing.T) {
|
||||
// commands map is initiated in init function
|
||||
command := commands["session_process_cdr"]
|
||||
// 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)
|
||||
}
|
||||
}
|
||||
@@ -68,7 +68,7 @@ func (self *CmdSessionsProcessEvent) PostprocessRpcParams() error {
|
||||
}
|
||||
|
||||
func (self *CmdSessionsProcessEvent) RpcResult() interface{} {
|
||||
var atr *sessions.V1ProcessMessageReply
|
||||
var atr sessions.V1ProcessMessageReply
|
||||
return &atr
|
||||
}
|
||||
|
||||
|
||||
54
console/session_process_message_test.go
Normal file
54
console/session_process_message_test.go
Normal file
@@ -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 <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
|
||||
package console
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
v1 "github.com/cgrates/cgrates/apier/v1"
|
||||
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
)
|
||||
|
||||
func TestCmdSessionProcessMessage(t *testing.T) {
|
||||
// commands map is initiated in init function
|
||||
command := commands["session_process_message"]
|
||||
// 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)
|
||||
}
|
||||
}
|
||||
@@ -68,6 +68,6 @@ func (self *CmdSessionsTerminate) PostprocessRpcParams() error {
|
||||
}
|
||||
|
||||
func (self *CmdSessionsTerminate) RpcResult() interface{} {
|
||||
var atr *string
|
||||
var atr string
|
||||
return &atr
|
||||
}
|
||||
|
||||
54
console/session_terminate_test.go
Normal file
54
console/session_terminate_test.go
Normal file
@@ -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 <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
|
||||
package console
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
v1 "github.com/cgrates/cgrates/apier/v1"
|
||||
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
)
|
||||
|
||||
func TestCmdSessionTerminate(t *testing.T) {
|
||||
// commands map is initiated in init function
|
||||
command := commands["session_terminate"]
|
||||
// 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)
|
||||
}
|
||||
}
|
||||
@@ -68,7 +68,7 @@ func (self *CmdSessionsUpdate) PostprocessRpcParams() error {
|
||||
}
|
||||
|
||||
func (self *CmdSessionsUpdate) RpcResult() interface{} {
|
||||
var atr *sessions.V1UpdateSessionReply
|
||||
var atr sessions.V1UpdateSessionReply
|
||||
return &atr
|
||||
}
|
||||
|
||||
|
||||
54
console/session_update_test.go
Normal file
54
console/session_update_test.go
Normal file
@@ -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 <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
|
||||
package console
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
v1 "github.com/cgrates/cgrates/apier/v1"
|
||||
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
)
|
||||
|
||||
func TestCmdSessionUpdate(t *testing.T) {
|
||||
// commands map is initiated in init function
|
||||
command := commands["session_update"]
|
||||
// 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)
|
||||
}
|
||||
}
|
||||
@@ -63,6 +63,6 @@ func (self *CmdGetStatQueueStringMetrics) PostprocessRpcParams() error {
|
||||
}
|
||||
|
||||
func (self *CmdGetStatQueueStringMetrics) RpcResult() interface{} {
|
||||
var atr *map[string]string
|
||||
var atr map[string]string
|
||||
return &atr
|
||||
}
|
||||
|
||||
53
console/stats_metrics_test.go
Normal file
53
console/stats_metrics_test.go
Normal file
@@ -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 <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
|
||||
package console
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
v1 "github.com/cgrates/cgrates/apier/v1"
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
)
|
||||
|
||||
func TestCmdStatsMetrics(t *testing.T) {
|
||||
// commands map is initiated in init function
|
||||
command := commands["stats_metrics"]
|
||||
// verify if ApierSv1 object has method on it
|
||||
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 ")
|
||||
}
|
||||
// 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)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user