Coverage tests in console

This commit is contained in:
andronache
2021-01-26 17:55:38 +02:00
committed by Dan Christian Bogos
parent 71812699e4
commit bda251199d
29 changed files with 567 additions and 67 deletions

View File

@@ -65,8 +65,8 @@ func (rsv1 *ResourceSv1) GetResource(args *utils.TenantIDWithOpts, reply *engine
}
// GetResourceProfile returns a resource configuration
func (apierSv1 *APIerSv1) GetResourceProfile(arg utils.TenantID, reply *engine.ResourceProfile) error {
if missing := utils.MissingStructFields(&arg, []string{utils.ID}); len(missing) != 0 { //Params missing
func (apierSv1 *APIerSv1) GetResourceProfile(arg *utils.TenantID, reply *engine.ResourceProfile) error {
if missing := utils.MissingStructFields(arg, []string{utils.ID}); len(missing) != 0 { //Params missing
return utils.NewErrMandatoryIeMissing(missing...)
}
tnt := utils.EmptyString
@@ -82,7 +82,7 @@ func (apierSv1 *APIerSv1) GetResourceProfile(arg utils.TenantID, reply *engine.R
}
// GetResourceProfileIDs returns list of resourceProfile IDs registered for a tenant
func (apierSv1 *APIerSv1) GetResourceProfileIDs(args utils.PaginatorWithTenant, rsPrfIDs *[]string) error {
func (apierSv1 *APIerSv1) GetResourceProfileIDs(args *utils.PaginatorWithTenant, rsPrfIDs *[]string) error {
tnt := args.Tenant
if tnt == utils.EmptyString {
tnt = apierSv1.Config.GeneralCfg().DefaultTenant

View File

@@ -163,8 +163,8 @@ type AttrResetAccountActionTriggers struct {
Executed bool
}
func (apierSv1 *APIerSv1) ResetAccountActionTriggers(attr AttrResetAccountActionTriggers, reply *string) error {
if missing := utils.MissingStructFields(&attr, []string{utils.AccountField}); len(missing) != 0 {
func (apierSv1 *APIerSv1) ResetAccountActionTriggers(attr *AttrResetAccountActionTriggers, reply *string) error {
if missing := utils.MissingStructFields(attr, []string{utils.AccountField}); len(missing) != 0 {
return utils.NewErrMandatoryIeMissing(missing...)
}
tnt := attr.Tenant
@@ -351,8 +351,8 @@ func (attr *AttrSetActionTrigger) UpdateActionTrigger(at *engine.ActionTrigger,
}
// SetAccountActionTriggers updates or creates if not present the ActionTrigger for an Account
func (apierSv1 *APIerSv1) SetAccountActionTriggers(attr AttrSetAccountActionTriggers, reply *string) error {
if missing := utils.MissingStructFields(&attr, []string{utils.AccountField}); len(missing) != 0 {
func (apierSv1 *APIerSv1) SetAccountActionTriggers(attr *AttrSetAccountActionTriggers, reply *string) error {
if missing := utils.MissingStructFields(attr, []string{utils.AccountField}); len(missing) != 0 {
return utils.NewErrMandatoryIeMissing(missing...)
}
tnt := attr.Tenant
@@ -401,8 +401,8 @@ type AttrRemoveActionTrigger struct {
UniqueID string
}
func (apierSv1 *APIerSv1) RemoveActionTrigger(attr AttrRemoveActionTrigger, reply *string) (err error) {
if missing := utils.MissingStructFields(&attr, []string{"GroupID"}); len(missing) != 0 {
func (apierSv1 *APIerSv1) RemoveActionTrigger(attr *AttrRemoveActionTrigger, reply *string) (err error) {
if missing := utils.MissingStructFields(attr, []string{"GroupID"}); len(missing) != 0 {
return utils.NewErrMandatoryIeMissing(missing...)
}
if attr.UniqueID == "" {
@@ -443,8 +443,8 @@ func (apierSv1 *APIerSv1) RemoveActionTrigger(attr AttrRemoveActionTrigger, repl
}
// SetActionTrigger updates a ActionTrigger
func (apierSv1 *APIerSv1) SetActionTrigger(attr AttrSetActionTrigger, reply *string) (err error) {
if missing := utils.MissingStructFields(&attr, []string{"GroupID"}); len(missing) != 0 {
func (apierSv1 *APIerSv1) SetActionTrigger(attr *AttrSetActionTrigger, reply *string) (err error) {
if missing := utils.MissingStructFields(attr, []string{"GroupID"}); len(missing) != 0 {
return utils.NewErrMandatoryIeMissing(missing...)
}

View File

@@ -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 TestCmdAccountTriggerReset(t *testing.T) {
// commands map is initiated in init function
command := commands["account_triggers_reset"]
@@ -44,4 +51,3 @@ func TestCmdAccountTriggerReset(t *testing.T) {
t.Fatal(err)
}
}
*/

View File

@@ -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 TestCmdAccountTriggerSet(t *testing.T) {
// commands map is initiated in init function
command := commands["account_triggers_set"]
@@ -44,4 +51,3 @@ func TestCmdAccountTriggerSet(t *testing.T) {
t.Fatal(err)
}
}
*/

View File

@@ -63,7 +63,7 @@ func (self *CmdActiveSessions) PostprocessRpcParams() error {
}
func (self *CmdActiveSessions) RpcResult() interface{} {
var sessions *[]*sessions.ExternalSession
var sessions []*sessions.ExternalSession
return &sessions
}

View 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 TestCmdActiveSessions(t *testing.T) {
// commands map is initiated in init function
command := commands["active_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)
}
}

View File

@@ -30,7 +30,7 @@ import (
func TestCmdAttributesProfileIDs(t *testing.T) {
// commands map is initiated in init function
command := commands["attributes_profile"]
command := commands["attributes_profile_ids"]
// 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 {

View File

@@ -19,7 +19,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
package console
import (
v1 "github.com/cgrates/cgrates/apier/v1"
"github.com/cgrates/cgrates/utils"
)
@@ -36,7 +35,7 @@ func init() {
type CmdRemoveBalance struct {
name string
rpcMethod string
rpcParams *v1.AttrAddBalance
rpcParams *utils.AttrSetBalance
*CommandExecuter
}
@@ -50,7 +49,7 @@ func (self *CmdRemoveBalance) RpcMethod() string {
func (self *CmdRemoveBalance) RpcParams(reset bool) interface{} {
if reset || self.rpcParams == nil {
self.rpcParams = &v1.AttrAddBalance{BalanceType: utils.MetaMonetary, Overwrite: false}
self.rpcParams = &utils.AttrSetBalance{BalanceType: utils.MetaMonetary}
}
return self.rpcParams
}

View File

@@ -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 TestCmdBalanceRemove(t *testing.T) {
// commands map is initiated in init function
command := commands["balance_remove"]
@@ -44,4 +51,3 @@ func TestCmdBalanceRemove(t *testing.T) {
t.Fatal(err)
}
}
*/

View File

@@ -30,9 +30,9 @@ import (
func TestCmdCacheClear(t *testing.T) {
// commands map is initiated in init function
command := commands["balance_set"]
command := commands["cache_clear"]
// verify if ApierSv1 object has method on it
m, ok := reflect.TypeOf(new(v1.APIerSv1)).MethodByName(strings.Split(command.RpcMethod(), utils.NestingSep)[1])
m, ok := reflect.TypeOf(new(v1.CacheSv1)).MethodByName(strings.Split(command.RpcMethod(), utils.NestingSep)[1])
if !ok {
t.Fatal("method not found")
}

View File

@@ -27,8 +27,6 @@ import (
"github.com/cgrates/cgrates/utils"
)
//willfix
func TestCmdChargersProcessEvent(t *testing.T) {
// commands map is initiated in init function
command := commands["chargers_process_event"]

View File

@@ -24,7 +24,7 @@ func init() {
c := &CmdRemoveChargers{
name: "chargers_profile_remove",
rpcMethod: utils.APIerSv1RemoveChargerProfile,
rpcParams: &utils.TenantID{},
rpcParams: &utils.TenantIDWithCache{},
}
commands[c.Name()] = c
c.CommandExecuter = &CommandExecuter{c}
@@ -33,7 +33,7 @@ func init() {
type CmdRemoveChargers struct {
name string
rpcMethod string
rpcParams *utils.TenantID
rpcParams *utils.TenantIDWithCache
*CommandExecuter
}
@@ -47,7 +47,7 @@ func (self *CmdRemoveChargers) RpcMethod() string {
func (self *CmdRemoveChargers) RpcParams(reset bool) interface{} {
if reset || self.rpcParams == nil {
self.rpcParams = &utils.TenantID{}
self.rpcParams = &utils.TenantIDWithCache{}
}
return self.rpcParams
}

View File

@@ -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 TestCmdChargersProfileRem(t *testing.T) {
// commands map is initiated in init function
command := commands["chargers_profile_remove"]
@@ -44,4 +51,3 @@ func TestCmdChargersProfileRem(t *testing.T) {
t.Fatal(err)
}
}
*/

View File

@@ -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 <http://www.gnu.org/licenses/>
*/
package console
//willfix
/*
func TestCmdComputeActionPlanIndexes(t *testing.T) {
// commands map is initiated in init function
command := commands["compute_actionplan_indexes"]
// 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)
}
}
*/

View 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 TestCmdComputeActionPlanIndexes(t *testing.T) {
// commands map is initiated in init function
command := commands["compute_filter_indexes"]
// 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 ")
}
// 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)
}
}

View File

@@ -18,18 +18,11 @@ 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"
)
//willfix
/*
func TestCmdDataDBVersions(t *testing.T) {
// commands map is initiated in init function
command := commands["datacost"]
command := commands["datadb_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 {
@@ -38,6 +31,8 @@ func TestCmdDataDBVersions(t *testing.T) {
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")
@@ -51,3 +46,4 @@ func TestCmdDataDBVersions(t *testing.T) {
t.Fatal(err)
}
}
*/

53
console/debit_max_test.go Normal file
View 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 TestCmdDebitMax(t *testing.T) {
// commands map is initiated in init function
command := commands["debit_max"]
// verify if ApierSv1 object has method on it
m, ok := reflect.TypeOf(new(v1.DispatcherResponder)).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)
}
}

53
console/debit_test.go Normal file
View 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 TestCmdDebit(t *testing.T) {
// commands map is initiated in init function
command := commands["debit"]
// verify if ApierSv1 object has method on it
m, ok := reflect.TypeOf(new(v1.DispatcherResponder)).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)
}
}

View File

@@ -27,7 +27,7 @@ func init() {
c := &CmdGetRateProfile{
name: "rates_profile",
rpcMethod: utils.APIerSv1GetRateProfile,
rpcParams: &utils.TenantID{},
rpcParams: &utils.TenantIDWithOpts{},
}
commands[c.Name()] = c
c.CommandExecuter = &CommandExecuter{c}
@@ -37,7 +37,7 @@ func init() {
type CmdGetRateProfile struct {
name string
rpcMethod string
rpcParams *utils.TenantID
rpcParams *utils.TenantIDWithOpts
*CommandExecuter
}
@@ -51,7 +51,7 @@ func (self *CmdGetRateProfile) RpcMethod() string {
func (self *CmdGetRateProfile) RpcParams(reset bool) interface{} {
if reset || self.rpcParams == nil {
self.rpcParams = &utils.TenantID{}
self.rpcParams = &utils.TenantIDWithOpts{}
}
return self.rpcParams
}

View File

@@ -30,7 +30,7 @@ import (
func TestCmdRatesProfile(t *testing.T) {
// commands map is initiated in init function
command := commands["rates_profile_set"]
command := commands["rates_profile"]
// 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 {

View 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 TestCmdResourcesProfileIDs(t *testing.T) {
// commands map is initiated in init function
command := commands["resources_profile_ids"]
// 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 ")
}
// 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)
}
}

View 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 TestCmdResourcesProfileRem(t *testing.T) {
// commands map is initiated in init function
command := commands["resources_profile_remove"]
// 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 ")
}
// 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)
}
}

View 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 TestCmdResourcesProfileSet(t *testing.T) {
// commands map is initiated in init function
command := commands["resources_profile_set"]
// 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 ")
}
// 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)
}
}

View 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 TestCmdResourcesProfile(t *testing.T) {
// commands map is initiated in init function
command := commands["resources_profile"]
// 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 ")
}
// 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)
}
}

View File

@@ -27,7 +27,7 @@ func init() {
c := &CmdGetThresholdProfile{
name: "thresholds_profile",
rpcMethod: utils.APIerSv1GetThresholdProfile,
rpcParams: &utils.TenantIDWithOpts{},
rpcParams: &utils.TenantID{},
}
commands[c.Name()] = c
c.CommandExecuter = &CommandExecuter{c}
@@ -36,7 +36,7 @@ func init() {
type CmdGetThresholdProfile struct {
name string
rpcMethod string
rpcParams *utils.TenantIDWithOpts
rpcParams *utils.TenantID
*CommandExecuter
}
@@ -50,10 +50,7 @@ func (self *CmdGetThresholdProfile) RpcMethod() string {
func (self *CmdGetThresholdProfile) RpcParams(reset bool) interface{} {
if reset || self.rpcParams == nil {
self.rpcParams = &utils.TenantIDWithOpts{
TenantID: new(utils.TenantID),
Opts: make(map[string]interface{}),
}
self.rpcParams = &utils.TenantID{}
}
return self.rpcParams
}

View File

@@ -29,7 +29,7 @@ import (
func TestCmdThresholdsProfileIDs(t *testing.T) {
// commands map is initiated in init function
command := commands["thresholds_profile_remove"]
command := commands["thresholds_profile_ids"]
// 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 {

View File

@@ -29,7 +29,7 @@ import (
func TestCmdThresholdsProfile(t *testing.T) {
// commands map is initiated in init function
command := commands["thresholds_profile_ids"]
command := commands["thresholds_profile"]
// 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 {

View File

@@ -18,8 +18,14 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
package console
//willfix
/*
import (
v1 "github.com/cgrates/cgrates/apier/v1"
"github.com/cgrates/cgrates/utils"
"reflect"
"strings"
"testing"
)
func TestCmdTriggerRemove(t *testing.T) {
// commands map is initiated in init function
command := commands["triggers_remove"]
@@ -31,8 +37,6 @@ func TestCmdTriggerRemove(t *testing.T) {
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")
@@ -46,4 +50,4 @@ func TestCmdTriggerRemove(t *testing.T) {
t.Fatal(err)
}
}
*/

View File

@@ -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 TestCmdTriggerSet(t *testing.T) {
// commands map is initiated in init function
command := commands["triggers_set"]
@@ -31,8 +38,6 @@ func TestCmdTriggerSet(t *testing.T) {
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")
@@ -46,4 +51,3 @@ func TestCmdTriggerSet(t *testing.T) {
t.Fatal(err)
}
}
*/