mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Merge pull request #1893 from adragusin/master
updated ConfigSanity tests
This commit is contained in:
@@ -44,6 +44,7 @@ var (
|
||||
cgrEngineFlags = flag.NewFlagSet("cgr-engine", flag.ContinueOnError)
|
||||
cfgPath = cgrEngineFlags.String("config_path", utils.CONFIG_PATH, "Configuration directory path.")
|
||||
version = cgrEngineFlags.Bool("version", false, "Prints the application version.")
|
||||
checkConfig = cgrEngineFlags.Bool("check_config", false, "Verify the config without starting the engine")
|
||||
pidFile = cgrEngineFlags.String("pid", "", "Write pid file")
|
||||
httpPprofPath = cgrEngineFlags.String("httprof_path", "", "http address used for program profiling")
|
||||
cpuProfDir = cgrEngineFlags.String("cpuprof_dir", "", "write cpu profile to files")
|
||||
@@ -367,6 +368,12 @@ func main() {
|
||||
if *nodeID != utils.EmptyString {
|
||||
cfg.GeneralCfg().NodeID = *nodeID
|
||||
}
|
||||
if *checkConfig {
|
||||
if err := cfg.CheckConfigSanity(); err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
return
|
||||
}
|
||||
config.SetCgrConfig(cfg) // Share the config object
|
||||
|
||||
// init syslog
|
||||
|
||||
@@ -26,6 +26,11 @@ import (
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
)
|
||||
|
||||
// Exported in cgr-engine
|
||||
func (cfg *CGRConfig) CheckConfigSanity() error {
|
||||
return cfg.checkConfigSanity()
|
||||
}
|
||||
|
||||
func (cfg *CGRConfig) checkConfigSanity() error {
|
||||
// Rater checks
|
||||
if cfg.ralsCfg.Enabled {
|
||||
@@ -298,7 +303,7 @@ func (cfg *CGRConfig) checkConfigSanity() error {
|
||||
return fmt.Errorf("<%s> not enabled but requested by <%s> HTTPAgent Template.", utils.SessionS, httpAgentCfg.ID)
|
||||
}
|
||||
if _, has := cfg.rpcConns[connID]; !has && !strings.HasPrefix(connID, utils.MetaInternal) {
|
||||
return fmt.Errorf("HTTPAgent Templae with ID <%s> has connection with id: <%s> not defined", httpAgentCfg.ID, connID)
|
||||
return fmt.Errorf("<%s> Template with ID <%s> has connection with id: <%s> not defined", utils.HTTPAgent, httpAgentCfg.ID, connID)
|
||||
}
|
||||
}
|
||||
if !utils.SliceHasMember([]string{utils.MetaUrl, utils.MetaXml}, httpAgentCfg.RequestPayload) {
|
||||
@@ -475,7 +480,7 @@ func (cfg *CGRConfig) checkConfigSanity() error {
|
||||
if cfg.dispatcherSCfg.Enabled {
|
||||
for _, connID := range cfg.dispatcherSCfg.AttributeSConns {
|
||||
if strings.HasPrefix(connID, utils.MetaInternal) && !cfg.attributeSCfg.Enabled {
|
||||
return fmt.Errorf("<%s> not enabled but requested by <%s> component", utils.AttributeS, utils.DispatcherS)
|
||||
return fmt.Errorf("<%s> not enabled but requested by <%s> component.", utils.AttributeS, utils.DispatcherS)
|
||||
}
|
||||
if _, has := cfg.rpcConns[connID]; !has && !strings.HasPrefix(connID, utils.MetaInternal) {
|
||||
return fmt.Errorf("<%s> Connection with id: <%s> not defined", utils.DispatcherS, connID)
|
||||
|
||||
@@ -34,13 +34,22 @@ func TestConfigSanityRater(t *testing.T) {
|
||||
if err := cfg.checkConfigSanity(); err == nil || err.Error() != expected {
|
||||
t.Errorf("Expecting: %+q received: %+q", expected, err)
|
||||
}
|
||||
cfg.statsCfg.Enabled = true
|
||||
|
||||
cfg.ralsCfg.StatSConns = []string{"test"}
|
||||
expected = "<RALs> Connection with id: <test> not defined"
|
||||
if err := cfg.checkConfigSanity(); err == nil || err.Error() != expected {
|
||||
t.Errorf("Expecting: %+q received: %+q", expected, err)
|
||||
}
|
||||
cfg.ralsCfg.StatSConns = []string{}
|
||||
cfg.ralsCfg.ThresholdSConns = []string{utils.MetaInternal}
|
||||
expected = "<ThresholdS> not enabled but requested by <RALs> component."
|
||||
if err := cfg.checkConfigSanity(); err == nil || err.Error() != expected {
|
||||
t.Errorf("Expecting: %+q received: %+q", expected, err)
|
||||
}
|
||||
cfg.ralsCfg.ThresholdSConns = []string{"test"}
|
||||
expected = "<RALs> Connection with id: <test> not defined"
|
||||
if err := cfg.checkConfigSanity(); err == nil || err.Error() != expected {
|
||||
t.Errorf("Expecting: %+q received: %+q", expected, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestConfigSanityCDRServer(t *testing.T) {
|
||||
@@ -54,7 +63,12 @@ func TestConfigSanityCDRServer(t *testing.T) {
|
||||
if err := cfg.checkConfigSanity(); err == nil || err.Error() != expected {
|
||||
t.Errorf("Expecting: %+q received: %+q", expected, err)
|
||||
}
|
||||
cfg.chargerSCfg.Enabled = true
|
||||
cfg.cdrsCfg.ChargerSConns = []string{"test"}
|
||||
expected = "<CDRs> Connection with id: <test> not defined"
|
||||
if err := cfg.checkConfigSanity(); err == nil || err.Error() != expected {
|
||||
t.Errorf("Expecting: %+q received: %+q", expected, err)
|
||||
}
|
||||
cfg.cdrsCfg.ChargerSConns = []string{}
|
||||
|
||||
cfg.cdrsCfg.RaterConns = []string{utils.MetaInternal}
|
||||
|
||||
@@ -62,21 +76,36 @@ func TestConfigSanityCDRServer(t *testing.T) {
|
||||
if err := cfg.checkConfigSanity(); err == nil || err.Error() != expected {
|
||||
t.Errorf("Expecting: %+q received: %+q", expected, err)
|
||||
}
|
||||
cfg.ralsCfg.Enabled = true
|
||||
cfg.cdrsCfg.RaterConns = []string{"test"}
|
||||
expected = "<CDRs> Connection with id: <test> not defined"
|
||||
if err := cfg.checkConfigSanity(); err == nil || err.Error() != expected {
|
||||
t.Errorf("Expecting: %+q received: %+q", expected, err)
|
||||
}
|
||||
cfg.cdrsCfg.RaterConns = []string{}
|
||||
|
||||
cfg.cdrsCfg.AttributeSConns = []string{utils.MetaInternal}
|
||||
expected = "<AttributeS> not enabled but requested by <CDRs> component."
|
||||
if err := cfg.checkConfigSanity(); err == nil || err.Error() != expected {
|
||||
t.Errorf("Expecting: %+q received: %+q", expected, err)
|
||||
}
|
||||
cfg.attributeSCfg.Enabled = true
|
||||
cfg.cdrsCfg.AttributeSConns = []string{"test"}
|
||||
expected = "<CDRs> Connection with id: <test> not defined"
|
||||
if err := cfg.checkConfigSanity(); err == nil || err.Error() != expected {
|
||||
t.Errorf("Expecting: %+q received: %+q", expected, err)
|
||||
}
|
||||
cfg.cdrsCfg.AttributeSConns = []string{}
|
||||
|
||||
cfg.cdrsCfg.StatSConns = []string{utils.MetaInternal}
|
||||
expected = "<StatS> not enabled but requested by <CDRs> component."
|
||||
if err := cfg.checkConfigSanity(); err == nil || err.Error() != expected {
|
||||
t.Errorf("Expecting: %+q received: %+q", expected, err)
|
||||
}
|
||||
cfg.statsCfg.Enabled = true
|
||||
cfg.cdrsCfg.StatSConns = []string{"test"}
|
||||
expected = "<CDRs> Connection with id: <test> not defined"
|
||||
if err := cfg.checkConfigSanity(); err == nil || err.Error() != expected {
|
||||
t.Errorf("Expecting: %+q received: %+q", expected, err)
|
||||
}
|
||||
cfg.cdrsCfg.StatSConns = []string{}
|
||||
|
||||
cfg.cdrsCfg.OnlineCDRExports = []string{"stringy"}
|
||||
cfg.CdreProfiles = map[string]*CdreCfg{"stringx": &CdreCfg{}}
|
||||
@@ -84,7 +113,12 @@ func TestConfigSanityCDRServer(t *testing.T) {
|
||||
if err := cfg.checkConfigSanity(); err == nil || err.Error() != expected {
|
||||
t.Errorf("Expecting: %+q received: %+q", expected, err)
|
||||
}
|
||||
cfg.cdrsCfg.OnlineCDRExports = []string{"stringx"}
|
||||
cfg.cdrsCfg.ThresholdSConns = []string{"test"}
|
||||
expected = "<CDRs> Connection with id: <test> not defined"
|
||||
if err := cfg.checkConfigSanity(); err == nil || err.Error() != expected {
|
||||
t.Errorf("Expecting: %+q received: %+q", expected, err)
|
||||
}
|
||||
cfg.cdrsCfg.ThresholdSConns = []string{}
|
||||
|
||||
cfg.cdrsCfg.ThresholdSConns = []string{utils.MetaInternal}
|
||||
expected = "<ThresholdS> not enabled but requested by <CDRs> component."
|
||||
@@ -169,6 +203,12 @@ func TestConfigSanitySessionS(t *testing.T) {
|
||||
if err := cfg.checkConfigSanity(); err == nil || err.Error() != expected {
|
||||
t.Errorf("Expecting: %+q received: %+q", expected, err)
|
||||
}
|
||||
cfg.sessionSCfg.ChargerSConns = []string{"test"}
|
||||
expected = "<SessionS> Connection with id: <test> not defined"
|
||||
if err := cfg.checkConfigSanity(); err == nil || err.Error() != expected {
|
||||
t.Errorf("Expecting: %+q received: %+q", expected, err)
|
||||
}
|
||||
cfg.sessionSCfg.ChargerSConns = []string{}
|
||||
cfg.chargerSCfg.Enabled = true
|
||||
|
||||
cfg.sessionSCfg.RALsConns = []string{utils.MetaInternal}
|
||||
@@ -176,6 +216,12 @@ func TestConfigSanitySessionS(t *testing.T) {
|
||||
if err := cfg.checkConfigSanity(); err == nil || err.Error() != expected {
|
||||
t.Errorf("Expecting: %+q received: %+q", expected, err)
|
||||
}
|
||||
cfg.sessionSCfg.RALsConns = []string{"test"}
|
||||
expected = "<SessionS> Connection with id: <test> not defined"
|
||||
if err := cfg.checkConfigSanity(); err == nil || err.Error() != expected {
|
||||
t.Errorf("Expecting: %+q received: %+q", expected, err)
|
||||
}
|
||||
cfg.sessionSCfg.RALsConns = []string{}
|
||||
cfg.ralsCfg.Enabled = true
|
||||
|
||||
cfg.sessionSCfg.ResSConns = []string{utils.MetaInternal}
|
||||
@@ -183,6 +229,12 @@ func TestConfigSanitySessionS(t *testing.T) {
|
||||
if err := cfg.checkConfigSanity(); err == nil || err.Error() != expected {
|
||||
t.Errorf("Expecting: %+q received: %+q", expected, err)
|
||||
}
|
||||
cfg.sessionSCfg.ResSConns = []string{"test"}
|
||||
expected = "<SessionS> Connection with id: <test> not defined"
|
||||
if err := cfg.checkConfigSanity(); err == nil || err.Error() != expected {
|
||||
t.Errorf("Expecting: %+q received: %+q", expected, err)
|
||||
}
|
||||
cfg.sessionSCfg.ResSConns = []string{}
|
||||
cfg.resourceSCfg.Enabled = true
|
||||
|
||||
cfg.sessionSCfg.ThreshSConns = []string{utils.MetaInternal}
|
||||
@@ -190,6 +242,12 @@ func TestConfigSanitySessionS(t *testing.T) {
|
||||
if err := cfg.checkConfigSanity(); err == nil || err.Error() != expected {
|
||||
t.Errorf("Expecting: %+q received: %+q", expected, err)
|
||||
}
|
||||
cfg.sessionSCfg.ThreshSConns = []string{"test"}
|
||||
expected = "<SessionS> Connection with id: <test> not defined"
|
||||
if err := cfg.checkConfigSanity(); err == nil || err.Error() != expected {
|
||||
t.Errorf("Expecting: %+q received: %+q", expected, err)
|
||||
}
|
||||
cfg.sessionSCfg.ThreshSConns = []string{}
|
||||
cfg.thresholdSCfg.Enabled = true
|
||||
|
||||
cfg.sessionSCfg.StatSConns = []string{utils.MetaInternal}
|
||||
@@ -197,6 +255,12 @@ func TestConfigSanitySessionS(t *testing.T) {
|
||||
if err := cfg.checkConfigSanity(); err == nil || err.Error() != expected {
|
||||
t.Errorf("Expecting: %+q received: %+q", expected, err)
|
||||
}
|
||||
cfg.sessionSCfg.StatSConns = []string{"test"}
|
||||
expected = "<SessionS> Connection with id: <test> not defined"
|
||||
if err := cfg.checkConfigSanity(); err == nil || err.Error() != expected {
|
||||
t.Errorf("Expecting: %+q received: %+q", expected, err)
|
||||
}
|
||||
cfg.sessionSCfg.StatSConns = []string{}
|
||||
cfg.statsCfg.Enabled = true
|
||||
|
||||
cfg.sessionSCfg.SupplSConns = []string{utils.MetaInternal}
|
||||
@@ -204,6 +268,12 @@ func TestConfigSanitySessionS(t *testing.T) {
|
||||
if err := cfg.checkConfigSanity(); err == nil || err.Error() != expected {
|
||||
t.Errorf("Expecting: %+q received: %+q", expected, err)
|
||||
}
|
||||
cfg.sessionSCfg.SupplSConns = []string{"test"}
|
||||
expected = "<SessionS> Connection with id: <test> not defined"
|
||||
if err := cfg.checkConfigSanity(); err == nil || err.Error() != expected {
|
||||
t.Errorf("Expecting: %+q received: %+q", expected, err)
|
||||
}
|
||||
cfg.sessionSCfg.SupplSConns = []string{}
|
||||
cfg.supplierSCfg.Enabled = true
|
||||
|
||||
cfg.sessionSCfg.AttrSConns = []string{utils.MetaInternal}
|
||||
@@ -211,6 +281,12 @@ func TestConfigSanitySessionS(t *testing.T) {
|
||||
if err := cfg.checkConfigSanity(); err == nil || err.Error() != expected {
|
||||
t.Errorf("Expecting: %+q received: %+q", expected, err)
|
||||
}
|
||||
cfg.sessionSCfg.AttrSConns = []string{"test"}
|
||||
expected = "<SessionS> Connection with id: <test> not defined"
|
||||
if err := cfg.checkConfigSanity(); err == nil || err.Error() != expected {
|
||||
t.Errorf("Expecting: %+q received: %+q", expected, err)
|
||||
}
|
||||
cfg.sessionSCfg.AttrSConns = []string{}
|
||||
cfg.attributeSCfg.Enabled = true
|
||||
|
||||
cfg.sessionSCfg.CDRsConns = []string{utils.MetaInternal}
|
||||
@@ -218,14 +294,31 @@ func TestConfigSanitySessionS(t *testing.T) {
|
||||
if err := cfg.checkConfigSanity(); err == nil || err.Error() != expected {
|
||||
t.Errorf("Expecting: %+q received: %+q", expected, err)
|
||||
}
|
||||
cfg.sessionSCfg.CDRsConns = []string{"test"}
|
||||
expected = "<SessionS> Connection with id: <test> not defined"
|
||||
if err := cfg.checkConfigSanity(); err == nil || err.Error() != expected {
|
||||
t.Errorf("Expecting: %+q received: %+q", expected, err)
|
||||
}
|
||||
cfg.sessionSCfg.CDRsConns = []string{}
|
||||
cfg.cdrsCfg.Enabled = true
|
||||
cfg.sessionSCfg.ReplicationConns = []string{"test"}
|
||||
expected = "<SessionS> Connection with id: <test> not defined"
|
||||
if err := cfg.checkConfigSanity(); err == nil || err.Error() != expected {
|
||||
t.Errorf("Expecting: %+q received: %+q", expected, err)
|
||||
}
|
||||
cfg.sessionSCfg.ReplicationConns = []string{}
|
||||
|
||||
cfg.cacheCfg[utils.CacheClosedSessions].Limit = 0
|
||||
expected = "<CacheS> *closed_sessions needs to be != 0, received: 0"
|
||||
if err := cfg.checkConfigSanity(); err == nil || err.Error() != expected {
|
||||
t.Errorf("Expecting: %+q received: %+q", expected, err)
|
||||
}
|
||||
|
||||
cfg.cacheCfg[utils.CacheClosedSessions].Limit = 1
|
||||
expected = "<SessionS> The following protected field can't be altered by session: <CGRID>"
|
||||
cfg.sessionSCfg.AlterableFields = utils.NewStringSet([]string{utils.CGRID})
|
||||
if err := cfg.checkConfigSanity(); err == nil || err.Error() != expected {
|
||||
t.Errorf("Expecting: %+q received: %+q", expected, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestConfigSanityFreeSWITCHAgent(t *testing.T) {
|
||||
@@ -247,6 +340,11 @@ func TestConfigSanityFreeSWITCHAgent(t *testing.T) {
|
||||
if err := cfg.checkConfigSanity(); err == nil || err.Error() != expected {
|
||||
t.Errorf("Expecting: %+q received: %+q", expected, err)
|
||||
}
|
||||
cfg.fsAgentCfg.SessionSConns = []string{"test"}
|
||||
expected = "<FreeSWITCHAgent> Connection with id: <test> not defined"
|
||||
if err := cfg.checkConfigSanity(); err == nil || err.Error() != expected {
|
||||
t.Errorf("Expecting: %+q received: %+q", expected, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestConfigSanityKamailioAgent(t *testing.T) {
|
||||
@@ -264,6 +362,11 @@ func TestConfigSanityKamailioAgent(t *testing.T) {
|
||||
if err := cfg.checkConfigSanity(); err == nil || err.Error() != expected {
|
||||
t.Errorf("Expecting: %+q received: %+q", expected, err)
|
||||
}
|
||||
cfg.kamAgentCfg.SessionSConns = []string{"test"}
|
||||
expected = "<KamailioAgent> Connection with id: <test> not defined"
|
||||
if err := cfg.checkConfigSanity(); err == nil || err.Error() != expected {
|
||||
t.Errorf("Expecting: %+q received: %+q", expected, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestConfigSanityAsteriskAgent(t *testing.T) {
|
||||
@@ -281,6 +384,11 @@ func TestConfigSanityAsteriskAgent(t *testing.T) {
|
||||
if err := cfg.checkConfigSanity(); err == nil || err.Error() != expected {
|
||||
t.Errorf("Expecting: %+q received: %+q", expected, err)
|
||||
}
|
||||
cfg.asteriskAgentCfg.SessionSConns = []string{"test"}
|
||||
expected = "<AsteriskAgent> Connection with id: <test> not defined"
|
||||
if err := cfg.checkConfigSanity(); err == nil || err.Error() != expected {
|
||||
t.Errorf("Expecting: %+q received: %+q", expected, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestConfigSanityDAgent(t *testing.T) {
|
||||
@@ -298,6 +406,11 @@ func TestConfigSanityDAgent(t *testing.T) {
|
||||
if err := cfg.checkConfigSanity(); err == nil || err.Error() != expected {
|
||||
t.Errorf("Expecting: %+q received: %+q", expected, err)
|
||||
}
|
||||
cfg.diameterAgentCfg.SessionSConns = []string{"test"}
|
||||
expected = "<DiameterAgent> Connection with id: <test> not defined"
|
||||
if err := cfg.checkConfigSanity(); err == nil || err.Error() != expected {
|
||||
t.Errorf("Expecting: %+q received: %+q", expected, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestConfigSanityRadiusAgent(t *testing.T) {
|
||||
@@ -315,6 +428,11 @@ func TestConfigSanityRadiusAgent(t *testing.T) {
|
||||
if err := cfg.checkConfigSanity(); err == nil || err.Error() != expected {
|
||||
t.Errorf("Expecting: %+q received: %+q", expected, err)
|
||||
}
|
||||
cfg.radiusAgentCfg.SessionSConns = []string{"test"}
|
||||
expected = "<RadiusAgent> Connection with id: <test> not defined"
|
||||
if err := cfg.checkConfigSanity(); err == nil || err.Error() != expected {
|
||||
t.Errorf("Expecting: %+q received: %+q", expected, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestConfigSanityDNSAgent(t *testing.T) {
|
||||
@@ -332,6 +450,11 @@ func TestConfigSanityDNSAgent(t *testing.T) {
|
||||
if err := cfg.checkConfigSanity(); err == nil || err.Error() != expected {
|
||||
t.Errorf("Expecting: %+q received: %+q", expected, err)
|
||||
}
|
||||
cfg.dnsAgentCfg.SessionSConns = []string{"test"}
|
||||
expected = "<DNSAgent> Connection with id: <test> not defined"
|
||||
if err := cfg.checkConfigSanity(); err == nil || err.Error() != expected {
|
||||
t.Errorf("Expecting: %+q received: %+q", expected, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestConfigSanityHTTPAgent(t *testing.T) {
|
||||
@@ -347,6 +470,12 @@ func TestConfigSanityHTTPAgent(t *testing.T) {
|
||||
if err := cfg.checkConfigSanity(); err == nil || err.Error() != expected {
|
||||
t.Errorf("Expecting: %+q received: %+q", expected, err)
|
||||
}
|
||||
cfg.httpAgentCfg[0].SessionSConns = []string{"test"}
|
||||
expected = "<HTTPAgent> Template with ID <Test> has connection with id: <test> not defined"
|
||||
if err := cfg.checkConfigSanity(); err == nil || err.Error() != expected {
|
||||
t.Errorf("Expecting: %+q received: %+q", expected, err)
|
||||
}
|
||||
cfg.httpAgentCfg[0].SessionSConns = []string{}
|
||||
cfg.sessionSCfg.Enabled = true
|
||||
|
||||
cfg.httpAgentCfg = HttpAgentCfgs{
|
||||
@@ -383,8 +512,13 @@ func TestConfigSanityHTTPAgent(t *testing.T) {
|
||||
ProcessRuns: 1,
|
||||
Enabled: false,
|
||||
}
|
||||
|
||||
cfg.chargerSCfg.Enabled = true
|
||||
cfg.attributeSCfg.Enabled = false
|
||||
cfg.chargerSCfg.AttributeSConns = []string{utils.MetaInternal}
|
||||
expected = "<AttributeS> not enabled but requested by <ChargerS> component."
|
||||
if err := cfg.checkConfigSanity(); err == nil || err.Error() != expected {
|
||||
t.Errorf("Expecting: %+q received: %+q", expected, err)
|
||||
}
|
||||
cfg.chargerSCfg.AttributeSConns = []string{"Invalid"}
|
||||
|
||||
expected = "<ChargerS> Connection with id: <Invalid> not defined"
|
||||
@@ -403,6 +537,11 @@ func TestConfigSanityResourceLimiter(t *testing.T) {
|
||||
if err := cfg.checkConfigSanity(); err == nil || err.Error() != expected {
|
||||
t.Errorf("Expecting: %+q received: %+q", expected, err)
|
||||
}
|
||||
cfg.resourceSCfg.ThresholdSConns = []string{"test"}
|
||||
expected = "<ResourceS> Connection with id: <test> not defined"
|
||||
if err := cfg.checkConfigSanity(); err == nil || err.Error() != expected {
|
||||
t.Errorf("Expecting: %+q received: %+q", expected, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestConfigSanityStatS(t *testing.T) {
|
||||
@@ -415,6 +554,11 @@ func TestConfigSanityStatS(t *testing.T) {
|
||||
if err := cfg.checkConfigSanity(); err == nil || err.Error() != expected {
|
||||
t.Errorf("Expecting: %+q received: %+q", expected, err)
|
||||
}
|
||||
cfg.statsCfg.ThresholdSConns = []string{"test"}
|
||||
expected = "<Stats> Connection with id: <test> not defined"
|
||||
if err := cfg.checkConfigSanity(); err == nil || err.Error() != expected {
|
||||
t.Errorf("Expecting: %+q received: %+q", expected, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestConfigSanitySupplierS(t *testing.T) {
|
||||
@@ -427,6 +571,12 @@ func TestConfigSanitySupplierS(t *testing.T) {
|
||||
if err := cfg.checkConfigSanity(); err == nil || err.Error() != expected {
|
||||
t.Errorf("Expecting: %+q received: %+q", expected, err)
|
||||
}
|
||||
cfg.supplierSCfg.ResourceSConns = []string{"test"}
|
||||
expected = "<SupplierS> Connection with id: <test> not defined"
|
||||
if err := cfg.checkConfigSanity(); err == nil || err.Error() != expected {
|
||||
t.Errorf("Expecting: %+q received: %+q", expected, err)
|
||||
}
|
||||
cfg.supplierSCfg.ResourceSConns = []string{utils.MetaInternal}
|
||||
cfg.resourceSCfg.Enabled = true
|
||||
|
||||
cfg.supplierSCfg.StatSConns = []string{utils.MetaInternal}
|
||||
@@ -434,6 +584,12 @@ func TestConfigSanitySupplierS(t *testing.T) {
|
||||
if err := cfg.checkConfigSanity(); err == nil || err.Error() != expected {
|
||||
t.Errorf("Expecting: %+q received: %+q", expected, err)
|
||||
}
|
||||
cfg.supplierSCfg.StatSConns = []string{"test"}
|
||||
expected = "<SupplierS> Connection with id: <test> not defined"
|
||||
if err := cfg.checkConfigSanity(); err == nil || err.Error() != expected {
|
||||
t.Errorf("Expecting: %+q received: %+q", expected, err)
|
||||
}
|
||||
cfg.supplierSCfg.StatSConns = []string{utils.MetaInternal}
|
||||
cfg.statsCfg.Enabled = true
|
||||
|
||||
cfg.supplierSCfg.AttributeSConns = []string{utils.MetaInternal}
|
||||
@@ -441,6 +597,11 @@ func TestConfigSanitySupplierS(t *testing.T) {
|
||||
if err := cfg.checkConfigSanity(); err == nil || err.Error() != expected {
|
||||
t.Errorf("Expecting: %+q received: %+q", expected, err)
|
||||
}
|
||||
cfg.supplierSCfg.AttributeSConns = []string{"test"}
|
||||
expected = "<SupplierS> Connection with id: <test> not defined"
|
||||
if err := cfg.checkConfigSanity(); err == nil || err.Error() != expected {
|
||||
t.Errorf("Expecting: %+q received: %+q", expected, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestConfigSanityScheduler(t *testing.T) {
|
||||
@@ -453,6 +614,11 @@ func TestConfigSanityScheduler(t *testing.T) {
|
||||
if err := cfg.checkConfigSanity(); err == nil || err.Error() != expected {
|
||||
t.Errorf("Expecting: %+q received: %+q", expected, err)
|
||||
}
|
||||
cfg.schedulerCfg.CDRsConns = []string{"test"}
|
||||
expected = "<SchedulerS> Connection with id: <test> not defined"
|
||||
if err := cfg.checkConfigSanity(); err == nil || err.Error() != expected {
|
||||
t.Errorf("Expecting: %+q received: %+q", expected, err)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -508,15 +674,41 @@ func TestConfigSanityEventReader(t *testing.T) {
|
||||
if err := cfg.checkConfigSanity(); err == nil || err.Error() != expected {
|
||||
t.Errorf("Expecting: %+q received: %+q", expected, err)
|
||||
}
|
||||
cfg.ersCfg.Readers[0].FieldSep = utils.InInFieldSep
|
||||
|
||||
cfg.ersCfg.Readers[0].ID = "test4"
|
||||
cfg.ersCfg.Readers[0].Type = utils.MetaKafkajsonMap
|
||||
cfg.ersCfg.Readers[0].RunDelay = 1
|
||||
cfg.ersCfg.Readers[0] = &EventReaderCfg{
|
||||
ID: "test4",
|
||||
Type: utils.MetaKafkajsonMap,
|
||||
RunDelay: 1,
|
||||
FieldSep: utils.InInFieldSep,
|
||||
}
|
||||
expected = "<ERs> RunDelay field can not be bigger than zero for reader with ID: test4"
|
||||
if err := cfg.checkConfigSanity(); err == nil || err.Error() != expected {
|
||||
t.Errorf("Expecting: %+q received: %+q", expected, err)
|
||||
}
|
||||
cfg.ersCfg.Readers[0] = &EventReaderCfg{
|
||||
ID: "test5",
|
||||
Type: utils.MetaFileXML,
|
||||
RunDelay: 0,
|
||||
FieldSep: utils.InInFieldSep,
|
||||
ProcessedPath: "not/a/path",
|
||||
SourcePath: "not/a/path",
|
||||
}
|
||||
expected = "<ERs> Nonexistent folder: not/a/path for reader with ID: test5"
|
||||
if err := cfg.checkConfigSanity(); err == nil || err.Error() != expected {
|
||||
t.Errorf("Expecting: %+q received: %+q", expected, err)
|
||||
}
|
||||
|
||||
cfg.ersCfg.Readers[0] = &EventReaderCfg{
|
||||
ID: "test5",
|
||||
Type: utils.MetaFileFWV,
|
||||
RunDelay: 0,
|
||||
FieldSep: utils.InInFieldSep,
|
||||
ProcessedPath: "not/a/path",
|
||||
SourcePath: "not/a/path",
|
||||
}
|
||||
expected = "<ERs> Nonexistent folder: not/a/path for reader with ID: test5"
|
||||
if err := cfg.checkConfigSanity(); err == nil || err.Error() != expected {
|
||||
t.Errorf("Expecting: %+q received: %+q", expected, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestConfigSanityStorDB(t *testing.T) {
|
||||
@@ -597,6 +789,49 @@ func TestConfigSanityDataDB(t *testing.T) {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestConfigSanityAPIer(t *testing.T) {
|
||||
cfg, _ = NewDefaultCGRConfig()
|
||||
cfg.apier.AttributeSConns = []string{utils.MetaInternal}
|
||||
|
||||
if err := cfg.checkConfigSanity(); err == nil || err.Error() != "<AttributeS> not enabled but requested by <ApierV1> component." {
|
||||
t.Error(err)
|
||||
}
|
||||
cfg.apier.AttributeSConns = []string{"test"}
|
||||
expected := "<ApierV1> Connection with id: <test> not defined"
|
||||
if err := cfg.checkConfigSanity(); err == nil || err.Error() != expected {
|
||||
t.Errorf("Expecting: %+q received: %+q", expected, err)
|
||||
}
|
||||
cfg.apier.AttributeSConns = []string{utils.MetaInternal}
|
||||
cfg.attributeSCfg.Enabled = true
|
||||
cfg.apier.SchedulerConns = []string{utils.MetaInternal}
|
||||
|
||||
if err := cfg.checkConfigSanity(); err == nil || err.Error() != "<SchedulerS> not enabled but requested by <ApierV1> component." {
|
||||
t.Error(err)
|
||||
}
|
||||
cfg.apier.SchedulerConns = []string{"test"}
|
||||
expected = "<ApierV1> Connection with id: <test> not defined"
|
||||
if err := cfg.checkConfigSanity(); err == nil || err.Error() != expected {
|
||||
t.Errorf("Expecting: %+q received: %+q", expected, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestConfigSanityDispatcher(t *testing.T) {
|
||||
cfg, _ = NewDefaultCGRConfig()
|
||||
cfg.dispatcherSCfg = &DispatcherSCfg{
|
||||
Enabled: true,
|
||||
AttributeSConns: []string{utils.MetaInternal},
|
||||
}
|
||||
if err := cfg.checkConfigSanity(); err == nil || err.Error() != "<AttributeS> not enabled but requested by <DispatcherS> component." {
|
||||
t.Error(err)
|
||||
}
|
||||
cfg.dispatcherSCfg.AttributeSConns = []string{"test"}
|
||||
expected := "<DispatcherS> Connection with id: <test> not defined"
|
||||
if err := cfg.checkConfigSanity(); err == nil || err.Error() != expected {
|
||||
t.Errorf("Expecting: %+q received: %+q", expected, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestConfigSanityCacheS(t *testing.T) {
|
||||
cfg, _ = NewDefaultCGRConfig()
|
||||
|
||||
@@ -610,3 +845,41 @@ func TestConfigSanityCacheS(t *testing.T) {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestConfigSanityFilterS(t *testing.T) {
|
||||
cfg, _ = NewDefaultCGRConfig()
|
||||
cfg.filterSCfg.StatSConns = []string{utils.MetaInternal}
|
||||
|
||||
if err := cfg.checkConfigSanity(); err == nil || err.Error() != "<Stats> not enabled but requested by <FilterS> component." {
|
||||
t.Error(err)
|
||||
}
|
||||
cfg.filterSCfg.StatSConns = []string{"test"}
|
||||
expected := "<FilterS> Connection with id: <test> not defined"
|
||||
if err := cfg.checkConfigSanity(); err == nil || err.Error() != expected {
|
||||
t.Errorf("Expecting: %+q received: %+q", expected, err)
|
||||
}
|
||||
cfg.filterSCfg.StatSConns = []string{}
|
||||
|
||||
cfg.filterSCfg.ResourceSConns = []string{utils.MetaInternal}
|
||||
|
||||
if err := cfg.checkConfigSanity(); err == nil || err.Error() != "<ResourceS> not enabled but requested by <FilterS> component." {
|
||||
t.Error(err)
|
||||
}
|
||||
cfg.filterSCfg.ResourceSConns = []string{"test"}
|
||||
expected = "<FilterS> Connection with id: <test> not defined"
|
||||
if err := cfg.checkConfigSanity(); err == nil || err.Error() != expected {
|
||||
t.Errorf("Expecting: %+q received: %+q", expected, err)
|
||||
}
|
||||
cfg.filterSCfg.ResourceSConns = []string{}
|
||||
|
||||
cfg.filterSCfg.RALsConns = []string{utils.MetaInternal}
|
||||
|
||||
if err := cfg.checkConfigSanity(); err == nil || err.Error() != "<RALs> not enabled but requested by <FilterS> component." {
|
||||
t.Error(err)
|
||||
}
|
||||
cfg.filterSCfg.RALsConns = []string{"test"}
|
||||
expected = "<FilterS> Connection with id: <test> not defined"
|
||||
if err := cfg.checkConfigSanity(); err == nil || err.Error() != expected {
|
||||
t.Errorf("Expecting: %+q received: %+q", expected, err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,7 +23,13 @@ import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestNewRSRField1(t *testing.T) {
|
||||
func TestNewRSRField(t *testing.T) {
|
||||
// Empty case
|
||||
if rcv, err := NewRSRField(EmptyString); err != nil {
|
||||
t.Error(err)
|
||||
} else if rcv != nil {
|
||||
t.Error("Expecting nill, received: ", rcv)
|
||||
}
|
||||
// Normal case
|
||||
rulesStr := `~sip_redirected_to:s/sip:\+49(\d+)@/0$1/(someval)`
|
||||
filter, _ := NewRSRFilter("someval")
|
||||
@@ -80,6 +86,18 @@ func TestNewRSRField1(t *testing.T) {
|
||||
} else if !reflect.DeepEqual(expRSRField3, rsrField) {
|
||||
t.Errorf("Expecting: %v, received: %v", expRSRField3, rsrField)
|
||||
}
|
||||
if _, err := NewRSRField("(test)"); err == nil || err.Error() != "Invalid FilterStartValue in string: (test)" {
|
||||
t.Error(err)
|
||||
}
|
||||
if _, err := NewRSRField("{*test"); err == nil || err.Error() != "Invalid converter value in string: {*test, err: invalid converter terminator" {
|
||||
t.Error(err)
|
||||
}
|
||||
if _, err := NewRSRField("^t::e::s::t::"); err == nil || err.Error() != "Invalid RSRField string: ^t::e::s::t::" {
|
||||
t.Error(err)
|
||||
}
|
||||
if _, err := NewRSRField("~-1"); err == nil || err.Error() != "Invalid Split of Search&Replace field rule. ~-1" {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNewRSRFieldDDz(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user