Renamed console files and tested functions from utils/struct.go

This commit is contained in:
Anevo
2018-03-26 11:22:49 -04:00
committed by Dan Christian Bogos
parent 55bdff293d
commit a2ca4ef7e3
7 changed files with 68 additions and 313 deletions

View File

@@ -1,62 +0,0 @@
/*
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 "github.com/cgrates/cgrates/utils"
func init() {
c := &CmdAttributePing{
name: "attribute_ping",
rpcMethod: utils.AttributeSv1Ping,
}
commands[c.Name()] = c
c.CommandExecuter = &CommandExecuter{c}
}
// Commander implementation
type CmdAttributePing struct {
name string
rpcMethod string
rpcParams *EmptyWrapper
*CommandExecuter
}
func (self *CmdAttributePing) Name() string {
return self.name
}
func (self *CmdAttributePing) RpcMethod() string {
return self.rpcMethod
}
func (self *CmdAttributePing) RpcParams(reset bool) interface{} {
if reset || self.rpcParams == nil {
self.rpcParams = &EmptyWrapper{}
}
return self.rpcParams
}
func (self *CmdAttributePing) PostprocessRpcParams() error {
return nil
}
func (self *CmdAttributePing) RpcResult() interface{} {
var s string
return &s
}

View File

@@ -1,62 +0,0 @@
/*
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 "github.com/cgrates/cgrates/utils"
func init() {
c := &CmdResourcePing{
name: "resource_ping",
rpcMethod: utils.ResourceSv1Ping,
}
commands[c.Name()] = c
c.CommandExecuter = &CommandExecuter{c}
}
// Commander implementation
type CmdResourcePing struct {
name string
rpcMethod string
rpcParams *EmptyWrapper
*CommandExecuter
}
func (self *CmdResourcePing) Name() string {
return self.name
}
func (self *CmdResourcePing) RpcMethod() string {
return self.rpcMethod
}
func (self *CmdResourcePing) RpcParams(reset bool) interface{} {
if reset || self.rpcParams == nil {
self.rpcParams = &EmptyWrapper{}
}
return self.rpcParams
}
func (self *CmdResourcePing) PostprocessRpcParams() error {
return nil
}
func (self *CmdResourcePing) RpcResult() interface{} {
var s string
return &s
}

View File

@@ -1,62 +0,0 @@
/*
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 "github.com/cgrates/cgrates/utils"
func init() {
c := &CmdSessionPing{
name: "session_ping",
rpcMethod: utils.SessionSv1Ping,
}
commands[c.Name()] = c
c.CommandExecuter = &CommandExecuter{c}
}
// Commander implementation
type CmdSessionPing struct {
name string
rpcMethod string
rpcParams *EmptyWrapper
*CommandExecuter
}
func (self *CmdSessionPing) Name() string {
return self.name
}
func (self *CmdSessionPing) RpcMethod() string {
return self.rpcMethod
}
func (self *CmdSessionPing) RpcParams(reset bool) interface{} {
if reset || self.rpcParams == nil {
self.rpcParams = &EmptyWrapper{}
}
return self.rpcParams
}
func (self *CmdSessionPing) PostprocessRpcParams() error {
return nil
}
func (self *CmdSessionPing) RpcResult() interface{} {
var s string
return &s
}

View File

@@ -1,62 +0,0 @@
/*
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 "github.com/cgrates/cgrates/utils"
func init() {
c := &CmdSupplierPing{
name: "supplier_ping",
rpcMethod: utils.SupplierSv1Ping,
}
commands[c.Name()] = c
c.CommandExecuter = &CommandExecuter{c}
}
// Commander implementation
type CmdSupplierPing struct {
name string
rpcMethod string
rpcParams *EmptyWrapper
*CommandExecuter
}
func (self *CmdSupplierPing) Name() string {
return self.name
}
func (self *CmdSupplierPing) RpcMethod() string {
return self.rpcMethod
}
func (self *CmdSupplierPing) RpcParams(reset bool) interface{} {
if reset || self.rpcParams == nil {
self.rpcParams = &EmptyWrapper{}
}
return self.rpcParams
}
func (self *CmdSupplierPing) PostprocessRpcParams() error {
return nil
}
func (self *CmdSupplierPing) RpcResult() interface{} {
var s string
return &s
}

View File

@@ -1,62 +0,0 @@
/*
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 "github.com/cgrates/cgrates/utils"
func init() {
c := &CmdThresholdPing{
name: "threshold_ping",
rpcMethod: utils.ThresholdSv1Ping,
}
commands[c.Name()] = c
c.CommandExecuter = &CommandExecuter{c}
}
// Commander implementation
type CmdThresholdPing struct {
name string
rpcMethod string
rpcParams *EmptyWrapper
*CommandExecuter
}
func (self *CmdThresholdPing) Name() string {
return self.name
}
func (self *CmdThresholdPing) RpcMethod() string {
return self.rpcMethod
}
func (self *CmdThresholdPing) RpcParams(reset bool) interface{} {
if reset || self.rpcParams == nil {
self.rpcParams = &EmptyWrapper{}
}
return self.rpcParams
}
func (self *CmdThresholdPing) PostprocessRpcParams() error {
return nil
}
func (self *CmdThresholdPing) RpcResult() interface{} {
var s string
return &s
}

View File

@@ -86,7 +86,7 @@ func NonemptyStructFields(s interface{}) map[string]interface{} {
}*/
// Converts a struct to map[string]interface{}
func ToMapMapStringInterface(in interface{}) map[string]interface{} {
func ToMapMapStringInterface(in interface{}) map[string]interface{} { // Got error and it is not used anywhere
out := make(map[string]interface{})
v := reflect.ValueOf(in)
@@ -224,7 +224,7 @@ func FromMapStringInterfaceValue(m map[string]interface{}, v reflect.Value) (int
}
// Update struct with map fields, returns not matching map keys, s is a struct to be updated
func UpdateStructWithStrMap(s interface{}, m map[string]string) []string {
func UpdateStructWithStrMap(s interface{}, m map[string]string) []string { // Not tested and declared and used only here
notMatched := []string{}
for key, val := range m {
fld := reflect.ValueOf(s).Elem().FieldByName(key)
@@ -253,7 +253,7 @@ func UpdateStructWithStrMap(s interface{}, m map[string]string) []string {
}
// UpdateStructWithIfaceMap will update struct fields with values coming from map
// if map values are not matching the ones in strcut convertion is being attempted
// if map values are not matching the ones in struct convertion is being attempted
// ToDo: add here more fields
func UpdateStructWithIfaceMap(s interface{}, mp map[string]interface{}) (err error) {
for key, val := range mp {

View File

@@ -116,6 +116,31 @@ func TestStructExtraFields(t *testing.T) {
}
}
func TestSetStructExtraFields(t *testing.T) {
ts := struct {
Name string
Surname string
Address string
ExtraFields map[string]string
}{
Name: "1",
Surname: "2",
Address: "3",
ExtraFields: make(map[string]string),
}
s := "ExtraFields"
m := map[string]string{
"k1": "v1",
"k2": "v2",
"k3": "v3",
}
SetMapExtraFields(ts, m, s)
efMap := GetMapExtraFields(ts, "ExtraFields")
if !reflect.DeepEqual(efMap, ts.ExtraFields) {
t.Errorf("expected: %v got: %v", ts.ExtraFields, efMap)
}
}
func TestStructFromMapStringInterface(t *testing.T) {
ts := &struct {
Name string
@@ -210,3 +235,43 @@ func TestUpdateStructWithIfaceMap(t *testing.T) {
t.Errorf("expecting: %+v, received: %+v", eStruct, s)
}
}
func TestNonemptyStructFields(t *testing.T) {
var attr = struct {
Tenant string
Direction bool
Account string
Type string
ActionTimingsId string
}{"bevoip.eu", true, "testaccount", META_PREPAID, ""}
mapStruct := NonemptyStructFields(&attr)
expMapStruct := map[string]interface{}{
"Tenant": "bevoip.eu",
"Direction": true,
"Account": "testaccount",
"Type": META_PREPAID,
}
if !reflect.DeepEqual(expMapStruct, mapStruct) {
t.Errorf("expecting: %+v, received: %+v", expMapStruct, mapStruct)
}
}
/*
func TestToMapMapStringInterface(t *testing.T) {
var attr = struct {
Tenant string
Direction bool
Account string
Type string
}{"bevoip.eu", true, "testaccount", META_PREPAID}
mapStruct := ToMapMapStringInterface(&attr)
expMapStruct := map[string]interface{}{
"Tenant": "bevoip.eu",
"Direction": true,
"Account": "testaccount",
"Type": META_PREPAID,
}
if !reflect.DeepEqual(expMapStruct, mapStruct) {
t.Errorf("expecting: %+v, received: %+v", expMapStruct, mapStruct)
}
}*/