Remove global CGRConfig used by tests

This commit is contained in:
ionutboangiu
2024-07-10 09:21:05 +03:00
committed by Dan Christian Bogos
parent 962000656b
commit 747bfd9967
2 changed files with 23 additions and 25 deletions

View File

@@ -32,8 +32,6 @@ import (
"github.com/cgrates/cgrates/utils"
)
var cfg *CGRConfig
func TestNewDefaultConfigError(t *testing.T) {
if _, err := newCGRConfig([]byte(CGRATES_CFG_JSON)); err != nil {
t.Error(err)
@@ -61,7 +59,7 @@ func TestNewCgrConfigFromBytesDecodeError(t *testing.T) {
}
func TestCgrCfgConfigSharing(t *testing.T) {
cfg = NewDefaultCGRConfig()
cfg := NewDefaultCGRConfig()
SetCgrConfig(cfg)
cfgReturn := CgrConfig()
if !reflect.DeepEqual(cfgReturn, cfg) {
@@ -5533,7 +5531,7 @@ func TestLoadConfigFromReaderError(t *testing.T) {
cgrCfg := NewDefaultCGRConfig()
if err == nil || err.Error() != expectedErrFile {
t.Errorf("Expected %+v, receivewd %+v", expectedErrFile, err)
} else if err := cgrCfg.loadConfigFromReader(file, []func(*CgrJsonCfg) error{cfg.loadFromJSONCfg}, true); err == nil || err.Error() != expectedErr {
} else if err := cgrCfg.loadConfigFromReader(file, []func(*CgrJsonCfg) error{cgrCfg.loadFromJSONCfg}, true); err == nil || err.Error() != expectedErr {
t.Errorf("Expected %+v, received %+v", expectedErr, err)
}
}
@@ -5547,7 +5545,7 @@ func TestLoadConfigFromReaderLoadFunctionsError(t *testing.T) {
expected := `json: cannot unmarshal number into Go struct field DbJsonCfg.Db_type of type string`
cgrCfg := NewDefaultCGRConfig()
if err := cgrCfg.loadConfigFromReader(strings.NewReader(cfgJSONStr),
[]func(jsonCfg *CgrJsonCfg) error{cfg.loadDataDBCfg},
[]func(jsonCfg *CgrJsonCfg) error{cgrCfg.loadDataDBCfg},
true); err == nil || err.Error() != expected {
t.Errorf("Expected %+v, received %+v", expected, err)
}

View File

@@ -139,7 +139,7 @@ func TestConfigSanityCDRServer(t *testing.T) {
}
func TestConfigSanityLoaders(t *testing.T) {
cfg = NewDefaultCGRConfig()
cfg := NewDefaultCGRConfig()
cfg.loaderCfg = LoaderSCfgs{
&LoaderSCfg{
Enabled: true,
@@ -249,7 +249,7 @@ func TestConfigSanityLoaders(t *testing.T) {
}
func TestConfigSanitySessionS(t *testing.T) {
cfg = NewDefaultCGRConfig()
cfg := NewDefaultCGRConfig()
cfg.sessionSCfg = &SessionSCfg{
Enabled: true,
TerminateAttempts: 0,
@@ -384,7 +384,7 @@ func TestConfigSanitySessionS(t *testing.T) {
}
func TestConfigSanityFreeSWITCHAgent(t *testing.T) {
cfg = NewDefaultCGRConfig()
cfg := NewDefaultCGRConfig()
cfg.fsAgentCfg = &FsAgentCfg{
Enabled: true,
}
@@ -410,7 +410,7 @@ func TestConfigSanityFreeSWITCHAgent(t *testing.T) {
}
func TestConfigSanityKamailioAgent(t *testing.T) {
cfg = NewDefaultCGRConfig()
cfg := NewDefaultCGRConfig()
cfg.kamAgentCfg = &KamAgentCfg{
Enabled: true,
}
@@ -432,7 +432,7 @@ func TestConfigSanityKamailioAgent(t *testing.T) {
}
func TestConfigSanityAsteriskAgent(t *testing.T) {
cfg = NewDefaultCGRConfig()
cfg := NewDefaultCGRConfig()
cfg.asteriskAgentCfg = &AsteriskAgentCfg{
Enabled: true,
}
@@ -454,7 +454,7 @@ func TestConfigSanityAsteriskAgent(t *testing.T) {
}
func TestConfigSanityDAgent(t *testing.T) {
cfg = NewDefaultCGRConfig()
cfg := NewDefaultCGRConfig()
cfg.templates = FcTemplates{
utils.MetaEEs: {
@@ -589,7 +589,7 @@ func TestConfigSanityDAgent(t *testing.T) {
}
func TestConfigSanityRadiusAgent(t *testing.T) {
cfg = NewDefaultCGRConfig()
cfg := NewDefaultCGRConfig()
cfg.radiusAgentCfg = &RadiusAgentCfg{
Enabled: true,
RequestProcessors: []*RequestProcessor{
@@ -709,7 +709,7 @@ func TestConfigSanityRadiusAgent(t *testing.T) {
}
func TestConfigSanityDNSAgent(t *testing.T) {
cfg = NewDefaultCGRConfig()
cfg := NewDefaultCGRConfig()
cfg.dnsAgentCfg = &DNSAgentCfg{
Enabled: true,
RequestProcessors: []*RequestProcessor{
@@ -1090,7 +1090,7 @@ func TestConfigSanityChargerS(t *testing.T) {
}
func TestConfigSanityResourceLimiter(t *testing.T) {
cfg = NewDefaultCGRConfig()
cfg := NewDefaultCGRConfig()
cfg.resourceSCfg = &ResourceSConfig{
Enabled: true,
ThresholdSConns: []string{utils.MetaInternal},
@@ -1107,7 +1107,7 @@ func TestConfigSanityResourceLimiter(t *testing.T) {
}
func TestConfigSanityStatS(t *testing.T) {
cfg = NewDefaultCGRConfig()
cfg := NewDefaultCGRConfig()
cfg.statsCfg = &StatSCfg{
Enabled: true,
ThresholdSConns: []string{utils.MetaInternal},
@@ -1124,7 +1124,7 @@ func TestConfigSanityStatS(t *testing.T) {
}
func TestConfigSanityRouteS(t *testing.T) {
cfg = NewDefaultCGRConfig()
cfg := NewDefaultCGRConfig()
cfg.routeSCfg.Enabled = true
cfg.routeSCfg.ResourceSConns = []string{utils.MetaInternal}
@@ -1178,7 +1178,7 @@ func TestConfigSanityRouteS(t *testing.T) {
}
func TestConfigSanityScheduler(t *testing.T) {
cfg = NewDefaultCGRConfig()
cfg := NewDefaultCGRConfig()
cfg.schedulerCfg.Enabled = true
cfg.schedulerCfg.CDRsConns = []string{utils.MetaInternal}
@@ -1225,7 +1225,7 @@ func TestConfigSanityScheduler(t *testing.T) {
}
func TestConfigSanityEventReader(t *testing.T) {
cfg = NewDefaultCGRConfig()
cfg := NewDefaultCGRConfig()
cfg.ersCfg = &ERsCfg{
Enabled: true,
SessionSConns: []string{"unexistedConn"},
@@ -1693,7 +1693,7 @@ func TestConfigSanityRegistrarCDispatcher(t *testing.T) {
}
func TestConfigSanityStorDB(t *testing.T) {
cfg = NewDefaultCGRConfig()
cfg := NewDefaultCGRConfig()
cfg.storDbCfg = &StorDbCfg{
Type: utils.MetaPostgres,
Opts: &StorDBOpts{
@@ -1740,7 +1740,7 @@ func TestConfigSanityAnalyzer(t *testing.T) {
}
func TestConfigSanityDataDB(t *testing.T) {
cfg = NewDefaultCGRConfig()
cfg := NewDefaultCGRConfig()
cfg.dataDbCfg.Type = utils.MetaInternal
cfg.cacheCfg = &CacheCfg{
@@ -1841,7 +1841,7 @@ func TestConfigSanityDataDB(t *testing.T) {
}
func TestConfigSanityAPIer(t *testing.T) {
cfg = NewDefaultCGRConfig()
cfg := NewDefaultCGRConfig()
cfg.apier.AttributeSConns = []string{utils.MetaInternal}
if err := cfg.checkConfigSanity(); err == nil || err.Error() != "<AttributeS> not enabled but requested by <APIerSv1> component" {
@@ -1867,7 +1867,7 @@ func TestConfigSanityAPIer(t *testing.T) {
}
func TestConfigSanityDispatcher(t *testing.T) {
cfg = NewDefaultCGRConfig()
cfg := NewDefaultCGRConfig()
cfg.dispatcherSCfg = &DispatcherSCfg{
Enabled: true,
AttributeSConns: []string{utils.MetaInternal},
@@ -1883,7 +1883,7 @@ func TestConfigSanityDispatcher(t *testing.T) {
}
func TestConfigSanityCacheS(t *testing.T) {
cfg = NewDefaultCGRConfig()
cfg := NewDefaultCGRConfig()
cfg.cacheCfg.Partitions = map[string]*CacheParamCfg{"wrong_partition_name": {Limit: 10}}
if err := cfg.checkConfigSanity(); err == nil || err.Error() != "<CacheS> partition <wrong_partition_name> not defined" {
@@ -1897,7 +1897,7 @@ func TestConfigSanityCacheS(t *testing.T) {
}
func TestConfigSanityFilterS(t *testing.T) {
cfg = NewDefaultCGRConfig()
cfg := NewDefaultCGRConfig()
cfg.filterSCfg.StatSConns = []string{utils.MetaInternal}
if err := cfg.checkConfigSanity(); err == nil || err.Error() != "<Stats> not enabled but requested by <FilterS> component" {
@@ -2003,7 +2003,7 @@ func TestCheckConfigSanity(t *testing.T) {
}
func TestConfigSanityErs(t *testing.T) {
cfg = NewDefaultCGRConfig()
cfg := NewDefaultCGRConfig()
cfg.ersCfg.Enabled = true
cfg.ersCfg.SessionSConns = []string{}