mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-14 20:59:53 +05:00
fix on extra pointer and added tests for missing fields checker
This commit is contained in:
@@ -219,7 +219,7 @@ type AttrAddAccount struct {
|
||||
}
|
||||
|
||||
// Ads a new account into dataDb. If already defined, returns success.
|
||||
func (self *ApierV1) AddAccount(attr *AttrAddAccount, reply *string) error {
|
||||
func (self *ApierV1) AddAccount(attr AttrAddAccount, reply *string) error {
|
||||
if missing := utils.MissingStructFields(&attr, []string{"Tenant", "Direction", "Account", "Type", "ActionTimingsId"}); len(missing) != 0 {
|
||||
*reply = fmt.Sprintf("%s:%v", utils.ERR_MANDATORY_IE_MISSING, missing)
|
||||
return fmt.Errorf("%s:%v", utils.ERR_MANDATORY_IE_MISSING, missing)
|
||||
|
||||
@@ -213,33 +213,33 @@ func startHistoryScribe() {
|
||||
}
|
||||
|
||||
if cfg.HistoryServerEnabled {
|
||||
if cfg.HistoryListen != INTERNAL {
|
||||
rpc.RegisterName("Scribe", scribeServer)
|
||||
var serveFunc func(io.ReadWriteCloser)
|
||||
if cfg.RPCEncoding == JSON {
|
||||
serveFunc = jsonrpc.ServeConn
|
||||
} else {
|
||||
serveFunc = rpc.ServeConn
|
||||
}
|
||||
l, err := net.Listen("tcp", cfg.HistoryListen)
|
||||
if err != nil {
|
||||
engine.Logger.Crit(fmt.Sprintf("<History> Could not listen to %v: %v", cfg.HistoryListen, err))
|
||||
exitChan <- true
|
||||
return
|
||||
}
|
||||
defer l.Close()
|
||||
for {
|
||||
conn, err := l.Accept()
|
||||
if err != nil {
|
||||
engine.Logger.Err(fmt.Sprintf("<History> Accept error: %v", conn))
|
||||
continue
|
||||
}
|
||||
if cfg.HistoryListen != INTERNAL {
|
||||
rpc.RegisterName("Scribe", scribeServer)
|
||||
var serveFunc func(io.ReadWriteCloser)
|
||||
if cfg.RPCEncoding == JSON {
|
||||
serveFunc = jsonrpc.ServeConn
|
||||
} else {
|
||||
serveFunc = rpc.ServeConn
|
||||
}
|
||||
l, err := net.Listen("tcp", cfg.HistoryListen)
|
||||
if err != nil {
|
||||
engine.Logger.Crit(fmt.Sprintf("<History> Could not listen to %v: %v", cfg.HistoryListen, err))
|
||||
exitChan <- true
|
||||
return
|
||||
}
|
||||
defer l.Close()
|
||||
for {
|
||||
conn, err := l.Accept()
|
||||
if err != nil {
|
||||
engine.Logger.Err(fmt.Sprintf("<History> Accept error: %v", conn))
|
||||
continue
|
||||
}
|
||||
|
||||
engine.Logger.Info(fmt.Sprintf("<History> New incoming connection: %v", conn.RemoteAddr()))
|
||||
go serveFunc(conn)
|
||||
}
|
||||
}
|
||||
}
|
||||
engine.Logger.Info(fmt.Sprintf("<History> New incoming connection: %v", conn.RemoteAddr()))
|
||||
go serveFunc(conn)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var scribeAgent history.Scribe
|
||||
|
||||
@@ -247,14 +247,14 @@ func startHistoryScribe() {
|
||||
if cfg.HistoryServer != INTERNAL { // Connect in iteration since there are chances of concurrency here
|
||||
for i := 0; i < 3; i++ { //ToDo: Make it globally configurable
|
||||
if scribeAgent, err = history.NewProxyScribe(cfg.HistoryServer, cfg.RPCEncoding); err == nil {
|
||||
break //Connected so no need to reiterate
|
||||
} else if (i==2 && err!= nil) {
|
||||
break //Connected so no need to reiterate
|
||||
} else if i == 2 && err != nil {
|
||||
engine.Logger.Crit(err.Error())
|
||||
exitChan <- true
|
||||
return
|
||||
}
|
||||
time.Sleep(time.Duration(i/2) * time.Second)
|
||||
}
|
||||
time.Sleep(time.Duration(i/2) * time.Second)
|
||||
}
|
||||
} else {
|
||||
scribeAgent = scribeServer
|
||||
}
|
||||
|
||||
@@ -23,9 +23,7 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
/*
|
||||
The output structure that will be returned with the call cost information.
|
||||
*/
|
||||
// The output structure that will be returned with the call cost information.
|
||||
type CallCost struct {
|
||||
Direction, TOR, Tenant, Subject, Account, Destination string
|
||||
Cost, ConnectFee float64
|
||||
|
||||
@@ -19,7 +19,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
package engine
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
@@ -30,8 +30,8 @@ type Serializer interface {
|
||||
Restore(string) error
|
||||
}
|
||||
|
||||
func notEnoughElements(line string) error {
|
||||
return errors.New("Too few elements to restore: " + line)
|
||||
func notEnoughElements(element, line string) error {
|
||||
return fmt.Errorf("Too few elements to restore (%v): %v", element, line)
|
||||
}
|
||||
|
||||
func (ap *ActivationPeriod) Store() (result string, err error) {
|
||||
@@ -132,7 +132,7 @@ func (a *Action) Store() (result string, err error) {
|
||||
func (a *Action) Restore(input string) (err error) {
|
||||
elements := strings.Split(input, "|")
|
||||
if len(elements) < 8 {
|
||||
return notEnoughElements(input)
|
||||
return notEnoughElements("Action", input)
|
||||
}
|
||||
a.Id = elements[0]
|
||||
a.ActionType = elements[1]
|
||||
@@ -260,7 +260,7 @@ func (at *ActionTrigger) Store() (result string, err error) {
|
||||
func (at *ActionTrigger) Restore(input string) error {
|
||||
elements := strings.Split(input, ";")
|
||||
if len(elements) != 9 {
|
||||
return notEnoughElements(input)
|
||||
return notEnoughElements("ActionTrigger", input)
|
||||
}
|
||||
at.Id = elements[0]
|
||||
at.BalanceId = elements[1]
|
||||
@@ -357,7 +357,7 @@ func (ub *UserBalance) Store() (result string, err error) {
|
||||
func (ub *UserBalance) Restore(input string) error {
|
||||
elements := strings.Split(input, "|")
|
||||
if len(elements) < 2 {
|
||||
return notEnoughElements(input)
|
||||
return notEnoughElements("UserBalance", input)
|
||||
}
|
||||
ub.Id = elements[0]
|
||||
ub.Type = elements[1]
|
||||
@@ -432,7 +432,7 @@ De-serializes the unit counter for the storage. Used for key-value storages.
|
||||
func (uc *UnitsCounter) Restore(input string) error {
|
||||
elements := strings.Split(input, "/")
|
||||
if len(elements) != 4 {
|
||||
return notEnoughElements(input)
|
||||
return notEnoughElements("UnitsCounter", input)
|
||||
}
|
||||
uc.Direction = elements[0]
|
||||
uc.BalanceId = elements[1]
|
||||
@@ -544,7 +544,7 @@ func (i *Interval) Store() (result string, err error) {
|
||||
func (i *Interval) Restore(input string) error {
|
||||
is := strings.Split(input, ";")
|
||||
if len(is) != 11 {
|
||||
return notEnoughElements(input)
|
||||
return notEnoughElements("Interval", input)
|
||||
}
|
||||
if err := i.Years.Restore(is[0]); err != nil {
|
||||
return err
|
||||
@@ -590,7 +590,7 @@ func (mb *MinuteBucket) Restore(input string) error {
|
||||
mb.DestinationId = elements[4]
|
||||
return nil
|
||||
}
|
||||
return notEnoughElements(input)
|
||||
return notEnoughElements("MinuteBucket", input)
|
||||
}
|
||||
|
||||
func (wds WeekDays) Store() (result string, err error) {
|
||||
|
||||
@@ -166,3 +166,31 @@ func TestParseDateRFC3339(t *testing.T) {
|
||||
t.Error("error parsing date: ", expected.Sub(date))
|
||||
}
|
||||
}
|
||||
|
||||
func TestMissingStructFieldsCorrect(t *testing.T) {
|
||||
var attr = struct {
|
||||
Tenant string
|
||||
Direction string
|
||||
Account string
|
||||
Type string
|
||||
ActionTimingsId string
|
||||
}{"bevoip.eu", "OUT", "danconns0001", "prepaid", "mama"}
|
||||
if missing := MissingStructFields(&attr,
|
||||
[]string{"Tenant", "Direction", "Account", "Type", "ActionTimingsId"}); len(missing) != 0 {
|
||||
t.Error("Found missing field on correct struct", missing)
|
||||
}
|
||||
}
|
||||
|
||||
func TestMissingStructFieldsIncorrect(t *testing.T) {
|
||||
var attr = struct {
|
||||
Tenant string
|
||||
Direction string
|
||||
Account string
|
||||
Type string
|
||||
ActionTimingsId string
|
||||
}{Tenant: "bevoip.eu", Direction: "OUT", Account: "danconns0001", Type: "prepaid"}
|
||||
if missing := MissingStructFields(&attr,
|
||||
[]string{"Tenant", "Direction", "Account", "Type", "ActionTimingsId"}); len(missing) != 1 || missing[0] != "ActionTimingsId" {
|
||||
t.Error("Found missing field on correct struct", missing)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user