diff --git a/config/apis_test.go b/config/apis_test.go
index 07f127d0d..99c9ecaf6 100644
--- a/config/apis_test.go
+++ b/config/apis_test.go
@@ -1435,39 +1435,6 @@ func TestPrepareGeneralSectionFromDB(t *testing.T) {
}
}
-// func TestPrepareRPCConnsSectionFromDB(t *testing.T) {
-// section := RPCConnsJSON
-// cfgJSONStr := `{
-// "rpc_conns": {
-// "*localhost": {
-// "conns": [{"address": "127.0.0.1:2012", "transport":"*json"}],
-// },
-// },
-// }`
-
-// cgrCfgJSON, err := NewCgrJsonCfgFromBytes([]byte(cfgJSONStr))
-// if err != nil {
-// t.Error(err)
-// }
-
-// expected := &RPCConnsJson{
-// "*localhost": {
-// Conns: &[]*RemoteHostJson{
-// {
-// Address: utils.StringPointer("127.0.0.1:2012"),
-// Transport: utils.StringPointer("*json"),
-// },
-// },
-// },
-// }
-
-// if cfgSec, err := prepareSectionFromDB(section, cgrCfgJSON); err != nil {
-// t.Error(err)
-// } else if !reflect.DeepEqual(cfgSec, expected) {
-// t.Errorf("Expected %v \n but received \n %v", utils.ToJSON(expected), utils.ToJSON(cfgSec))
-// }
-// }
-
func TestPrepareCacheSectionFromDB(t *testing.T) {
section := CacheJSON
cfgJSONStr := `{
diff --git a/config/config_apis.go b/config/config_apis.go
deleted file mode 100644
index 5039cbaea..000000000
--- a/config/config_apis.go
+++ /dev/null
@@ -1,858 +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
-*/
-
-package config
-
-import (
- "bytes"
- "encoding/json"
- "errors"
- "fmt"
-
- "github.com/cgrates/birpc/context"
- "github.com/cgrates/cgrates/utils"
-)
-
-// getSectionAsMap returns a section from config as a map[string]interface
-func (cfg *CGRConfig) getSectionAsMap(section string) (mp interface{}, err error) {
- switch section {
- case GeneralJSON:
- mp = cfg.GeneralCfg().AsMapInterface()
- case DataDBJSON:
- mp = cfg.DataDbCfg().AsMapInterface()
- case StorDBJSON:
- mp = cfg.StorDbCfg().AsMapInterface()
- case TlsJSON:
- mp = cfg.TLSCfg().AsMapInterface()
- case CacheJSON:
- mp = cfg.CacheCfg().AsMapInterface()
- case ListenJSON:
- mp = cfg.ListenCfg().AsMapInterface()
- case HTTPJSON:
- mp = cfg.HTTPCfg().AsMapInterface()
- case FilterSJSON:
- mp = cfg.FilterSCfg().AsMapInterface()
- case CDRsJSON:
- mp = cfg.CdrsCfg().AsMapInterface()
- case SessionSJSON:
- mp = cfg.SessionSCfg().AsMapInterface()
- case FreeSWITCHAgentJSON:
- mp = cfg.FsAgentCfg().AsMapInterface(cfg.GeneralCfg().RSRSep)
- case KamailioAgentJSON:
- mp = cfg.KamAgentCfg().AsMapInterface()
- case AsteriskAgentJSON:
- mp = cfg.AsteriskAgentCfg().AsMapInterface()
- case DiameterAgentJSON:
- mp = cfg.DiameterAgentCfg().AsMapInterface(cfg.GeneralCfg().RSRSep)
- case RadiusAgentJSON:
- mp = cfg.RadiusAgentCfg().AsMapInterface(cfg.GeneralCfg().RSRSep)
- case DNSAgentJSON:
- mp = cfg.DNSAgentCfg().AsMapInterface(cfg.GeneralCfg().RSRSep)
- case AttributeSJSON:
- mp = cfg.AttributeSCfg().AsMapInterface()
- case ChargerSJSON:
- mp = cfg.ChargerSCfg().AsMapInterface()
- case ResourceSJSON:
- mp = cfg.ResourceSCfg().AsMapInterface()
- case StatSJSON:
- mp = cfg.StatSCfg().AsMapInterface()
- case ThresholdSJSON:
- mp = cfg.ThresholdSCfg().AsMapInterface()
- case RouteSJSON:
- mp = cfg.RouteSCfg().AsMapInterface()
- case SureTaxJSON:
- mp = cfg.SureTaxCfg().AsMapInterface(cfg.GeneralCfg().RSRSep)
- case DispatcherSJSON:
- mp = cfg.DispatcherSCfg().AsMapInterface()
- case RegistrarCJSON:
- mp = cfg.RegistrarCCfg().AsMapInterface()
- case LoaderSJSON:
- mp = cfg.LoaderCfg().AsMapInterface(cfg.GeneralCfg().RSRSep)
- case LoaderJSON:
- mp = cfg.LoaderCgrCfg().AsMapInterface()
- case MigratorJSON:
- mp = cfg.MigratorCgrCfg().AsMapInterface()
- case AdminSJSON:
- mp = cfg.AdminSCfg().AsMapInterface()
- case EEsJSON:
- mp = cfg.EEsCfg().AsMapInterface(cfg.GeneralCfg().RSRSep)
- case ERsJSON:
- mp = cfg.ERsCfg().AsMapInterface(cfg.GeneralCfg().RSRSep)
- case RPCConnsJSON:
- mp = cfg.RPCConns().AsMapInterface()
- case SIPAgentJSON:
- mp = cfg.SIPAgentCfg().AsMapInterface(cfg.GeneralCfg().RSRSep)
- case TemplatesJSON:
- mp = cfg.TemplatesCfg().AsMapInterface(cfg.GeneralCfg().RSRSep)
- case ConfigSJSON:
- mp = cfg.ConfigSCfg().AsMapInterface()
- case APIBanJSON:
- mp = cfg.APIBanCfg().AsMapInterface()
- case HTTPAgentJSON:
- mp = cfg.HTTPAgentCfg().AsMapInterface(cfg.GeneralCfg().RSRSep)
- case AnalyzerSJSON:
- mp = cfg.AnalyzerSCfg().AsMapInterface()
- case RateSJSON:
- mp = cfg.RateSCfg().AsMapInterface()
- case CoreSJSON:
- mp = cfg.CoreSCfg().AsMapInterface()
- case ActionSJSON:
- mp = cfg.ActionSCfg().AsMapInterface()
- case AccountSJSON:
- mp = cfg.AccountSCfg().AsMapInterface()
- case ConfigDBJSON:
- mp = cfg.ConfigDBCfg().AsMapInterface()
- default:
- err = errors.New("Invalid section ")
- }
- return
-}
-
-// ReloadArgs the API params for V1ReloadConfig
-type ReloadArgs struct {
- APIOpts map[string]interface{}
- Tenant string
- Path string
- Section string
- DryRun bool
-}
-
-// V1ReloadConfig reloads the configuration
-func (cfg *CGRConfig) V1ReloadConfig(ctx *context.Context, args *ReloadArgs, reply *string) (err error) {
- updateDB := cfg.db != nil
- if !updateDB &&
- args.Path == utils.EmptyString {
- return utils.NewErrMandatoryIeMissing("Path")
- } else if updateDB &&
- args.Path != utils.EmptyString {
- return fmt.Errorf("Reload from the path is disabled when the configDB is enabled")
- }
- cfgV := cfg
- if args.DryRun {
- cfgV = cfg.Clone()
- }
- cfgV.reloadDPCache(args.Section)
- if updateDB {
- sections := []string{args.Section}
- if args.Section == utils.MetaEmpty ||
- args.Section == utils.MetaAll {
- sections = sortedCfgSections[:len(sortedCfgSections)-1] // all exept the configDB section
- }
- err = cfgV.loadCfgFromDB(cfg.db, sections)
- } else {
- err = cfgV.loadCfgWithLocks(args.Path, args.Section)
- }
- if err != nil {
- return
- }
- // lock all sections
- cfgV.rLockSections()
-
- err = cfgV.checkConfigSanity()
-
- cfgV.rUnlockSections() // unlock before checking the error
-
- if err != nil {
- return
- }
- if !args.DryRun {
- if args.Section == utils.EmptyString || args.Section == utils.MetaAll {
- cfgV.reloadSections(sortedCfgSections...)
- } else {
- cfgV.reloadSections(args.Section)
- }
- }
- *reply = utils.OK
- return
-}
-
-// SectionWithAPIOpts the API params for GetConfig
-type SectionWithAPIOpts struct {
- APIOpts map[string]interface{}
- Tenant string
- Sections []string
-}
-
-// V1GetConfig will retrieve from CGRConfig a section
-func (cfg *CGRConfig) V1GetConfig(ctx *context.Context, args *SectionWithAPIOpts, reply *map[string]interface{}) (err error) {
- if len(args.Sections) == 0 ||
- args.Sections[0] == utils.MetaAll {
- args.Sections = sortedCfgSections
- }
- mp := make(map[string]interface{})
- sections := utils.StringSet{}
- cfg.cacheDPMux.RLock()
- for _, section := range args.Sections {
- if val, has := cfg.cacheDP[section]; has && val != nil {
- mp[section] = val
- } else {
- sections.Add(section)
- }
- }
- cfg.cacheDPMux.RUnlock()
- if sections.Size() == 0 { // all sections were cached
- *reply = mp
- return
- }
- if sections.Size() == len(sortedCfgSections) {
- mp = cfg.AsMapInterface(cfg.GeneralCfg().RSRSep)
- } else {
- for section := range sections {
- var val interface{}
- if val, err = cfg.getSectionAsMap(section); err != nil {
- return
- }
- mp[section] = val
- cfg.cacheDPMux.Lock()
- cfg.cacheDP[section] = val
- cfg.cacheDPMux.Unlock()
- }
- }
- *reply = mp
- return
-}
-
-// SetConfigArgs the API params for V1SetConfig
-type SetConfigArgs struct {
- APIOpts map[string]interface{}
- Tenant string
- Config map[string]interface{}
- DryRun bool
-}
-
-// V1SetConfig reloads the sections of config
-func (cfg *CGRConfig) V1SetConfig(ctx *context.Context, args *SetConfigArgs, reply *string) (err error) {
- if len(args.Config) == 0 {
- *reply = utils.OK
- return
- }
- sections := make([]string, 0, len(args.Config))
- for section := range args.Config {
- if !sortedSectionsSet.Has(section) {
- return fmt.Errorf("Invalid section <%s> ", section)
- }
- sections = append(sections, section)
- }
- var b []byte
- if b, err = json.Marshal(args.Config); err != nil {
- return
- }
-
- var mp map[string]interface{}
- updateDB := cfg.db != nil
- if !args.DryRun && updateDB { // need to update the DB but only parts
- if err = cfg.V1GetConfig(ctx, &SectionWithAPIOpts{Sections: sections}, &mp); err != nil {
- return
- }
- }
-
- cfgV := cfg
- if args.DryRun {
- cfgV = cfg.Clone()
- }
-
- cfgV.reloadDPCache(sections...)
- if err = cfgV.loadCfgFromJSONWithLocks(bytes.NewBuffer(b), sections); err != nil {
- return
- }
-
- // lock all sections
- cfgV.rLockSections()
-
- err = cfgV.checkConfigSanity()
-
- cfgV.rUnlockSections() // unlock before checking the error
- if err != nil {
- return
- }
- if !args.DryRun {
- cfgV.reloadSections(sections...)
- if updateDB { // need to update the DB but only parts
- // ToDo: add here the call
- }
- }
- *reply = utils.OK
- return
-}
-
-//V1GetConfigAsJSON will retrieve from CGRConfig a section as a string
-func (cfg *CGRConfig) V1GetConfigAsJSON(ctx *context.Context, args *SectionWithAPIOpts, reply *string) (err error) {
- var mp map[string]interface{}
- if err = cfg.V1GetConfig(ctx, args, &mp); err != nil {
- return
- }
- *reply = utils.ToJSON(mp)
- return
-}
-
-// SetConfigFromJSONArgs the API params for V1SetConfigFromJSON
-type SetConfigFromJSONArgs struct {
- APIOpts map[string]interface{}
- Tenant string
- Config string
- DryRun bool
-}
-
-// V1SetConfigFromJSON reloads the sections of config
-func (cfg *CGRConfig) V1SetConfigFromJSON(ctx *context.Context, args *SetConfigFromJSONArgs, reply *string) (err error) {
- if len(args.Config) == 0 {
- *reply = utils.OK
- return
- }
- var mp map[string]interface{}
- updateDB := cfg.db != nil
- if !args.DryRun && updateDB { // need to update the DB but only parts
- if err = cfg.V1GetConfig(ctx, &SectionWithAPIOpts{Sections: sortedCfgSections}, &mp); err != nil {
- return
- }
- }
- cfgV := cfg
- if args.DryRun {
- cfgV = cfg.Clone()
- }
-
- cfgV.reloadDPCache(sortedCfgSections...)
- if err = cfgV.loadCfgFromJSONWithLocks(bytes.NewBufferString(args.Config), sortedCfgSections); err != nil {
- return
- }
-
- // lock all sections
- cfgV.rLockSections()
- err = cfgV.checkConfigSanity()
- cfgV.rUnlockSections() // unlock before checking the error
- if err != nil {
- return
- }
- if !args.DryRun {
- cfgV.reloadSections(sortedCfgSections...)
- if updateDB { // need to update the DB but only parts
- // ToDo: add here the call
- }
- }
- *reply = utils.OK
- return
-}
-
-func (cfg *CGRConfig) reloadDPCache(sections ...string) {
- cfg.cacheDPMux.Lock()
- delete(cfg.cacheDP, utils.MetaAll)
- for _, sec := range sections {
- delete(cfg.cacheDP, sec)
- }
- cfg.cacheDPMux.Unlock()
-}
-
-// loadFromJSONDB Loads from json configuration object, will be used for defaults, config from file and reload
-// this function ignores the config_db section
-func (cfg *CGRConfig) LoadFromDB(jsnCfg ConfigDB) (err error) {
- // Load sections out of JSON config, stop on error
- cfg.lockSections()
- defer cfg.unlockSections()
- cfg.db = jsnCfg
- for _, loadFunc := range []func(ConfigDB) error{
- cfg.loadRPCConns,
- cfg.loadGeneralCfg, cfg.loadTemplateSCfg, cfg.loadCacheCfg, cfg.loadListenCfg,
- cfg.loadHTTPCfg, cfg.loadDataDBCfg, cfg.loadStorDBCfg,
- cfg.loadFilterSCfg,
- cfg.loadCdrsCfg, cfg.loadSessionSCfg,
- cfg.loadFreeswitchAgentCfg, cfg.loadKamAgentCfg,
- cfg.loadAsteriskAgentCfg, cfg.loadDiameterAgentCfg, cfg.loadRadiusAgentCfg,
- cfg.loadDNSAgentCfg, cfg.loadHTTPAgentCfg, cfg.loadAttributeSCfg,
- cfg.loadChargerSCfg, cfg.loadResourceSCfg, cfg.loadStatSCfg,
- cfg.loadThresholdSCfg, cfg.loadRouteSCfg, cfg.loadLoaderSCfg,
- cfg.loadSureTaxCfg, cfg.loadDispatcherSCfg,
- cfg.loadLoaderCgrCfg, cfg.loadMigratorCgrCfg, cfg.loadTLSCgrCfg,
- cfg.loadAnalyzerCgrCfg, cfg.loadApierCfg, cfg.loadErsCfg, cfg.loadEesCfg,
- cfg.loadRateSCfg, cfg.loadSIPAgentCfg, cfg.loadRegistrarCCfg,
- cfg.loadConfigSCfg, cfg.loadAPIBanCgrCfg, cfg.loadCoreSCfg, cfg.loadActionSCfg,
- cfg.loadAccountSCfg} {
- if err = loadFunc(jsnCfg); err != nil {
- return
- }
- }
- return cfg.checkConfigSanity()
-}
-
-func (cfg *CGRConfig) loadCfgFromDB(db ConfigDB, sections []string) (err error) {
- loadMap := cfg.getLoadFunctions()
- for _, section := range sections {
- if fnct, has := loadMap[section]; !has ||
- section == ConfigDBJSON {
- return fmt.Errorf("Invalid section: <%s> ", section)
- } else {
- cfg.lks[section].Lock()
- err = fnct(db)
- cfg.lks[section].Unlock()
- if err != nil {
- return
- }
- }
- }
- return
-}
-
-func (cfg *CGRConfig) V1StoreCfgInDB(ctx *context.Context, args *SectionWithAPIOpts, rply *string) (err error) {
- if cfg.db == nil {
- return errors.New("no DB connection for config")
- }
- if len(args.Sections) != 0 && args.Sections[0] != utils.MetaAll {
- for _, section := range args.Sections {
- var mp interface{}
- if mp, err = cfg.getSectionAsMap(section); err != nil {
- return
- }
- var cfgSec interface{}
- if cfgSec, err = prepareSectionFromMap(section, mp); err != nil {
- return
- }
- if err = cfg.db.SetSection(ctx, section, cfgSec); err != nil {
- return
- }
- }
- }
- cfg.rLockSections()
- mp := cfg.AsMapInterface(cfg.generalCfg.RSRSep)
- cfg.rUnlockSections()
- var data []byte
- if data, err = json.Marshal(mp); err != nil {
- return
- }
- var dp ConfigDB
- if dp, err = NewCgrJsonCfgFromBytes(data); err != nil {
- return
- }
- var sc interface{}
- if sc, err = dp.GeneralJsonCfg(); err != nil {
- return
- } else if err = cfg.db.SetSection(ctx, GeneralJSON, sc); err != nil {
- return
- }
- if sc, err = dp.RPCConnJsonCfg(); err != nil {
- return
- } else if err = cfg.db.SetSection(ctx, RPCConnsJSON, sc); err != nil {
- return
- }
- if sc, err = dp.CacheJsonCfg(); err != nil {
- return
- } else if err = cfg.db.SetSection(ctx, CacheJSON, sc); err != nil {
- return
- }
- if sc, err = dp.ListenJsonCfg(); err != nil {
- return
- } else if err = cfg.db.SetSection(ctx, ListenJSON, sc); err != nil {
- return
- }
- if sc, err = dp.HttpJsonCfg(); err != nil {
- return
- } else if err = cfg.db.SetSection(ctx, HTTPJSON, sc); err != nil {
- return
- }
- if sc, err = dp.DbJsonCfg(StorDBJSON); err != nil {
- return
- } else if err = cfg.db.SetSection(ctx, StorDBJSON, sc); err != nil {
- return
- }
- if sc, err = dp.DbJsonCfg(DataDBJSON); err != nil {
- return
- } else if err = cfg.db.SetSection(ctx, DataDBJSON, sc); err != nil {
- return
- }
- if sc, err = dp.FilterSJsonCfg(); err != nil {
- return
- } else if err = cfg.db.SetSection(ctx, FilterSJSON, sc); err != nil {
- return
- }
- if sc, err = dp.CdrsJsonCfg(); err != nil {
- return
- } else if err = cfg.db.SetSection(ctx, CDRsJSON, sc); err != nil {
- return
- }
- if sc, err = dp.ERsJsonCfg(); err != nil {
- return
- } else if err = cfg.db.SetSection(ctx, ERsJSON, sc); err != nil {
- return
- }
- if sc, err = dp.EEsJsonCfg(); err != nil {
- return
- } else if err = cfg.db.SetSection(ctx, EEsJSON, sc); err != nil {
- return
- }
- if sc, err = dp.SessionSJsonCfg(); err != nil {
- return
- } else if err = cfg.db.SetSection(ctx, SessionSJSON, sc); err != nil {
- return
- }
- if sc, err = dp.FreeswitchAgentJsonCfg(); err != nil {
- return
- } else if err = cfg.db.SetSection(ctx, FreeSWITCHAgentJSON, sc); err != nil {
- return
- }
- if sc, err = dp.KamAgentJsonCfg(); err != nil {
- return
- } else if err = cfg.db.SetSection(ctx, KamailioAgentJSON, sc); err != nil {
- return
- }
- if sc, err = dp.AsteriskAgentJsonCfg(); err != nil {
- return
- } else if err = cfg.db.SetSection(ctx, AsteriskAgentJSON, sc); err != nil {
- return
- }
- if sc, err = dp.DiameterAgentJsonCfg(); err != nil {
- return
- } else if err = cfg.db.SetSection(ctx, DiameterAgentJSON, sc); err != nil {
- return
- }
- if sc, err = dp.RadiusAgentJsonCfg(); err != nil {
- return
- } else if err = cfg.db.SetSection(ctx, RadiusAgentJSON, sc); err != nil {
- return
- }
- if sc, err = dp.HttpAgentJsonCfg(); err != nil {
- return
- } else if err = cfg.db.SetSection(ctx, HTTPAgentJSON, sc); err != nil {
- return
- }
- if sc, err = dp.DNSAgentJsonCfg(); err != nil {
- return
- } else if err = cfg.db.SetSection(ctx, DNSAgentJSON, sc); err != nil {
- return
- }
- if sc, err = dp.AttributeServJsonCfg(); err != nil {
- return
- } else if err = cfg.db.SetSection(ctx, AttributeSJSON, sc); err != nil {
- return
- }
- if sc, err = dp.ChargerServJsonCfg(); err != nil {
- return
- } else if err = cfg.db.SetSection(ctx, ChargerSJSON, sc); err != nil {
- return
- }
- if sc, err = dp.ResourceSJsonCfg(); err != nil {
- return
- } else if err = cfg.db.SetSection(ctx, ResourceSJSON, sc); err != nil {
- return
- }
- if sc, err = dp.StatSJsonCfg(); err != nil {
- return
- } else if err = cfg.db.SetSection(ctx, StatSJSON, sc); err != nil {
- return
- }
- if sc, err = dp.ThresholdSJsonCfg(); err != nil {
- return
- } else if err = cfg.db.SetSection(ctx, ThresholdSJSON, sc); err != nil {
- return
- }
- if sc, err = dp.RouteSJsonCfg(); err != nil {
- return
- } else if err = cfg.db.SetSection(ctx, RouteSJSON, sc); err != nil {
- return
- }
- if sc, err = dp.LoaderJsonCfg(); err != nil {
- return
- } else if err = cfg.db.SetSection(ctx, LoaderSJSON, sc); err != nil {
- return
- }
- if sc, err = dp.SureTaxJsonCfg(); err != nil {
- return
- } else if err = cfg.db.SetSection(ctx, SureTaxJSON, sc); err != nil {
- return
- }
- if sc, err = dp.DispatcherSJsonCfg(); err != nil {
- return
- } else if err = cfg.db.SetSection(ctx, DispatcherSJSON, sc); err != nil {
- return
- }
- if sc, err = dp.RegistrarCJsonCfgs(); err != nil {
- return
- } else if err = cfg.db.SetSection(ctx, RegistrarCJSON, sc); err != nil {
- return
- }
- if sc, err = dp.LoaderCfgJson(); err != nil {
- return
- } else if err = cfg.db.SetSection(ctx, LoaderJSON, sc); err != nil {
- return
- }
- if sc, err = dp.MigratorCfgJson(); err != nil {
- return
- } else if err = cfg.db.SetSection(ctx, MigratorJSON, sc); err != nil {
- return
- }
- if sc, err = dp.TlsCfgJson(); err != nil {
- return
- } else if err = cfg.db.SetSection(ctx, TlsJSON, sc); err != nil {
- return
- }
- if sc, err = dp.AnalyzerCfgJson(); err != nil {
- return
- } else if err = cfg.db.SetSection(ctx, AnalyzerSJSON, sc); err != nil {
- return
- }
- if sc, err = dp.AdminSCfgJson(); err != nil {
- return
- } else if err = cfg.db.SetSection(ctx, AdminSJSON, sc); err != nil {
- return
- }
- if sc, err = dp.RateCfgJson(); err != nil {
- return
- } else if err = cfg.db.SetSection(ctx, RateSJSON, sc); err != nil {
- return
- }
- if sc, err = dp.SIPAgentJsonCfg(); err != nil {
- return
- } else if err = cfg.db.SetSection(ctx, SIPAgentJSON, sc); err != nil {
- return
- }
- if sc, err = dp.TemplateSJsonCfg(); err != nil {
- return
- } else if err = cfg.db.SetSection(ctx, TemplatesJSON, sc); err != nil {
- return
- }
- if sc, err = dp.ConfigSJsonCfg(); err != nil {
- return
- } else if err = cfg.db.SetSection(ctx, ConfigSJSON, sc); err != nil {
- return
- }
- if sc, err = dp.ApiBanCfgJson(); err != nil {
- return
- } else if err = cfg.db.SetSection(ctx, APIBanJSON, sc); err != nil {
- return
- }
- if sc, err = dp.CoreSJSON(); err != nil {
- return
- } else if err = cfg.db.SetSection(ctx, CoreSJSON, sc); err != nil {
- return
- }
- if sc, err = dp.ActionSCfgJson(); err != nil {
- return
- } else if err = cfg.db.SetSection(ctx, ActionSJSON, sc); err != nil {
- return
- }
- if sc, err = dp.AccountSCfgJson(); err != nil {
- return
- } else if err = cfg.db.SetSection(ctx, AccountSJSON, sc); err != nil {
- return
- }
- *rply = utils.OK
- return
-}
-
-func prepareSectionFromMap(section string, mp interface{}) (cfgSec interface{}, err error) {
- var data []byte
- if data, err = json.Marshal(mp); err != nil {
- return
- }
- switch section {
- case GeneralJSON:
- cfgSec = new(GeneralJsonCfg)
- case RPCConnsJSON:
- cfgSec = &RPCConnsJson{}
- case CacheJSON:
- cfgSec = new(CacheJsonCfg)
- case ListenJSON:
- cfgSec = new(ListenJsonCfg)
- case HTTPJSON:
- cfgSec = new(HTTPJsonCfg)
- case StorDBJSON:
- cfgSec = new(DbJsonCfg)
- case DataDBJSON:
- cfgSec = new(DbJsonCfg)
- case FilterSJSON:
- cfgSec = new(FilterSJsonCfg)
- case CDRsJSON:
- cfgSec = new(CdrsJsonCfg)
- case ERsJSON:
- cfgSec = new(ERsJsonCfg)
- case EEsJSON:
- cfgSec = new(EEsJsonCfg)
- case SessionSJSON:
- cfgSec = new(SessionSJsonCfg)
- case FreeSWITCHAgentJSON:
- cfgSec = new(FreeswitchAgentJsonCfg)
- case KamailioAgentJSON:
- cfgSec = new(KamAgentJsonCfg)
- case AsteriskAgentJSON:
- cfgSec = new(AsteriskAgentJsonCfg)
- case DiameterAgentJSON:
- cfgSec = new(DiameterAgentJsonCfg)
- case RadiusAgentJSON:
- cfgSec = new(RadiusAgentJsonCfg)
- case HTTPAgentJSON:
- cfgSec = new([]*HttpAgentJsonCfg)
- case DNSAgentJSON:
- cfgSec = new(DNSAgentJsonCfg)
- case AttributeSJSON:
- cfgSec = new(AttributeSJsonCfg)
- case ChargerSJSON:
- cfgSec = new(ChargerSJsonCfg)
- case ResourceSJSON:
- cfgSec = new(ResourceSJsonCfg)
- case StatSJSON:
- cfgSec = new(StatServJsonCfg)
- case ThresholdSJSON:
- cfgSec = new(ThresholdSJsonCfg)
- case RouteSJSON:
- cfgSec = new(RouteSJsonCfg)
- case LoaderSJSON:
- cfgSec = make([]*LoaderJsonCfg, 0)
- case SureTaxJSON:
- cfgSec = new(SureTaxJsonCfg)
- case DispatcherSJSON:
- cfgSec = new(DispatcherSJsonCfg)
- case RegistrarCJSON:
- cfgSec = new(RegistrarCJsonCfgs)
- case LoaderJSON:
- cfgSec = new(LoaderCfgJson)
- case MigratorJSON:
- cfgSec = new(MigratorCfgJson)
- case TlsJSON:
- cfgSec = new(TlsJsonCfg)
- case AnalyzerSJSON:
- cfgSec = new(AnalyzerSJsonCfg)
- case AdminSJSON:
- cfgSec = new(AdminSJsonCfg)
- case RateSJSON:
- cfgSec = new(RateSJsonCfg)
- case SIPAgentJSON:
- cfgSec = new(SIPAgentJsonCfg)
- case TemplatesJSON:
- cfgSec = &FcTemplatesJsonCfg{}
- case ConfigSJSON:
- cfgSec = new(ConfigSCfgJson)
- case APIBanJSON:
- cfgSec = new(APIBanJsonCfg)
- case CoreSJSON:
- cfgSec = new(CoreSJsonCfg)
- case ActionSJSON:
- cfgSec = new(ActionSJsonCfg)
- case AccountSJSON:
- cfgSec = new(AccountSJsonCfg)
- }
-
- err = json.Unmarshal(data, cfgSec)
- return
-}
-
-func updateSections(ctx *context.Context, db ConfigDB, mp map[string]interface{}) (err error) {
- for section, val := range mp {
- var sec interface{}
- if sec, err = prepareSectionFromDB(section, db); err != nil {
- return
- }
- var data []byte
- if data, err = json.Marshal(val); err != nil {
- return
- }
- if err = json.Unmarshal(data, &sec); err != nil {
- return
- }
- if err = db.SetSection(ctx, section, sec); err != nil {
- return
- }
- }
- return
-}
-
-func prepareSectionFromDB(section string, db ConfigDB) (cfgSec interface{}, err error) {
- switch section {
- case GeneralJSON:
- cfgSec, err = db.GeneralJsonCfg()
- case RPCConnsJSON:
- cfgSec, err = db.RPCConnJsonCfg()
- case CacheJSON:
- cfgSec, err = db.CacheJsonCfg()
- case ListenJSON:
- cfgSec, err = db.ListenJsonCfg()
- case HTTPJSON:
- cfgSec, err = db.HttpJsonCfg()
- case StorDBJSON:
- cfgSec, err = db.DbJsonCfg(StorDBJSON)
- case DataDBJSON:
- cfgSec, err = db.DbJsonCfg(DataDBJSON)
- case FilterSJSON:
- cfgSec, err = db.FilterSJsonCfg()
- case CDRsJSON:
- cfgSec, err = db.CdrsJsonCfg()
- case ERsJSON:
- cfgSec, err = db.ERsJsonCfg()
- case EEsJSON:
- cfgSec, err = db.EEsJsonCfg()
- case SessionSJSON:
- cfgSec, err = db.SessionSJsonCfg()
- case FreeSWITCHAgentJSON:
- cfgSec, err = db.FreeswitchAgentJsonCfg()
- case KamailioAgentJSON:
- cfgSec, err = db.KamAgentJsonCfg()
- case AsteriskAgentJSON:
- cfgSec, err = db.AsteriskAgentJsonCfg()
- case DiameterAgentJSON:
- cfgSec, err = db.DiameterAgentJsonCfg()
- case RadiusAgentJSON:
- cfgSec, err = db.RadiusAgentJsonCfg()
- case HTTPAgentJSON:
- cfgSec, err = db.HttpAgentJsonCfg()
- case DNSAgentJSON:
- cfgSec, err = db.DNSAgentJsonCfg()
- case AttributeSJSON:
- cfgSec, err = db.AttributeServJsonCfg()
- case ChargerSJSON:
- cfgSec, err = db.ChargerServJsonCfg()
- case ResourceSJSON:
- cfgSec, err = db.ResourceSJsonCfg()
- case StatSJSON:
- cfgSec, err = db.StatSJsonCfg()
- case ThresholdSJSON:
- cfgSec, err = db.ThresholdSJsonCfg()
- case RouteSJSON:
- cfgSec, err = db.RouteSJsonCfg()
- case LoaderSJSON:
- cfgSec, err = db.LoaderJsonCfg()
- case SureTaxJSON:
- cfgSec, err = db.SureTaxJsonCfg()
- case DispatcherSJSON:
- cfgSec, err = db.DispatcherSJsonCfg()
- case RegistrarCJSON:
- cfgSec, err = db.RegistrarCJsonCfgs()
- case LoaderJSON:
- cfgSec, err = db.LoaderCfgJson()
- case MigratorJSON:
- cfgSec, err = db.MigratorCfgJson()
- case TlsJSON:
- cfgSec, err = db.TlsCfgJson()
- case AnalyzerSJSON:
- cfgSec, err = db.AnalyzerCfgJson()
- case AdminSJSON:
- cfgSec, err = db.AdminSCfgJson()
- case RateSJSON:
- cfgSec, err = db.RateCfgJson()
- case SIPAgentJSON:
- cfgSec, err = db.SIPAgentJsonCfg()
- case TemplatesJSON:
- cfgSec, err = db.TemplateSJsonCfg()
- case ConfigSJSON:
- cfgSec, err = db.ConfigSJsonCfg()
- case APIBanJSON:
- cfgSec, err = db.ApiBanCfgJson()
- case CoreSJSON:
- cfgSec, err = db.CoreSJSON()
- case ActionSJSON:
- cfgSec, err = db.ActionSCfgJson()
- case AccountSJSON:
- cfgSec, err = db.AccountSCfgJson()
- }
- return
-}
diff --git a/config/config_apis_test.go b/config/config_apis_test.go
deleted file mode 100644
index 22f52d7f1..000000000
--- a/config/config_apis_test.go
+++ /dev/null
@@ -1,967 +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
-*/
-package config
-
-import (
- "reflect"
- "testing"
-
- "github.com/cgrates/cgrates/utils"
-)
-
-func TestPrepareGeneralSectionFromMap(t *testing.T) {
- section := GeneralJSON
- mp := map[string]interface{}{
- "Node_id": "",
- "Logger": "*syslog",
- "Log_level": 7,
- "Rounding_decimals": 5,
- "Dbdata_encoding": "*msgpack",
- "Tpexport_dir": "/var/spool/cgrates/tpe",
- "Poster_attempts": 3,
- "Failed_posts_dir": "/var/spool/cgrates/failed_posts",
- "Failed_posts_ttl": "5s",
- "Default_request_type": "*rated",
- "Default_category": "call",
- "Default_tenant": "cgrates.org",
- "Default_timezone": "Local",
- "Default_caching": "*reload",
- "Min_call_duration": "0s",
- "Max_call_duration": "3h",
- "Connect_attempts": 5,
- "Reconnects": -1,
- "Connect_timeout": "1s",
- "Reply_timeout": "2s",
- "Locking_timeout": "0",
- "Digest_separator": ",",
- "Digest_equal": ":",
- "Rsr_separator": ";",
- "Max_parallel_conns": 100,
- }
- expected := &GeneralJsonCfg{
- Node_id: utils.StringPointer(""),
- Logger: utils.StringPointer("*syslog"),
- Log_level: utils.IntPointer(7),
- Rounding_decimals: utils.IntPointer(5),
- Dbdata_encoding: utils.StringPointer("*msgpack"),
- Tpexport_dir: utils.StringPointer("/var/spool/cgrates/tpe"),
- Poster_attempts: utils.IntPointer(3),
- Failed_posts_dir: utils.StringPointer("/var/spool/cgrates/failed_posts"),
- Failed_posts_ttl: utils.StringPointer("5s"),
- Default_request_type: utils.StringPointer("*rated"),
- Default_category: utils.StringPointer("call"),
- Default_tenant: utils.StringPointer("cgrates.org"),
- Default_timezone: utils.StringPointer("Local"),
- Default_caching: utils.StringPointer("*reload"),
- Connect_attempts: utils.IntPointer(5),
- Reconnects: utils.IntPointer(-1),
- Connect_timeout: utils.StringPointer("1s"),
- Reply_timeout: utils.StringPointer("2s"),
- Locking_timeout: utils.StringPointer("0"),
- Digest_separator: utils.StringPointer(","),
- Digest_equal: utils.StringPointer(":"),
- Rsr_separator: utils.StringPointer(";"),
- Max_parallel_conns: utils.IntPointer(100),
- }
- if cfgSec, err := prepareSectionFromMap(section, mp); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(cfgSec, expected) {
- t.Errorf("Expected %v \n but received \n %v", utils.ToJSON(mp), utils.ToJSON(cfgSec))
- }
-}
-
-func TestPrepareCacheSectionFromMap(t *testing.T) {
- section := CacheJSON
- mp := &CacheJsonCfg{
- Partitions: map[string]*CacheParamJsonCfg{
- "*resource_profiles": {
- Limit: utils.IntPointer(-1),
- Ttl: utils.StringPointer(""),
- Static_ttl: utils.BoolPointer(false),
- Precache: utils.BoolPointer(false),
- Replicate: utils.BoolPointer(false),
- },
- },
- }
-
- expected := &CacheJsonCfg{
- Partitions: map[string]*CacheParamJsonCfg{
- "*resource_profiles": {
- Limit: utils.IntPointer(-1),
- Ttl: utils.StringPointer(""),
- Static_ttl: utils.BoolPointer(false),
- Precache: utils.BoolPointer(false),
- Replicate: utils.BoolPointer(false),
- },
- },
- }
-
- if cfgSec, err := prepareSectionFromMap(section, mp); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(cfgSec, expected) {
- t.Errorf("Expected %v \n but received \n %v", utils.ToJSON(mp), utils.ToJSON(cfgSec))
- }
-}
-
-func TestPrepareListenSectionFromMap(t *testing.T) {
- section := ListenJSON
- mp := &ListenJsonCfg{
- Rpc_json: utils.StringPointer("127.0.0.1:2012"),
- Rpc_gob: utils.StringPointer("127.0.0.1:2013"),
- Http: utils.StringPointer("127.0.0.1:2080"),
- Rpc_json_tls: utils.StringPointer("127.0.0.1:2023"),
- Http_tls: utils.StringPointer("127.0.0.1:2280"),
- }
-
- expected := &ListenJsonCfg{
- Rpc_json: utils.StringPointer("127.0.0.1:2012"),
- Rpc_gob: utils.StringPointer("127.0.0.1:2013"),
- Http: utils.StringPointer("127.0.0.1:2080"),
- Rpc_json_tls: utils.StringPointer("127.0.0.1:2023"),
- Http_tls: utils.StringPointer("127.0.0.1:2280"),
- }
-
- if cfgSec, err := prepareSectionFromMap(section, mp); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(cfgSec, expected) {
- t.Errorf("Expected %v \n but received \n %v", utils.ToJSON(mp), utils.ToJSON(cfgSec))
- }
-}
-
-func TestPrepareHTTPSectionFromMap(t *testing.T) {
- section := HTTPJSON
- mp := &HTTPJsonCfg{
- Json_rpc_url: utils.StringPointer("/jsonrpc"),
- Registrars_url: utils.StringPointer("/registrar"),
- Ws_url: utils.StringPointer("/ws"),
- Freeswitch_cdrs_url: utils.StringPointer("/freeswitch_json"),
- Http_Cdrs: utils.StringPointer("/cdr_http"),
- Use_basic_auth: utils.BoolPointer(false),
- Auth_users: &map[string]string{
- "user1": "pass1",
- },
- Client_opts: map[string]interface{}{},
- }
-
- expected := &HTTPJsonCfg{
- Json_rpc_url: utils.StringPointer("/jsonrpc"),
- Registrars_url: utils.StringPointer("/registrar"),
- Ws_url: utils.StringPointer("/ws"),
- Freeswitch_cdrs_url: utils.StringPointer("/freeswitch_json"),
- Http_Cdrs: utils.StringPointer("/cdr_http"),
- Use_basic_auth: utils.BoolPointer(false),
- Auth_users: &map[string]string{
- "user1": "pass1",
- },
- Client_opts: map[string]interface{}{},
- }
-
- if cfgSec, err := prepareSectionFromMap(section, mp); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(cfgSec, expected) {
- t.Errorf("Expected %v \n but received \n %v", utils.ToJSON(mp), utils.ToJSON(cfgSec))
- }
-}
-
-func TestPrepareStorDBSectionFromMap(t *testing.T) {
- section := StorDBJSON
- mp := map[string]interface{}{
- "db_type": "*mysql",
- "db_host": "127.0.0.1",
- "db_port": 3306,
- "db_name": "cgrates",
- "db_user": "cgrates",
- "db_password": "",
- "string_indexed_fields": []string{},
- "prefix_indexed_fields": []string{},
- "opts": map[string]interface{}{},
- "items": map[string]*ItemOptJson{},
- }
-
- expected := &DbJsonCfg{
- Db_type: utils.StringPointer("*mysql"),
- Db_host: utils.StringPointer("127.0.0.1"),
- Db_port: utils.IntPointer(3306),
- Db_name: utils.StringPointer("cgrates"),
- Db_user: utils.StringPointer("cgrates"),
- Db_password: utils.StringPointer(""),
- String_indexed_fields: &[]string{},
- Prefix_indexed_fields: &[]string{},
- Opts: map[string]interface{}{},
- Items: map[string]*ItemOptJson{},
- }
-
- if cfgSec, err := prepareSectionFromMap(section, mp); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(cfgSec, expected) {
- t.Errorf("Expected %v \n but received \n %v", utils.ToJSON(mp), utils.ToJSON(cfgSec))
- }
-}
-
-func TestPrepareDataDBSectionFromMap(t *testing.T) {
- section := DataDBJSON
- mp := &DbJsonCfg{
- Db_type: utils.StringPointer("*mysql"),
- Db_host: utils.StringPointer("127.0.0.1"),
- Db_port: utils.IntPointer(3306),
- Db_name: utils.StringPointer("cgrates"),
- Db_user: utils.StringPointer("cgrates"),
- Db_password: utils.StringPointer(""),
- String_indexed_fields: &[]string{},
- Prefix_indexed_fields: &[]string{},
- Opts: map[string]interface{}{},
- Items: map[string]*ItemOptJson{},
- }
-
- expected := &DbJsonCfg{
- Db_type: utils.StringPointer("*mysql"),
- Db_host: utils.StringPointer("127.0.0.1"),
- Db_port: utils.IntPointer(3306),
- Db_name: utils.StringPointer("cgrates"),
- Db_user: utils.StringPointer("cgrates"),
- Db_password: utils.StringPointer(""),
- String_indexed_fields: &[]string{},
- Prefix_indexed_fields: &[]string{},
- Opts: map[string]interface{}{},
- Items: map[string]*ItemOptJson{},
- }
-
- if cfgSec, err := prepareSectionFromMap(section, mp); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(cfgSec, expected) {
- t.Errorf("Expected %v \n but received \n %v", utils.ToJSON(mp), utils.ToJSON(cfgSec))
- }
-}
-
-func TestPrepareFilterSSectionFromMap(t *testing.T) {
- section := FilterSJSON
- mp := &FilterSJsonCfg{
-
- Stats_conns: &[]string{"*birpc"},
- Resources_conns: &[]string{"*birpc"},
- Admins_conns: &[]string{"*birpc"},
- }
-
- expected := &FilterSJsonCfg{
- Stats_conns: &[]string{"*birpc"},
- Resources_conns: &[]string{"*birpc"},
- Admins_conns: &[]string{"*birpc"},
- }
-
- if cfgSec, err := prepareSectionFromMap(section, mp); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(cfgSec, expected) {
- t.Errorf("Expected %v \n but received \n %v", utils.ToJSON(mp), utils.ToJSON(cfgSec))
- }
-}
-
-func TestPrepareCDRsSectionFromMap(t *testing.T) {
- section := CDRsJSON
- mp := &CdrsJsonCfg{
- Enabled: utils.BoolPointer(true),
- Extra_fields: &[]string{"extra_field"},
- Session_cost_retries: utils.IntPointer(2),
- Store_cdrs: utils.BoolPointer(true),
- Stats_conns: &[]string{"*birpc"},
- Chargers_conns: &[]string{"*birpc"},
- Thresholds_conns: &[]string{"*birpc"},
- Attributes_conns: &[]string{"*birpc"},
- Ees_conns: &[]string{"*birpc"},
- Online_cdr_exports: &[]string{"online_cdr_export"},
- Actions_conns: &[]string{"*birpc"},
- }
-
- expected := &CdrsJsonCfg{
- Enabled: utils.BoolPointer(true),
- Extra_fields: &[]string{"extra_field"},
- Session_cost_retries: utils.IntPointer(2),
- Store_cdrs: utils.BoolPointer(true),
- Stats_conns: &[]string{"*birpc"},
- Chargers_conns: &[]string{"*birpc"},
- Thresholds_conns: &[]string{"*birpc"},
- Attributes_conns: &[]string{"*birpc"},
- Ees_conns: &[]string{"*birpc"},
- Online_cdr_exports: &[]string{"online_cdr_export"},
- Actions_conns: &[]string{"*birpc"},
- }
-
- if cfgSec, err := prepareSectionFromMap(section, mp); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(cfgSec, expected) {
- t.Errorf("Expected %v \n but received \n %v", utils.ToJSON(mp), utils.ToJSON(cfgSec))
- }
-}
-
-func TestPrepareERsSectionFromMap(t *testing.T) {
- section := ERsJSON
- mp := &ERsJsonCfg{
- Enabled: utils.BoolPointer(true),
- Sessions_conns: &[]string{"*birpc"},
- Readers: &[]*EventReaderJsonCfg{
- {
- Id: utils.StringPointer("ERsID"),
- },
- },
- Partial_cache_ttl: utils.StringPointer("partial_cache_ttl"),
- Partial_cache_action: utils.StringPointer("partial_cache_action"),
- Partial_path: utils.StringPointer("/partial/path"),
- }
-
- expected := &ERsJsonCfg{
- Enabled: utils.BoolPointer(true),
- Sessions_conns: &[]string{"*birpc"},
- Readers: &[]*EventReaderJsonCfg{
- {
- Id: utils.StringPointer("ERsID"),
- },
- },
- Partial_cache_ttl: utils.StringPointer("partial_cache_ttl"),
- Partial_cache_action: utils.StringPointer("partial_cache_action"),
- Partial_path: utils.StringPointer("/partial/path"),
- }
-
- if cfgSec, err := prepareSectionFromMap(section, mp); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(cfgSec, expected) {
- t.Errorf("Expected %v \n but received \n %v", utils.ToJSON(mp), utils.ToJSON(cfgSec))
- }
-}
-
-func TestPrepareEEsSectionFromMap(t *testing.T) {
- section := EEsJSON
- mp := &EEsJsonCfg{
- Enabled: utils.BoolPointer(true),
- Attributes_conns: &[]string{"*birpc"},
- Cache: map[string]*CacheParamJsonCfg{
- "CACHE1": {
- Limit: utils.IntPointer(2),
- },
- },
- Exporters: &[]*EventExporterJsonCfg{
- {
- Id: utils.StringPointer("EEsID"),
- },
- },
- }
-
- expected := &EEsJsonCfg{
- Enabled: utils.BoolPointer(true),
- Attributes_conns: &[]string{"*birpc"},
- Cache: map[string]*CacheParamJsonCfg{
- "CACHE1": {
- Limit: utils.IntPointer(2),
- },
- },
- Exporters: &[]*EventExporterJsonCfg{
- {
- Id: utils.StringPointer("EEsID"),
- },
- },
- }
-
- if cfgSec, err := prepareSectionFromMap(section, mp); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(cfgSec, expected) {
- t.Errorf("Expected %v \n but received \n %v", utils.ToJSON(mp), utils.ToJSON(cfgSec))
- }
-}
-
-func TestPrepareSessionSSectionFromMap(t *testing.T) {
- section := SessionSJSON
- mp := &SessionSJsonCfg{
- Enabled: utils.BoolPointer(true),
- Listen_bijson: utils.StringPointer("*tcp"),
- Listen_bigob: utils.StringPointer("*tcp"),
- Stats_conns: &[]string{"*birpc"},
- Chargers_conns: &[]string{"*birpc"},
- Thresholds_conns: &[]string{"*birpc"},
- Attributes_conns: &[]string{"*birpc"},
- Cdrs_conns: &[]string{"*birpc"},
- Resources_conns: &[]string{"*birpc"},
- Routes_conns: &[]string{"*birpc"},
- Replication_conns: &[]string{"*birpc"},
- Debit_interval: utils.StringPointer("2s"),
- Store_session_costs: utils.BoolPointer(true),
- Session_ttl: utils.StringPointer("session_ttl"),
- Session_ttl_max_delay: utils.StringPointer("session_ttl_max_delay"),
- Session_ttl_last_used: utils.StringPointer("session_ttl_last_used"),
- Session_ttl_usage: utils.StringPointer("session_ttl_usage"),
- Session_ttl_last_usage: utils.StringPointer("session_ttl_last_usage"),
- Session_indexes: &[]string{"session_index"},
- Client_protocol: utils.Float64Pointer(12.2),
- Channel_sync_interval: utils.StringPointer("channel_sync_interval"),
- Terminate_attempts: utils.IntPointer(2),
- Alterable_fields: &[]string{"alterable_field"},
- Min_dur_low_balance: utils.StringPointer("min_dur_low_balance"),
- Actions_conns: &[]string{"*birpc"},
- Stir: &STIRJsonCfg{
- Payload_maxduration: utils.StringPointer("2s"),
- },
- Default_usage: map[string]string{},
- }
-
- expected := &SessionSJsonCfg{
- Enabled: utils.BoolPointer(true),
- Listen_bijson: utils.StringPointer("*tcp"),
- Listen_bigob: utils.StringPointer("*tcp"),
- Stats_conns: &[]string{"*birpc"},
- Chargers_conns: &[]string{"*birpc"},
- Thresholds_conns: &[]string{"*birpc"},
- Attributes_conns: &[]string{"*birpc"},
- Cdrs_conns: &[]string{"*birpc"},
- Resources_conns: &[]string{"*birpc"},
- Routes_conns: &[]string{"*birpc"},
- Replication_conns: &[]string{"*birpc"},
- Debit_interval: utils.StringPointer("2s"),
- Store_session_costs: utils.BoolPointer(true),
- Session_ttl: utils.StringPointer("session_ttl"),
- Session_ttl_max_delay: utils.StringPointer("session_ttl_max_delay"),
- Session_ttl_last_used: utils.StringPointer("session_ttl_last_used"),
- Session_ttl_usage: utils.StringPointer("session_ttl_usage"),
- Session_ttl_last_usage: utils.StringPointer("session_ttl_last_usage"),
- Session_indexes: &[]string{"session_index"},
- Client_protocol: utils.Float64Pointer(12.2),
- Channel_sync_interval: utils.StringPointer("channel_sync_interval"),
- Terminate_attempts: utils.IntPointer(2),
- Alterable_fields: &[]string{"alterable_field"},
- Min_dur_low_balance: utils.StringPointer("min_dur_low_balance"),
- Actions_conns: &[]string{"*birpc"},
- Stir: &STIRJsonCfg{
- Payload_maxduration: utils.StringPointer("2s"),
- },
- Default_usage: map[string]string{},
- }
-
- if cfgSec, err := prepareSectionFromMap(section, mp); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(cfgSec, expected) {
- t.Errorf("Expected %v \n but received \n %v", utils.ToJSON(mp), utils.ToJSON(cfgSec))
- }
-}
-
-func TestPrepareFreeSWITCHAgentSectionFromMap(t *testing.T) {
- section := FreeSWITCHAgentJSON
- mp := &FreeswitchAgentJsonCfg{
- Enabled: utils.BoolPointer(true),
- Sessions_conns: &[]string{"*birpc"},
- Subscribe_park: utils.BoolPointer(true),
- Create_cdr: utils.BoolPointer(true),
- Extra_fields: &[]string{"extra_field"},
- Low_balance_ann_file: utils.StringPointer("low_balance_ann_file"),
- Empty_balance_context: utils.StringPointer("empty_balance_context"),
- Empty_balance_ann_file: utils.StringPointer("empty_balance_ann_file"),
- Max_wait_connection: utils.StringPointer("2s"),
- Event_socket_conns: &[]*FsConnJsonCfg{},
- }
-
- expected := &FreeswitchAgentJsonCfg{
- Enabled: utils.BoolPointer(true),
- Sessions_conns: &[]string{"*birpc"},
- Subscribe_park: utils.BoolPointer(true),
- Create_cdr: utils.BoolPointer(true),
- Extra_fields: &[]string{"extra_field"},
- Low_balance_ann_file: utils.StringPointer("low_balance_ann_file"),
- Empty_balance_context: utils.StringPointer("empty_balance_context"),
- Empty_balance_ann_file: utils.StringPointer("empty_balance_ann_file"),
- Max_wait_connection: utils.StringPointer("2s"),
- Event_socket_conns: &[]*FsConnJsonCfg{},
- }
-
- if cfgSec, err := prepareSectionFromMap(section, mp); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(cfgSec, expected) {
- t.Errorf("Expected %v \n but received \n %v", utils.ToJSON(mp), utils.ToJSON(cfgSec))
- }
-}
-
-func TestPrepareKamAgentSectionFromMap(t *testing.T) {
- section := KamailioAgentJSON
- mp := &KamAgentJsonCfg{
- Enabled: utils.BoolPointer(true),
- Sessions_conns: &[]string{"*birpc"},
- Create_cdr: utils.BoolPointer(true),
- Evapi_conns: &[]*KamConnJsonCfg{},
- Timezone: utils.StringPointer("UTC"),
- }
-
- expected := &KamAgentJsonCfg{
- Enabled: utils.BoolPointer(true),
- Sessions_conns: &[]string{"*birpc"},
- Create_cdr: utils.BoolPointer(true),
- Evapi_conns: &[]*KamConnJsonCfg{},
- Timezone: utils.StringPointer("UTC"),
- }
-
- if cfgSec, err := prepareSectionFromMap(section, mp); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(cfgSec, expected) {
- t.Errorf("Expected %v \n but received \n %v", utils.ToJSON(mp), utils.ToJSON(cfgSec))
- }
-}
-
-func TestPrepareAsteriskAgentSectionFromMap(t *testing.T) {
- section := AsteriskAgentJSON
- mp := &AsteriskAgentJsonCfg{
- Enabled: utils.BoolPointer(true),
- Sessions_conns: &[]string{"*birpc"},
- Create_cdr: utils.BoolPointer(true),
- Asterisk_conns: &[]*AstConnJsonCfg{},
- }
-
- expected := &AsteriskAgentJsonCfg{
- Enabled: utils.BoolPointer(true),
- Sessions_conns: &[]string{"*birpc"},
- Create_cdr: utils.BoolPointer(true),
- Asterisk_conns: &[]*AstConnJsonCfg{},
- }
-
- if cfgSec, err := prepareSectionFromMap(section, mp); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(cfgSec, expected) {
- t.Errorf("Expected %v \n but received \n %v", utils.ToJSON(mp), utils.ToJSON(cfgSec))
- }
-}
-
-func TestPrepareDiameterAgentSectionFromMap(t *testing.T) {
- section := DiameterAgentJSON
- mp := &DiameterAgentJsonCfg{
- Enabled: utils.BoolPointer(true),
- Listen: utils.StringPointer("127.0.0.1:8080"),
- Listen_net: utils.StringPointer("tcp"),
- Dictionaries_path: utils.StringPointer("dictionaries/path"),
- Sessions_conns: &[]string{"*localhost"},
- Origin_host: utils.StringPointer("origin_host"),
- Origin_realm: utils.StringPointer("origin_realm"),
- Vendor_id: utils.IntPointer(2),
- Product_name: utils.StringPointer("prod_name"),
- Concurrent_requests: utils.IntPointer(3),
- Synced_conn_requests: utils.BoolPointer(false),
- Asr_template: utils.StringPointer("asr_template"),
- Rar_template: utils.StringPointer("rar_template"),
- Request_processors: &[]*ReqProcessorJsnCfg{},
- }
-
- expected := &DiameterAgentJsonCfg{
- Enabled: utils.BoolPointer(true),
- Listen: utils.StringPointer("127.0.0.1:8080"),
- Listen_net: utils.StringPointer("tcp"),
- Dictionaries_path: utils.StringPointer("dictionaries/path"),
- Sessions_conns: &[]string{"*localhost"},
- Origin_host: utils.StringPointer("origin_host"),
- Origin_realm: utils.StringPointer("origin_realm"),
- Vendor_id: utils.IntPointer(2),
- Product_name: utils.StringPointer("prod_name"),
- Concurrent_requests: utils.IntPointer(3),
- Synced_conn_requests: utils.BoolPointer(false),
- Asr_template: utils.StringPointer("asr_template"),
- Rar_template: utils.StringPointer("rar_template"),
- Request_processors: &[]*ReqProcessorJsnCfg{},
- }
-
- if cfgSec, err := prepareSectionFromMap(section, mp); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(cfgSec, expected) {
- t.Errorf("Expected %v \n but received \n %v", utils.ToJSON(mp), utils.ToJSON(cfgSec))
- }
-}
-
-func TestPrepareRadiusAgentSectionFromMap(t *testing.T) {
- section := RadiusAgentJSON
- mp := &RadiusAgentJsonCfg{
- Enabled: utils.BoolPointer(true),
- Listen_net: utils.StringPointer("tcp"),
- Listen_auth: utils.StringPointer("listen_auth"),
- Listen_acct: utils.StringPointer("listen_acct"),
- Client_secrets: map[string]string{
- "user1": "pass1",
- },
- Client_dictionaries: map[string]string{
- "user1": "dictionary1",
- },
- Sessions_conns: &[]string{"*birpc"},
- Request_processors: &[]*ReqProcessorJsnCfg{},
- }
-
- expected := &RadiusAgentJsonCfg{
- Enabled: utils.BoolPointer(true),
- Listen_net: utils.StringPointer("tcp"),
- Listen_auth: utils.StringPointer("listen_auth"),
- Listen_acct: utils.StringPointer("listen_acct"),
- Client_secrets: map[string]string{
- "user1": "pass1",
- },
- Client_dictionaries: map[string]string{
- "user1": "dictionary1",
- },
- Sessions_conns: &[]string{"*birpc"},
- Request_processors: &[]*ReqProcessorJsnCfg{},
- }
-
- if cfgSec, err := prepareSectionFromMap(section, mp); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(cfgSec, expected) {
- t.Errorf("Expected %v \n but received \n %v", utils.ToJSON(mp), utils.ToJSON(cfgSec))
- }
-}
-
-func TestPrepareDNSAgentSectionFromMap(t *testing.T) {
- section := DNSAgentJSON
- mp := &DNSAgentJsonCfg{
- Enabled: utils.BoolPointer(true),
- Listen: utils.StringPointer("127.0.0.1:8080"),
- Listen_net: utils.StringPointer("tcp"),
- Sessions_conns: &[]string{"*birpc"},
- Timezone: utils.StringPointer("UTC"),
- Request_processors: &[]*ReqProcessorJsnCfg{},
- }
-
- expected := &DNSAgentJsonCfg{
- Enabled: utils.BoolPointer(true),
- Listen: utils.StringPointer("127.0.0.1:8080"),
- Listen_net: utils.StringPointer("tcp"),
- Sessions_conns: &[]string{"*birpc"},
- Timezone: utils.StringPointer("UTC"),
- Request_processors: &[]*ReqProcessorJsnCfg{},
- }
-
- if cfgSec, err := prepareSectionFromMap(section, mp); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(cfgSec, expected) {
- t.Errorf("Expected %v \n but received \n %v", utils.ToJSON(mp), utils.ToJSON(cfgSec))
- }
-}
-
-func TestPrepareAttributeSSectionFromMap(t *testing.T) {
- section := AttributeSJSON
- mp := &AttributeSJsonCfg{
- Enabled: utils.BoolPointer(true),
- Stats_conns: &[]string{"*birpc"},
- Resources_conns: &[]string{"*birpc"},
- Admins_conns: &[]string{"*birpc"},
- Indexed_selects: utils.BoolPointer(true),
- String_indexed_fields: &[]string{"*req.index1"},
- Prefix_indexed_fields: &[]string{"*req.index2"},
- Suffix_indexed_fields: &[]string{"*req.index3"},
- Nested_fields: utils.BoolPointer(true),
- Process_runs: utils.IntPointer(2),
- Any_context: utils.BoolPointer(false),
- }
-
- expected := &AttributeSJsonCfg{
- Enabled: utils.BoolPointer(true),
- Stats_conns: &[]string{"*birpc"},
- Resources_conns: &[]string{"*birpc"},
- Admins_conns: &[]string{"*birpc"},
- Indexed_selects: utils.BoolPointer(true),
- String_indexed_fields: &[]string{"*req.index1"},
- Prefix_indexed_fields: &[]string{"*req.index2"},
- Suffix_indexed_fields: &[]string{"*req.index3"},
- Nested_fields: utils.BoolPointer(true),
- Process_runs: utils.IntPointer(2),
- Any_context: utils.BoolPointer(false),
- }
-
- if cfgSec, err := prepareSectionFromMap(section, mp); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(cfgSec, expected) {
- t.Errorf("Expected %v \n but received \n %v", utils.ToJSON(mp), utils.ToJSON(cfgSec))
- }
-}
-
-func TestPrepareChargerSSectionFromMap(t *testing.T) {
- section := ChargerSJSON
- mp := &ChargerSJsonCfg{
- Enabled: utils.BoolPointer(true),
- Indexed_selects: utils.BoolPointer(true),
- String_indexed_fields: &[]string{"*req.index1"},
- Prefix_indexed_fields: &[]string{"*req.index2"},
- Suffix_indexed_fields: &[]string{"*req.index3"},
- Attributes_conns: &[]string{"*birpc"},
- Nested_fields: utils.BoolPointer(true),
- }
-
- expected := &ChargerSJsonCfg{
- Enabled: utils.BoolPointer(true),
- Indexed_selects: utils.BoolPointer(true),
- String_indexed_fields: &[]string{"*req.index1"},
- Prefix_indexed_fields: &[]string{"*req.index2"},
- Suffix_indexed_fields: &[]string{"*req.index3"},
- Attributes_conns: &[]string{"*birpc"},
- Nested_fields: utils.BoolPointer(true),
- }
-
- if cfgSec, err := prepareSectionFromMap(section, mp); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(cfgSec, expected) {
- t.Errorf("Expected %v \n but received \n %v", utils.ToJSON(mp), utils.ToJSON(cfgSec))
- }
-}
-
-func TestPrepareResourceSSectionFromMap(t *testing.T) {
- section := ResourceSJSON
- mp := &ResourceSJsonCfg{
- Enabled: utils.BoolPointer(true),
- Indexed_selects: utils.BoolPointer(true),
- Thresholds_conns: &[]string{"*birpc"},
- Store_interval: utils.StringPointer("1s"),
- String_indexed_fields: &[]string{"*req.index1"},
- Prefix_indexed_fields: &[]string{"*req.index2"},
- Suffix_indexed_fields: &[]string{"*req.index3"},
- Nested_fields: utils.BoolPointer(true),
- }
-
- expected := &ResourceSJsonCfg{
- Enabled: utils.BoolPointer(true),
- Indexed_selects: utils.BoolPointer(true),
- Thresholds_conns: &[]string{"*birpc"},
- Store_interval: utils.StringPointer("1s"),
- String_indexed_fields: &[]string{"*req.index1"},
- Prefix_indexed_fields: &[]string{"*req.index2"},
- Suffix_indexed_fields: &[]string{"*req.index3"},
- Nested_fields: utils.BoolPointer(true),
- }
-
- if cfgSec, err := prepareSectionFromMap(section, mp); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(cfgSec, expected) {
- t.Errorf("Expected %v \n but received \n %v", utils.ToJSON(mp), utils.ToJSON(cfgSec))
- }
-}
-
-func TestPrepareStatSSectionFromMap(t *testing.T) {
- section := StatSJSON
- mp := &StatServJsonCfg{
- Enabled: utils.BoolPointer(true),
- Indexed_selects: utils.BoolPointer(true),
- Thresholds_conns: &[]string{"*birpc"},
- Store_uncompressed_limit: utils.IntPointer(2),
- Store_interval: utils.StringPointer("1s"),
- String_indexed_fields: &[]string{"*req.index1"},
- Prefix_indexed_fields: &[]string{"*req.index2"},
- Suffix_indexed_fields: &[]string{"*req.index3"},
- Nested_fields: utils.BoolPointer(true),
- }
-
- expected := &StatServJsonCfg{
- Enabled: utils.BoolPointer(true),
- Indexed_selects: utils.BoolPointer(true),
- Thresholds_conns: &[]string{"*birpc"},
- Store_uncompressed_limit: utils.IntPointer(2),
- Store_interval: utils.StringPointer("1s"),
- String_indexed_fields: &[]string{"*req.index1"},
- Prefix_indexed_fields: &[]string{"*req.index2"},
- Suffix_indexed_fields: &[]string{"*req.index3"},
- Nested_fields: utils.BoolPointer(true),
- }
-
- if cfgSec, err := prepareSectionFromMap(section, mp); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(cfgSec, expected) {
- t.Errorf("Expected %v \n but received \n %v", utils.ToJSON(mp), utils.ToJSON(cfgSec))
- }
-}
-
-func TestPrepareThresholdSSectionFromMap(t *testing.T) {
- section := ThresholdSJSON
- mp := &ThresholdSJsonCfg{
- Enabled: utils.BoolPointer(true),
- Indexed_selects: utils.BoolPointer(true),
- Store_interval: utils.StringPointer("1s"),
- String_indexed_fields: &[]string{"*req.index1"},
- Prefix_indexed_fields: &[]string{"*req.index2"},
- Suffix_indexed_fields: &[]string{"*req.index3"},
- Nested_fields: utils.BoolPointer(true),
- }
-
- expected := &ThresholdSJsonCfg{
- Enabled: utils.BoolPointer(true),
- Indexed_selects: utils.BoolPointer(true),
- Store_interval: utils.StringPointer("1s"),
- String_indexed_fields: &[]string{"*req.index1"},
- Prefix_indexed_fields: &[]string{"*req.index2"},
- Suffix_indexed_fields: &[]string{"*req.index3"},
- Nested_fields: utils.BoolPointer(true),
- }
-
- if cfgSec, err := prepareSectionFromMap(section, mp); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(cfgSec, expected) {
- t.Errorf("Expected %v \n but received \n %v", utils.ToJSON(mp), utils.ToJSON(cfgSec))
- }
-}
-
-func TestPrepareRouteSSectionFromMap(t *testing.T) {
- section := RouteSJSON
- mp := &RouteSJsonCfg{
- Enabled: utils.BoolPointer(true),
- Indexed_selects: utils.BoolPointer(true),
- String_indexed_fields: &[]string{"*req.index1"},
- Prefix_indexed_fields: &[]string{"*req.index2"},
- Suffix_indexed_fields: &[]string{"*req.index3"},
- Nested_fields: utils.BoolPointer(true),
- Attributes_conns: &[]string{"*birpc"},
- Resources_conns: &[]string{"*birpc"},
- Stats_conns: &[]string{"*birpc"},
- Default_ratio: utils.IntPointer(2),
- }
-
- expected := &RouteSJsonCfg{
- Enabled: utils.BoolPointer(true),
- Indexed_selects: utils.BoolPointer(true),
- String_indexed_fields: &[]string{"*req.index1"},
- Prefix_indexed_fields: &[]string{"*req.index2"},
- Suffix_indexed_fields: &[]string{"*req.index3"},
- Nested_fields: utils.BoolPointer(true),
- Attributes_conns: &[]string{"*birpc"},
- Resources_conns: &[]string{"*birpc"},
- Stats_conns: &[]string{"*birpc"},
- Default_ratio: utils.IntPointer(2),
- }
-
- if cfgSec, err := prepareSectionFromMap(section, mp); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(cfgSec, expected) {
- t.Errorf("Expected %v \n but received \n %v", utils.ToJSON(mp), utils.ToJSON(cfgSec))
- }
-}
-
-func TestPrepareSureTaxSectionFromMap(t *testing.T) {
- section := SureTaxJSON
- mp := &SureTaxJsonCfg{
- Url: utils.StringPointer("sure_tax_url"),
- Client_number: utils.StringPointer("client_number"),
- Validation_key: utils.StringPointer("validation_key"),
- Business_unit: utils.StringPointer("business_unit"),
- Timezone: utils.StringPointer("UTC"),
- Include_local_cost: utils.BoolPointer(false),
- Return_file_code: utils.StringPointer("return_file_code"),
- Response_group: utils.StringPointer("response_group"),
- Response_type: utils.StringPointer("response_type"),
- Regulatory_code: utils.StringPointer("regulatory_code"),
- Client_tracking: utils.StringPointer("client_tracking"),
- Customer_number: utils.StringPointer("custom_number"),
- Orig_number: utils.StringPointer("orig_number"),
- }
-
- expected := &SureTaxJsonCfg{
- Url: utils.StringPointer("sure_tax_url"),
- Client_number: utils.StringPointer("client_number"),
- Validation_key: utils.StringPointer("validation_key"),
- Business_unit: utils.StringPointer("business_unit"),
- Timezone: utils.StringPointer("UTC"),
- Include_local_cost: utils.BoolPointer(false),
- Return_file_code: utils.StringPointer("return_file_code"),
- Response_group: utils.StringPointer("response_group"),
- Response_type: utils.StringPointer("response_type"),
- Regulatory_code: utils.StringPointer("regulatory_code"),
- Client_tracking: utils.StringPointer("client_tracking"),
- Customer_number: utils.StringPointer("custom_number"),
- Orig_number: utils.StringPointer("orig_number"),
- }
-
- if cfgSec, err := prepareSectionFromMap(section, mp); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(cfgSec, expected) {
- t.Errorf("Expected %v \n but received \n %v", utils.ToJSON(mp), utils.ToJSON(cfgSec))
- }
-}
-
-func TestPrepareDispatcherSSectionFromMap(t *testing.T) {
- section := DispatcherSJSON
- mp := &DispatcherSJsonCfg{
- Enabled: utils.BoolPointer(true),
- Indexed_selects: utils.BoolPointer(true),
- String_indexed_fields: &[]string{"*req.index1"},
- Prefix_indexed_fields: &[]string{"*req.index2"},
- Suffix_indexed_fields: &[]string{"*req.index3"},
- Nested_fields: utils.BoolPointer(true),
- Attributes_conns: &[]string{"*birpc"},
- Any_subsystem: utils.BoolPointer(false),
- }
-
- expected := &DispatcherSJsonCfg{
- Enabled: utils.BoolPointer(true),
- Indexed_selects: utils.BoolPointer(true),
- String_indexed_fields: &[]string{"*req.index1"},
- Prefix_indexed_fields: &[]string{"*req.index2"},
- Suffix_indexed_fields: &[]string{"*req.index3"},
- Nested_fields: utils.BoolPointer(true),
- Attributes_conns: &[]string{"*birpc"},
- Any_subsystem: utils.BoolPointer(false),
- }
-
- if cfgSec, err := prepareSectionFromMap(section, mp); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(cfgSec, expected) {
- t.Errorf("Expected %v \n but received \n %v", utils.ToJSON(mp), utils.ToJSON(cfgSec))
- }
-}
-
-func TestPrepareRegistrarCSectionFromMap(t *testing.T) {
- section := RegistrarCJSON
- mp := &RegistrarCJsonCfgs{
- RPC: &RegistrarCJsonCfg{
- Enabled: utils.BoolPointer(false),
- },
- Dispatcher: &RegistrarCJsonCfg{
- Enabled: utils.BoolPointer(false),
- },
- }
-
- expected := &RegistrarCJsonCfgs{
- RPC: &RegistrarCJsonCfg{
- Enabled: utils.BoolPointer(false),
- },
- Dispatcher: &RegistrarCJsonCfg{
- Enabled: utils.BoolPointer(false),
- },
- }
-
- if cfgSec, err := prepareSectionFromMap(section, mp); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(cfgSec, expected) {
- t.Errorf("Expected %v \n but received \n %v", utils.ToJSON(mp), utils.ToJSON(cfgSec))
- }
-}
-
-func TestPrepareLoaderSectionFromMap(t *testing.T) {
- section := LoaderJSON
- mp := &LoaderCfgJson{
- Tpid: utils.StringPointer("tpid"),
- Data_path: utils.StringPointer("data_path"),
- Disable_reverse: utils.BoolPointer(true),
- Field_separator: utils.StringPointer("fld_separator"),
- Caches_conns: &[]string{"*birpc"},
- Actions_conns: &[]string{"*birpc"},
- }
-
- expected := &LoaderCfgJson{
- Tpid: utils.StringPointer("tpid"),
- Data_path: utils.StringPointer("data_path"),
- Disable_reverse: utils.BoolPointer(true),
- Field_separator: utils.StringPointer("fld_separator"),
- Caches_conns: &[]string{"*birpc"},
- Actions_conns: &[]string{"*birpc"},
- }
-
- if cfgSec, err := prepareSectionFromMap(section, mp); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(cfgSec, expected) {
- t.Errorf("Expected %v \n but received \n %v", utils.ToJSON(mp), utils.ToJSON(cfgSec))
- }
-}