mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Updated load tests for analyzerscfg, apiercfg, attributescfg, cachecfg
This commit is contained in:
committed by
Dan Christian Bogos
parent
e2e2775625
commit
dd42186b22
@@ -25,34 +25,18 @@ import (
|
||||
)
|
||||
|
||||
func TestAnalyzerSCfgloadFromJsonCfg(t *testing.T) {
|
||||
var alS, expected AnalyzerSCfg
|
||||
if err := alS.loadFromJsonCfg(nil); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(alS, expected) {
|
||||
t.Errorf("Expected: %+v ,recived: %+v", expected, alS)
|
||||
jsonCfg := &AnalyzerSJsonCfg{
|
||||
Enabled: utils.BoolPointer(false),
|
||||
}
|
||||
if err := alS.loadFromJsonCfg(new(AnalyzerSJsonCfg)); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(alS, expected) {
|
||||
t.Errorf("Expected: %+v ,recived: %+v", expected, alS)
|
||||
}
|
||||
cfgJSONStr := `{
|
||||
"analyzers":{ // AnalyzerS config
|
||||
"enabled":false // starts AnalyzerS service: <true|false>.
|
||||
},
|
||||
|
||||
}`
|
||||
expected = AnalyzerSCfg{
|
||||
expected := &AnalyzerSCfg{
|
||||
Enabled: false,
|
||||
}
|
||||
if jsnCfg, err := NewCgrJsonCfgFromBytes([]byte(cfgJSONStr)); err != nil {
|
||||
if jsnCfg, err := NewDefaultCGRConfig(); err != nil {
|
||||
t.Error(err)
|
||||
} else if jsnalS, err := jsnCfg.AnalyzerCfgJson(); err != nil {
|
||||
} else if err = jsnCfg.analyzerSCfg.loadFromJsonCfg(jsonCfg); err != nil {
|
||||
t.Error(err)
|
||||
} else if err = alS.loadFromJsonCfg(jsnalS); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(expected, alS) {
|
||||
t.Errorf("Expected: %+v , recived: %+v", expected, alS)
|
||||
} else if !reflect.DeepEqual(jsnCfg.analyzerSCfg, expected) {
|
||||
t.Errorf("Expected %+v \n, received %+v", expected, jsnCfg.analyzerSCfg)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -25,39 +25,26 @@ import (
|
||||
)
|
||||
|
||||
func TestApierCfgloadFromJsonCfg(t *testing.T) {
|
||||
var aCfg, expected ApierCfg
|
||||
if err := aCfg.loadFromJsonCfg(nil); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(aCfg, expected) {
|
||||
t.Errorf("Expected: %+v ,recived: %+v", expected, aCfg)
|
||||
jsonCfg := &ApierJsonCfg{
|
||||
Enabled: utils.BoolPointer(false),
|
||||
Caches_conns: &[]string{"*internal:*caches"},
|
||||
Scheduler_conns: &[]string{"*conn1"},
|
||||
Attributes_conns: &[]string{"*internal:*attributes"},
|
||||
Ees_conns: &[]string{"*conn1", "*conn2"},
|
||||
}
|
||||
if err := aCfg.loadFromJsonCfg(new(ApierJsonCfg)); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(aCfg, expected) {
|
||||
t.Errorf("Expected: %+v ,recived: %+v", expected, aCfg)
|
||||
}
|
||||
cfgJSONStr := `{
|
||||
"apiers": {
|
||||
"enabled": false,
|
||||
"caches_conns":["*internal"],
|
||||
"scheduler_conns": [],
|
||||
"attributes_conns": [],
|
||||
},
|
||||
}`
|
||||
expected = ApierCfg{
|
||||
expected := &ApierCfg{
|
||||
Enabled: false,
|
||||
CachesConns: []string{"*internal:*caches"},
|
||||
SchedulerConns: []string{},
|
||||
AttributeSConns: []string{},
|
||||
SchedulerConns: []string{"*conn1"},
|
||||
AttributeSConns: []string{"*internal:*attributes"},
|
||||
EEsConns: []string{"*conn1", "*conn2"},
|
||||
}
|
||||
if jsnCfg, err := NewCgrJsonCfgFromBytes([]byte(cfgJSONStr)); err != nil {
|
||||
if jsnCfg, err := NewDefaultCGRConfig(); err != nil {
|
||||
t.Error(err)
|
||||
} else if jsnaCfg, err := jsnCfg.ApierCfgJson(); err != nil {
|
||||
} else if err = jsnCfg.apier.loadFromJsonCfg(jsonCfg); err != nil {
|
||||
t.Error(err)
|
||||
} else if err = aCfg.loadFromJsonCfg(jsnaCfg); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(expected, aCfg) {
|
||||
t.Errorf("Expected: %+v , recived: %+v", expected, aCfg)
|
||||
} else if !reflect.DeepEqual(expected, jsnCfg.apier) {
|
||||
t.Errorf("Expected %+v \n, received %+v", utils.ToJSON(expected), utils.ToJSON(jsnCfg.apier))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -25,38 +25,28 @@ import (
|
||||
)
|
||||
|
||||
func TestAttributeSCfgloadFromJsonCfg(t *testing.T) {
|
||||
var attscfg, expected AttributeSCfg
|
||||
if err := attscfg.loadFromJsonCfg(nil); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(attscfg, expected) {
|
||||
t.Errorf("Expected: %+v ,received: %+v", expected, attscfg)
|
||||
jsonCfg := &AttributeSJsonCfg{
|
||||
Enabled: utils.BoolPointer(true),
|
||||
Indexed_selects: utils.BoolPointer(false),
|
||||
Prefix_indexed_fields: &[]string{"*req.index1", "*req.index2"},
|
||||
Suffix_indexed_fields: &[]string{"*req.index1"},
|
||||
Process_runs: utils.IntPointer(1),
|
||||
Nested_fields: utils.BoolPointer(true),
|
||||
}
|
||||
if err := attscfg.loadFromJsonCfg(new(AttributeSJsonCfg)); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(attscfg, expected) {
|
||||
t.Errorf("Expected: %+v ,received: %+v", expected, attscfg)
|
||||
}
|
||||
cfgJSONStr := `{
|
||||
"attributes": { // Attribute service
|
||||
"enabled": true, // starts attribute service: <true|false>.
|
||||
//"string_indexed_fields": [], // query indexes based on these fields for faster processing
|
||||
"prefix_indexed_fields": ["*req.index1","*req.index2"], // query indexes based on these fields for faster processing
|
||||
"process_runs": 1, // number of run loops when processing event
|
||||
},
|
||||
}`
|
||||
expected = AttributeSCfg{
|
||||
expected := &AttributeSCfg{
|
||||
Enabled: true,
|
||||
IndexedSelects: false,
|
||||
PrefixIndexedFields: &[]string{"*req.index1", "*req.index2"},
|
||||
SuffixIndexedFields: &[]string{"*req.index1"},
|
||||
ProcessRuns: 1,
|
||||
NestedFields: true,
|
||||
}
|
||||
if jsnCfg, err := NewCgrJsonCfgFromBytes([]byte(cfgJSONStr)); err != nil {
|
||||
if jsnCfg, err := NewDefaultCGRConfig(); err != nil {
|
||||
t.Error(err)
|
||||
} else if jsnAttSCfg, err := jsnCfg.AttributeServJsonCfg(); err != nil {
|
||||
} else if err = jsnCfg.attributeSCfg.loadFromJsonCfg(jsonCfg); err != nil {
|
||||
t.Error(err)
|
||||
} else if err = attscfg.loadFromJsonCfg(jsnAttSCfg); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(expected, attscfg) {
|
||||
t.Errorf("Expected: %+v , received: %+v", expected, attscfg)
|
||||
} else if !reflect.DeepEqual(expected, jsnCfg.attributeSCfg) {
|
||||
t.Errorf("Expected %+v, received %+v", utils.ToJSON(expected), utils.ToJSON(jsnCfg.attributeSCfg))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -51,76 +51,56 @@ func TestAsTransCacheConfig(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestCacheCfgloadFromJsonCfg(t *testing.T) {
|
||||
var cachecfg, expected *CacheCfg
|
||||
cachecfg = new(CacheCfg)
|
||||
expected = new(CacheCfg)
|
||||
if err := cachecfg.loadFromJsonCfg(nil); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(cachecfg, expected) {
|
||||
t.Errorf("Expected: %+v ,received: %+v", expected, cachecfg)
|
||||
}
|
||||
if err := cachecfg.loadFromJsonCfg(new(CacheJsonCfg)); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(cachecfg, expected) {
|
||||
t.Errorf("Expected: %+v ,received: %+v", expected, cachecfg)
|
||||
}
|
||||
cfgJSONStr := `{
|
||||
"caches":{
|
||||
"partitions": {
|
||||
"*destinations": {"limit": -1, "ttl": "", "static_ttl": false, "precache": false},
|
||||
"*reverse_destinations": {"limit": -1, "ttl": "", "static_ttl": false, "precache": false},
|
||||
"*rating_plans": {"limit": -1, "ttl": "", "static_ttl": false, "precache": false},
|
||||
jsonCfg := &CacheJsonCfg{
|
||||
Partitions: &map[string]*CacheParamJsonCfg{
|
||||
utils.MetaDestinations: {
|
||||
Limit: utils.IntPointer(10),
|
||||
Ttl: utils.StringPointer("2"),
|
||||
Static_ttl: utils.BoolPointer(true),
|
||||
Precache: utils.BoolPointer(true),
|
||||
Replicate: utils.BoolPointer(true),
|
||||
},
|
||||
},
|
||||
},
|
||||
}`
|
||||
expected = &CacheCfg{
|
||||
Replication_conns: &[]string{"conn1", "conn2"},
|
||||
}
|
||||
expected := &CacheCfg{
|
||||
Partitions: map[string]*CacheParamCfg{
|
||||
"*destinations": {Limit: -1, TTL: time.Duration(0), StaticTTL: false, Precache: false},
|
||||
"*reverse_destinations": {Limit: -1, TTL: time.Duration(0), StaticTTL: false, Precache: false},
|
||||
"*rating_plans": {Limit: -1, TTL: time.Duration(0), StaticTTL: false, Precache: false},
|
||||
utils.MetaDestinations: {Limit: 10, TTL: time.Duration(2), StaticTTL: true, Precache: true, Replicate: true},
|
||||
},
|
||||
ReplicationConns: []string{"conn1", "conn2"},
|
||||
}
|
||||
cachecfg = new(CacheCfg)
|
||||
cachecfg.Partitions = make(map[string]*CacheParamCfg)
|
||||
if jsnCfg, err := NewCgrJsonCfgFromBytes([]byte(cfgJSONStr)); err != nil {
|
||||
if jsnCfg, err := NewDefaultCGRConfig(); err != nil {
|
||||
t.Error(err)
|
||||
} else if jsnCacheCfg, err := jsnCfg.CacheJsonCfg(); err != nil {
|
||||
} else if err = jsnCfg.cacheCfg.loadFromJsonCfg(jsonCfg); err != nil {
|
||||
t.Error(err)
|
||||
} else if err = cachecfg.loadFromJsonCfg(jsnCacheCfg); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(expected, cachecfg) {
|
||||
t.Errorf("Expected: %+v , received: %+v", expected, cachecfg)
|
||||
} else {
|
||||
if !reflect.DeepEqual(expected.Partitions[utils.MetaDestinations], jsnCfg.cacheCfg.Partitions[utils.MetaDestinations]) {
|
||||
t.Errorf("Expected %+v \n, received %+v", utils.ToJSON(expected.Partitions[utils.MetaDestinations]),
|
||||
utils.ToJSON(jsnCfg.cacheCfg.Partitions[utils.MetaDestinations]))
|
||||
} else if !reflect.DeepEqual(jsnCfg.cacheCfg.ReplicationConns, expected.ReplicationConns) {
|
||||
t.Errorf("Expected %+v \n, received %+v", utils.ToJSON(expected.ReplicationConns), utils.ToJSON(jsnCfg.cacheCfg.ReplicationConns))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestCacheParamCfgloadFromJsonCfg(t *testing.T) {
|
||||
var fscocfg, expected CacheParamCfg
|
||||
if err := fscocfg.loadFromJsonCfg(nil); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(fscocfg, expected) {
|
||||
t.Errorf("Expected: %+v ,received: %+v", expected, fscocfg)
|
||||
}
|
||||
if err := fscocfg.loadFromJsonCfg(new(CacheParamJsonCfg)); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(fscocfg, expected) {
|
||||
t.Errorf("Expected: %+v ,received: %+v", expected, fscocfg)
|
||||
}
|
||||
json := &CacheParamJsonCfg{
|
||||
Limit: utils.IntPointer(5),
|
||||
Ttl: utils.StringPointer("1s"),
|
||||
Static_ttl: utils.BoolPointer(true),
|
||||
Precache: utils.BoolPointer(true),
|
||||
}
|
||||
expected = CacheParamCfg{
|
||||
expected := &CacheParamCfg{
|
||||
Limit: 5,
|
||||
TTL: time.Duration(time.Second),
|
||||
StaticTTL: true,
|
||||
Precache: true,
|
||||
}
|
||||
if err = fscocfg.loadFromJsonCfg(json); err != nil {
|
||||
rcv := new(CacheParamCfg)
|
||||
if err := rcv.loadFromJsonCfg(json); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(expected, fscocfg) {
|
||||
t.Errorf("Expected: %+v , received: %+v", utils.ToJSON(expected), utils.ToJSON(fscocfg))
|
||||
} else if !reflect.DeepEqual(rcv, expected) {
|
||||
t.Errorf("Expected %+v, received %+v", utils.ToJSON(expected), utils.ToJSON(rcv))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,3 +1,21 @@
|
||||
/*
|
||||
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 <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
|
||||
package config
|
||||
|
||||
import (
|
||||
|
||||
Reference in New Issue
Block a user