mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Update AsMapInterface function in config for AttributeS
This commit is contained in:
committed by
Dan Christian Bogos
parent
2605c34d79
commit
40d8870584
@@ -72,27 +72,32 @@ func (alS *AttributeSCfg) loadFromJsonCfg(jsnCfg *AttributeSJsonCfg) (err error)
|
||||
}
|
||||
|
||||
func (alS *AttributeSCfg) AsMapInterface() map[string]interface{} {
|
||||
stringIndexedFields := []string{}
|
||||
if alS.StringIndexedFields != nil {
|
||||
stringIndexedFields = make([]string, len(*alS.StringIndexedFields))
|
||||
for i, item := range *alS.StringIndexedFields {
|
||||
stringIndexedFields[i] = item
|
||||
}
|
||||
}
|
||||
prefixIndexedFields := []string{}
|
||||
if alS.PrefixIndexedFields != nil {
|
||||
prefixIndexedFields = make([]string, len(*alS.PrefixIndexedFields))
|
||||
for i, item := range *alS.PrefixIndexedFields {
|
||||
prefixIndexedFields[i] = item
|
||||
}
|
||||
}
|
||||
return map[string]interface{}{
|
||||
initialMP := map[string]interface{}{
|
||||
utils.EnabledCfg: alS.Enabled,
|
||||
utils.IndexedSelectsCfg: alS.IndexedSelects,
|
||||
utils.StringIndexedFieldsCfg: stringIndexedFields,
|
||||
utils.PrefixIndexedFieldsCfg: prefixIndexedFields,
|
||||
utils.ProcessRunsCfg: alS.ProcessRuns,
|
||||
utils.NestedFieldsCfg: alS.NestedFields,
|
||||
}
|
||||
|
||||
if alS.StringIndexedFields != nil {
|
||||
stringIndexedFields := make([]string, len(*alS.StringIndexedFields))
|
||||
for i, item := range *alS.StringIndexedFields {
|
||||
stringIndexedFields[i] = item
|
||||
}
|
||||
initialMP[utils.StringIndexedFieldsCfg] = stringIndexedFields
|
||||
}
|
||||
if alS.PrefixIndexedFields != nil {
|
||||
prefixIndexedFields := make([]string, len(*alS.PrefixIndexedFields))
|
||||
for i, item := range *alS.PrefixIndexedFields {
|
||||
prefixIndexedFields[i] = item
|
||||
}
|
||||
initialMP[utils.PrefixIndexedFieldsCfg] = prefixIndexedFields
|
||||
}
|
||||
if alS.SuffixIndexedFields != nil {
|
||||
suffixIndexedFields := make([]string, len(*alS.SuffixIndexedFields))
|
||||
for i, item := range *alS.SuffixIndexedFields {
|
||||
suffixIndexedFields[i] = item
|
||||
}
|
||||
initialMP[utils.SuffixIndexedFieldsCfg] = suffixIndexedFields
|
||||
}
|
||||
return initialMP
|
||||
}
|
||||
|
||||
@@ -61,7 +61,6 @@ func TestAttributeSCfgloadFromJsonCfg(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestAttributeSCfgAsMapInterface(t *testing.T) {
|
||||
var attscfg AttributeSCfg
|
||||
cfgJSONStr := `{
|
||||
"attributes": {
|
||||
"enabled": true,
|
||||
@@ -70,20 +69,61 @@ func TestAttributeSCfgAsMapInterface(t *testing.T) {
|
||||
},
|
||||
}`
|
||||
eMap := map[string]interface{}{
|
||||
"enabled": true,
|
||||
"prefix_indexed_fields": []string{"*req.index1", "*req.index2"},
|
||||
"process_runs": 3,
|
||||
"indexed_selects": false,
|
||||
"nested_fields": false,
|
||||
"string_indexed_fields": []string{},
|
||||
utils.EnabledCfg: true,
|
||||
utils.PrefixIndexedFieldsCfg: []string{"*req.index1", "*req.index2"},
|
||||
utils.ProcessRunsCfg: 3,
|
||||
utils.IndexedSelectsCfg: true,
|
||||
utils.NestedFieldsCfg: false,
|
||||
utils.SuffixIndexedFieldsCfg: []string{},
|
||||
}
|
||||
if jsnCfg, err := NewCgrJsonCfgFromBytes([]byte(cfgJSONStr)); err != nil {
|
||||
if cgrCfg, err := NewCGRConfigFromJsonStringWithDefaults(cfgJSONStr); err != nil {
|
||||
t.Error(err)
|
||||
} else if jsnAttSCfg, err := jsnCfg.AttributeServJsonCfg(); err != nil {
|
||||
t.Error(err)
|
||||
} else if err = attscfg.loadFromJsonCfg(jsnAttSCfg); err != nil {
|
||||
t.Error(err)
|
||||
} else if rcv := attscfg.AsMapInterface(); !reflect.DeepEqual(eMap, rcv) {
|
||||
} else if rcv := cgrCfg.attributeSCfg.AsMapInterface(); !reflect.DeepEqual(eMap, rcv) {
|
||||
t.Errorf("\nExpected: %+v\nRecived: %+v", utils.ToJSON(eMap), utils.ToJSON(rcv))
|
||||
}
|
||||
}
|
||||
|
||||
func TestAttributeSCfgAsMapInterface2(t *testing.T) {
|
||||
cfgJSONStr := `{
|
||||
"attributes": {
|
||||
"suffix_indexed_fields": ["*req.index1","*req.index2"],
|
||||
"nested_fields": true,
|
||||
"enabled": true,
|
||||
"process_runs": 7,
|
||||
},
|
||||
}`
|
||||
expectedMap := map[string]interface{}{
|
||||
utils.EnabledCfg: true,
|
||||
utils.IndexedSelectsCfg: true,
|
||||
utils.PrefixIndexedFieldsCfg: []string{},
|
||||
utils.SuffixIndexedFieldsCfg: []string{"*req.index1", "*req.index2"},
|
||||
utils.NestedFieldsCfg: true,
|
||||
utils.ProcessRunsCfg: 7,
|
||||
}
|
||||
if cgrCfg, err := NewCGRConfigFromJsonStringWithDefaults(cfgJSONStr); err != nil {
|
||||
t.Error(err)
|
||||
} else if newMap := cgrCfg.attributeSCfg.AsMapInterface(); !reflect.DeepEqual(expectedMap, newMap) {
|
||||
t.Errorf("Expected %+v \n, recieved %+v", utils.ToJSON(expectedMap), utils.ToJSON(newMap))
|
||||
}
|
||||
}
|
||||
|
||||
func TestAttributeSCfgAsMapInterface3(t *testing.T) {
|
||||
myJSONStr := `
|
||||
{
|
||||
"attributes": {}
|
||||
}
|
||||
`
|
||||
expectedMap := map[string]interface{}{
|
||||
utils.EnabledCfg: false,
|
||||
utils.IndexedSelectsCfg: true,
|
||||
utils.PrefixIndexedFieldsCfg: []string{},
|
||||
utils.SuffixIndexedFieldsCfg: []string{},
|
||||
utils.NestedFieldsCfg: false,
|
||||
utils.ProcessRunsCfg: 1,
|
||||
}
|
||||
if conv, err := NewCGRConfigFromJsonStringWithDefaults(myJSONStr); err != nil {
|
||||
t.Error(err)
|
||||
} else if newMap := conv.attributeSCfg.AsMapInterface(); !reflect.DeepEqual(expectedMap, newMap) {
|
||||
t.Errorf("Expected %+v, recieved %+v", expectedMap, newMap)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1888,6 +1888,7 @@ const (
|
||||
ConnMaxLifetimeCfg = "conn_max_lifetime"
|
||||
StringIndexedFieldsCfg = "string_indexed_fields"
|
||||
PrefixIndexedFieldsCfg = "prefix_indexed_fields"
|
||||
SuffixIndexedFieldsCfg = "suffix_indexed_fields"
|
||||
QueryTimeoutCfg = "query_timeout"
|
||||
SSLModeCfg = "sslmode"
|
||||
ItemsCfg = "items"
|
||||
|
||||
Reference in New Issue
Block a user