Covered config to 100%

This commit is contained in:
porosnicuadrian
2021-01-11 16:48:14 +02:00
committed by Dan Christian Bogos
parent 0958def326
commit dd4d42e323
4 changed files with 71 additions and 17 deletions

View File

@@ -28,9 +28,9 @@ import (
func TestAccountSCfgLoadFromJSONCfg(t *testing.T) {
jsonCfg := &AccountSJsonCfg{
Enabled: utils.BoolPointer(true),
Attributes_conns: &[]string{"*req.index1"},
Rates_conns: &[]string{"*req.index1"},
Thresholds_conns: &[]string{"*req.index1"},
Attributes_conns: &[]string{utils.MetaInternal},
Rates_conns: &[]string{utils.MetaInternal},
Thresholds_conns: &[]string{utils.MetaInternal},
Indexed_selects: utils.BoolPointer(false),
String_indexed_fields: &[]string{"*req.index1"},
Prefix_indexed_fields: &[]string{"*req.index1"},
@@ -39,9 +39,9 @@ func TestAccountSCfgLoadFromJSONCfg(t *testing.T) {
}
expected := &AccountSCfg{
Enabled: true,
AttributeSConns: []string{"*req.index1"},
RateSConns: []string{"*req.index1"},
ThresholdSConns: []string{"*req.index1"},
AttributeSConns: []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaAttributes)},
RateSConns: []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaRateS)},
ThresholdSConns: []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaThresholds)},
IndexedSelects: false,
StringIndexedFields: &[]string{"*req.index1"},
PrefixIndexedFields: &[]string{"*req.index1"},
@@ -61,9 +61,9 @@ func TestAccountSCfgAsMapInterface(t *testing.T) {
"accounts": {
"enabled": true,
"indexed_selects": false,
"attributes_conns": ["*req.index1"],
"rates_conns": ["*req.index1"],
"thresholds_conns": ["*req.index1"],
"attributes_conns": ["*internal:*attributes"],
"rates_conns": ["*internal:*rates"],
"thresholds_conns": ["*internal:*thresholds"],
"string_indexed_fields": ["*req.index1"],
"prefix_indexed_fields": ["*req.index1"],
"suffix_indexed_fields": ["*req.index1"],
@@ -74,9 +74,9 @@ func TestAccountSCfgAsMapInterface(t *testing.T) {
eMap := map[string]interface{}{
utils.EnabledCfg: true,
utils.IndexedSelectsCfg: false,
utils.AttributeSConnsCfg: []string{"*req.index1"},
utils.RateSConnsCfg: []string{"*req.index1"},
utils.ThresholdSConnsCfg: []string{"*req.index1"},
utils.AttributeSConnsCfg: []string{utils.MetaInternal},
utils.RateSConnsCfg: []string{utils.MetaInternal},
utils.ThresholdSConnsCfg: []string{utils.MetaInternal},
utils.StringIndexedFieldsCfg: []string{"*req.index1"},
utils.PrefixIndexedFieldsCfg: []string{"*req.index1"},
utils.SuffixIndexedFieldsCfg: []string{"*req.index1"},

View File

@@ -1632,11 +1632,7 @@ func (cfg *CGRConfig) V1GetConfig(args *SectionWithOpts, reply *map[string]inter
case GENERAL_JSN:
mp = cfg.GeneralCfg().AsMapInterface()
case DATADB_JSN:
var datadb map[string]interface{}
if datadb = cfg.DataDbCfg().AsMapInterface(); err != nil {
return
}
mp = datadb
mp = cfg.DataDbCfg().AsMapInterface()
case STORDB_JSN:
mp = cfg.StorDbCfg().AsMapInterface()
case TlsCfgJson:
@@ -1869,6 +1865,8 @@ func (cfg *CGRConfig) V1GetConfigAsJSON(args *SectionWithOpts, reply *string) (e
mp = cfg.RateSCfg().AsMapInterface()
case CoreSCfgJson:
mp = cfg.CoreSCfg().AsMapInterface()
case AccountSCfgJson:
mp = cfg.AccountSCfg().AsMapInterface()
default:
return errors.New("Invalid section")
}

View File

@@ -4462,6 +4462,29 @@ func TestV1GetConfigThresholds(t *testing.T) {
}
}
func TestV1GetConfigAcounts(t *testing.T) {
var reply map[string]interface{}
expected := map[string]interface{}{
AccountSCfgJson: map[string]interface{}{
utils.EnabledCfg: false,
utils.IndexedSelectsCfg: true,
utils.AttributeSConnsCfg: []string{},
utils.RateSConnsCfg: []string{},
utils.ThresholdSConnsCfg: []string{},
utils.PrefixIndexedFieldsCfg: []string{},
utils.SuffixIndexedFieldsCfg: []string{},
utils.NestedFieldsCfg: false,
},
}
cfg := NewDefaultCGRConfig()
if err := cfg.V1GetConfig(&SectionWithOpts{Section: AccountSCfgJson}, &reply); err != nil {
t.Error(expected)
} else if !reflect.DeepEqual(reply, expected) {
t.Errorf("Expected %+v \n, received %+v", utils.ToJSON(expected), utils.ToJSON(reply))
}
}
func TestV1GetConfigRoutes(t *testing.T) {
var reply map[string]interface{}
expected := map[string]interface{}{
@@ -5092,6 +5115,17 @@ func TestV1GetConfigAsJSONTListen(t *testing.T) {
}
}
func TestV1GetConfigAsJSONAccounts(t *testing.T) {
var reply string
expected := `{"accounts":{"attributes_conns":[],"enabled":false,"indexed_selects":true,"nested_fields":false,"prefix_indexed_fields":[],"rates_conns":[],"suffix_indexed_fields":[],"thresholds_conns":[]}}`
cfg := NewDefaultCGRConfig()
if err := cfg.V1GetConfigAsJSON(&SectionWithOpts{Section: AccountSCfgJson}, &reply); err != nil {
t.Error(err)
} else if expected != reply {
t.Errorf("Expected %+v \n, received %+v", expected, reply)
}
}
func TestV1GetConfigAsJSONHTTP(t *testing.T) {
var reply string
expected := `{"http":{"auth_users":{},"client_opts":{"dialFallbackDelay":"300ms","dialKeepAlive":"30s","dialTimeout":"30s","disableCompression":false,"disableKeepAlives":false,"expectContinueTimeout":"0","forceAttemptHttp2":true,"idleConnTimeout":"90s","maxConnsPerHost":0,"maxIdleConns":100,"maxIdleConnsPerHost":2,"responseHeaderTimeout":"0","skipTlsVerify":false,"tlsHandshakeTimeout":"10s"},"dispatchers_registrar_url":"/dispatchers_registrar","freeswitch_cdrs_url":"/freeswitch_json","http_cdrs":"/cdr_http","json_rpc_url":"/jsonrpc","use_basic_auth":false,"ws_url":"/ws"}}`
@@ -6107,3 +6141,19 @@ func TestLoadActionSCfgError(t *testing.T) {
t.Errorf("Expected %+v, received %+v", expected, err)
}
}
func TestLoadAccountSCfgError(t *testing.T) {
cfgJSONStr := `{
"accounts": {
"enabled": "not_bool",
}
}`
expected := "json: cannot unmarshal string into Go struct field AccountSJsonCfg.Enabled of type bool"
cfg := NewDefaultCGRConfig()
if cgrCfgJSON, err := NewCgrJsonCfgFromBytes([]byte(cfgJSONStr)); err != nil {
t.Error(err)
} else if err := cfg.loadAccountSCfg(cgrCfgJSON); err == nil || err.Error() != expected {
t.Errorf("Expected %+v, received %+v", expected, err)
}
}

View File

@@ -1018,6 +1018,12 @@ func TestConfigSanityEventExporter(t *testing.T) {
if err := cfg.CheckConfigSanity(); err == nil || err.Error() != expected {
t.Errorf("Expecting: %+q received: %+q", expected, err)
}
cfg.eesCfg.Exporters[0].Type = utils.MetaSQL
expected = "<EEs> empty content fields for exporter with ID: "
if err := cfg.CheckConfigSanity(); err == nil || err.Error() != expected {
t.Errorf("Expecting: %+q received: %+q", expected, err)
}
}
func TestConfigSanityCache(t *testing.T) {