mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
coverage tests at configs
This commit is contained in:
committed by
Dan Christian Bogos
parent
f7ab15d454
commit
0d72169516
@@ -39,6 +39,7 @@ func TestAttributeSCfgloadFromJsonCfg(t *testing.T) {
|
||||
Any_context: utils.BoolPointer(true),
|
||||
Opts: &AttributesOptsJson{
|
||||
ProcessRuns: utils.IntPointer(1),
|
||||
Context: utils.StringPointer("context"),
|
||||
},
|
||||
}
|
||||
expected := &AttributeSCfg{
|
||||
@@ -55,6 +56,7 @@ func TestAttributeSCfgloadFromJsonCfg(t *testing.T) {
|
||||
Opts: &AttributesOpts{
|
||||
ProcessRuns: 1,
|
||||
ProfileIDs: []string{},
|
||||
Context: utils.StringPointer("context"),
|
||||
},
|
||||
}
|
||||
jsnCfg := NewDefaultCGRConfig()
|
||||
@@ -63,6 +65,12 @@ func TestAttributeSCfgloadFromJsonCfg(t *testing.T) {
|
||||
} else if !reflect.DeepEqual(expected, jsnCfg.attributeSCfg) {
|
||||
t.Errorf("Expected %+v, received %+v", utils.ToJSON(expected), utils.ToJSON(jsnCfg.attributeSCfg))
|
||||
}
|
||||
|
||||
jsnCfg.attributeSCfg.Opts.loadFromJSONCfg(nil)
|
||||
|
||||
if reflect.DeepEqual(jsnCfg.attributeSCfg.Opts, nil) {
|
||||
t.Error("expected nil")
|
||||
}
|
||||
}
|
||||
|
||||
func TestAttributeSCfgAsMapInterface(t *testing.T) {
|
||||
@@ -76,6 +84,7 @@ func TestAttributeSCfgAsMapInterface(t *testing.T) {
|
||||
"string_indexed_fields": ["*req.index1"],
|
||||
"opts": {
|
||||
"*processRuns": 3,
|
||||
"*context":"Context"
|
||||
},
|
||||
},
|
||||
}`
|
||||
@@ -95,6 +104,7 @@ func TestAttributeSCfgAsMapInterface(t *testing.T) {
|
||||
utils.MetaProfileRuns: 0,
|
||||
utils.MetaProfileIDs: []string{},
|
||||
utils.MetaProfileIgnoreFiltersCfg: false,
|
||||
utils.OptsContext: "Context",
|
||||
},
|
||||
}
|
||||
if cgrCfg, err := NewCGRConfigFromJSONStringWithDefaults(cfgJSONStr); err != nil {
|
||||
@@ -184,6 +194,7 @@ func TestAttributeSCfgClone(t *testing.T) {
|
||||
Opts: &AttributesOpts{
|
||||
ProcessRuns: 1,
|
||||
ProfileIDs: []string{},
|
||||
Context: utils.StringPointer("Context"),
|
||||
},
|
||||
}
|
||||
rcv := ban.Clone()
|
||||
|
||||
@@ -94,6 +94,11 @@ func TestDataDbCfgloadFromJsonCfg(t *testing.T) {
|
||||
t.Errorf("Expected %+v \n, received %+v", expected.RplConns, jsnCfg.dataDbCfg.RplConns)
|
||||
}
|
||||
}
|
||||
|
||||
if err := jsnCfg.dataDbCfg.Opts.loadFromJSONCfg(nil); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
jsonCfg = &DbJsonCfg{
|
||||
Opts: &DBOptsJson{
|
||||
RedisClusterSync: utils.StringPointer("test"),
|
||||
@@ -537,8 +542,8 @@ func TestDataDbCfgAsMapInterface(t *testing.T) {
|
||||
"remote_conns":[],
|
||||
"replication_conns":[],
|
||||
"items":{
|
||||
"*accounts":{"remote":true, "replicate":false, "api_key": "randomVal", "route_id": "randomVal"},
|
||||
"*reverse_destinations": {"remote":false, "replicate":false, "api_key": "randomVal", "route_id": "randomVal"},
|
||||
"*accounts":{"remote":true, "replicate":false, "api_key": "randomVal", "route_id": "randomVal","ttl":"1"},
|
||||
"*reverse_destinations": {"remote":false, "replicate":false, "api_key": "randomVal", "route_id": "randomVal","ttl":"1"},
|
||||
},
|
||||
},
|
||||
}`
|
||||
@@ -556,8 +561,8 @@ func TestDataDbCfgAsMapInterface(t *testing.T) {
|
||||
utils.RemoteConnsCfg: []string{},
|
||||
utils.ReplicationConnsCfg: []string{},
|
||||
utils.ItemsCfg: map[string]interface{}{
|
||||
utils.MetaAccounts: map[string]interface{}{utils.RemoteCfg: true, utils.ReplicateCfg: false, utils.APIKeyCfg: "randomVal", utils.RouteIDCfg: "randomVal", utils.LimitCfg: -1, utils.StaticTTLCfg: false},
|
||||
utils.MetaReverseDestinations: map[string]interface{}{utils.RemoteCfg: false, utils.ReplicateCfg: false, utils.APIKeyCfg: "randomVal", utils.RouteIDCfg: "randomVal", utils.LimitCfg: -1, utils.StaticTTLCfg: false},
|
||||
utils.MetaAccounts: map[string]interface{}{utils.RemoteCfg: true, utils.ReplicateCfg: false, utils.APIKeyCfg: "randomVal", utils.RouteIDCfg: "randomVal", utils.LimitCfg: -1, utils.StaticTTLCfg: false, utils.TTLCfg: "1ns"},
|
||||
utils.MetaReverseDestinations: map[string]interface{}{utils.RemoteCfg: false, utils.ReplicateCfg: false, utils.APIKeyCfg: "randomVal", utils.RouteIDCfg: "randomVal", utils.LimitCfg: -1, utils.StaticTTLCfg: false, utils.TTLCfg: "1ns"},
|
||||
},
|
||||
}
|
||||
if cgrCfg, err := NewCGRConfigFromJSONStringWithDefaults(cfgJSONStr); err != nil {
|
||||
|
||||
@@ -169,6 +169,7 @@ func TestEventReaderloadFromJsonCfg(t *testing.T) {
|
||||
if err = eventReader.loadFromJSONCfg(nil, jsonCfg.templates, jsonCfg.generalCfg.RSRSep); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestEventReaderloadFromJsonCase1(t *testing.T) {
|
||||
|
||||
@@ -76,6 +76,12 @@ func TestGeneralCfgloadFromJsonCfg(t *testing.T) {
|
||||
} else if !reflect.DeepEqual(expected, jsnCfg.generalCfg) {
|
||||
t.Errorf("Expected %+v \n, received %+v", utils.ToJSON(expected), utils.ToJSON(jsnCfg.generalCfg))
|
||||
}
|
||||
|
||||
cfgJSON.Max_reconnect_interval = utils.StringPointer("test1")
|
||||
|
||||
if err := jsnCfg.generalCfg.loadFromJSONCfg(cfgJSON); err == nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGeneralParseDurationCfgloadFromJsonCfg(t *testing.T) {
|
||||
@@ -139,9 +145,11 @@ func TestGeneralCfgAsMapInterface(t *testing.T) {
|
||||
"digest_separator": ",",
|
||||
"digest_equal": ":",
|
||||
"rsr_separator": ";",
|
||||
"max_parallel_conns": 100,
|
||||
"max_parallel_conns": 100,
|
||||
"max_reconnect_interval":"1s"
|
||||
},
|
||||
}`
|
||||
|
||||
eMap := map[string]interface{}{
|
||||
utils.NodeIDCfg: "cgrates",
|
||||
utils.LoggerCfg: "*syslog",
|
||||
@@ -159,7 +167,7 @@ func TestGeneralCfgAsMapInterface(t *testing.T) {
|
||||
utils.DefaultCachingCfg: "*reload",
|
||||
utils.ConnectAttemptsCfg: 5,
|
||||
utils.ReconnectsCfg: -1,
|
||||
utils.MaxReconnectIntervalCfg: "0",
|
||||
utils.MaxReconnectIntervalCfg: "1s",
|
||||
utils.ConnectTimeoutCfg: "1s",
|
||||
utils.ReplyTimeoutCfg: "2s",
|
||||
utils.LockingTimeoutCfg: "1s",
|
||||
|
||||
@@ -75,6 +75,7 @@ func TestHTTPCfgloadFromJsonCfg(t *testing.T) {
|
||||
} else if !reflect.DeepEqual(expected.AsMapInterface(), cfgJsn.httpCfg.AsMapInterface()) {
|
||||
t.Errorf("Expected %+v \n, received %+v", expected.AsMapInterface(), cfgJsn.httpCfg.AsMapInterface())
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestHTTPCfgAsMapInterface(t *testing.T) {
|
||||
|
||||
@@ -512,3 +512,16 @@ func TestLockFolderIsDir(t *testing.T) {
|
||||
t.Errorf("Expected %v \n but received \n %v", expPath, ldr.LockFilePath)
|
||||
}
|
||||
}
|
||||
|
||||
func TestLockGetLockFilePath(t *testing.T) {
|
||||
|
||||
l := LoaderSCfg{
|
||||
LockFilePath: "folder",
|
||||
TpInDir: "/dir",
|
||||
ID: "4"}
|
||||
expected := "/dir/folder"
|
||||
if val := l.GetLockFilePath(); val != expected {
|
||||
t.Error(val)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -55,6 +55,23 @@ func TestResourceSConfigloadFromJsonCfgCase1(t *testing.T) {
|
||||
} else if !reflect.DeepEqual(expected, cfg.resourceSCfg) {
|
||||
t.Errorf("Expected %+v \n, received %+v", utils.ToJSON(expected), utils.ToJSON(cfg.resourceSCfg))
|
||||
}
|
||||
cfg.resourceSCfg.Opts.loadFromJSONCfg(nil)
|
||||
if reflect.DeepEqual(nil, cfg.resourceSCfg.Opts) {
|
||||
t.Error("expected nil")
|
||||
}
|
||||
cfgJson := &ResourcesOptsJson{
|
||||
UsageTTL: utils.StringPointer("1000"),
|
||||
}
|
||||
if err := cfg.resourceSCfg.Opts.loadFromJSONCfg(cfgJson); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
cfgJsonFail := &ResourcesOptsJson{
|
||||
UsageTTL: utils.StringPointer("test"),
|
||||
}
|
||||
if err := cfg.resourceSCfg.Opts.loadFromJSONCfg(cfgJsonFail); err == nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestResourceSConfigloadFromJsonCfgCase2(t *testing.T) {
|
||||
@@ -102,7 +119,11 @@ func TestResourceSConfigAsMapInterface1(t *testing.T) {
|
||||
"string_indexed_fields": ["*req.index1"],
|
||||
"prefix_indexed_fields": ["*req.prefix_indexed_fields1","*req.prefix_indexed_fields2"],
|
||||
"suffix_indexed_fields": ["*req.prefix_indexed_fields1"],
|
||||
"nested_fields": true,
|
||||
"nested_fields": true,
|
||||
"opts":{
|
||||
"*usageTTL":"1"
|
||||
|
||||
}
|
||||
},
|
||||
}`
|
||||
eMap := map[string]interface{}{
|
||||
@@ -115,8 +136,9 @@ func TestResourceSConfigAsMapInterface1(t *testing.T) {
|
||||
utils.SuffixIndexedFieldsCfg: []string{"*req.prefix_indexed_fields1"},
|
||||
utils.NestedFieldsCfg: true,
|
||||
utils.OptsCfg: map[string]interface{}{
|
||||
utils.MetaUnitsCfg: 1.,
|
||||
utils.MetaUsageIDCfg: "",
|
||||
utils.MetaUnitsCfg: 1.,
|
||||
utils.MetaUsageIDCfg: "",
|
||||
utils.MetaUsageTTLCfg: 1 * time.Nanosecond,
|
||||
},
|
||||
}
|
||||
if cgrCfg, err := NewCGRConfigFromJSONStringWithDefaults(cfgJSONStr); err != nil {
|
||||
@@ -136,7 +158,9 @@ func TestResourceSConfigClone(t *testing.T) {
|
||||
PrefixIndexedFields: &[]string{"*req.index1"},
|
||||
SuffixIndexedFields: &[]string{"*req.index1"},
|
||||
NestedFields: true,
|
||||
Opts: &ResourcesOpts{},
|
||||
Opts: &ResourcesOpts{
|
||||
UsageTTL: utils.DurationPointer(1 * time.Second),
|
||||
},
|
||||
}
|
||||
rcv := ban.Clone()
|
||||
if !reflect.DeepEqual(ban, rcv) {
|
||||
|
||||
@@ -72,11 +72,20 @@ func TestRouteSCfgloadFromJsonCfg(t *testing.T) {
|
||||
} else if !reflect.DeepEqual(expected, jsonCfg.routeSCfg) {
|
||||
t.Errorf("Expected %+v \n, received %+v", utils.ToJSON(expected), utils.ToJSON(jsonCfg.routeSCfg))
|
||||
}
|
||||
jsonCfg.routeSCfg.Opts.loadFromJSONCfg(nil)
|
||||
if reflect.DeepEqual(nil, jsonCfg.routeSCfg.Opts) {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRouteSCfgAsMapInterface(t *testing.T) {
|
||||
cfgJSONStr := `{
|
||||
"routes": {},
|
||||
"routes": {
|
||||
|
||||
"opts":{
|
||||
|
||||
},
|
||||
},
|
||||
}`
|
||||
eMap := map[string]interface{}{
|
||||
utils.EnabledCfg: false,
|
||||
@@ -156,7 +165,11 @@ func TestRouteSCfgClone(t *testing.T) {
|
||||
RALsConns: []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaResponder), "conn1"},
|
||||
DefaultRatio: 10,
|
||||
NestedFields: true,
|
||||
Opts: &RoutesOpts{},
|
||||
Opts: &RoutesOpts{
|
||||
ProfileCount: utils.IntPointer(0),
|
||||
Limit: utils.IntPointer(0),
|
||||
Offset: utils.IntPointer(0),
|
||||
},
|
||||
}
|
||||
rcv := ban.Clone()
|
||||
if !reflect.DeepEqual(ban, rcv) {
|
||||
|
||||
@@ -661,22 +661,29 @@ func TestFsConnCfgloadFromJsonCfg(t *testing.T) {
|
||||
t.Errorf("Expected: %+v ,received: %+v", expected, fscocfg)
|
||||
}
|
||||
json := &FsConnJsonCfg{
|
||||
Address: utils.StringPointer("127.0.0.1:8448"),
|
||||
Password: utils.StringPointer("pass123"),
|
||||
Reconnects: utils.IntPointer(5),
|
||||
Alias: utils.StringPointer("127.0.0.1:8448"),
|
||||
Address: utils.StringPointer("127.0.0.1:8448"),
|
||||
Password: utils.StringPointer("pass123"),
|
||||
Reconnects: utils.IntPointer(5),
|
||||
Alias: utils.StringPointer("127.0.0.1:8448"),
|
||||
Max_reconnect_interval: utils.StringPointer("1"),
|
||||
}
|
||||
expected = FsConnCfg{
|
||||
Address: "127.0.0.1:8448",
|
||||
Password: "pass123",
|
||||
Reconnects: 5,
|
||||
Alias: "127.0.0.1:8448",
|
||||
Address: "127.0.0.1:8448",
|
||||
Password: "pass123",
|
||||
Reconnects: 5,
|
||||
Alias: "127.0.0.1:8448",
|
||||
MaxReconnectInterval: 1 * time.Nanosecond,
|
||||
}
|
||||
if err = fscocfg.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))
|
||||
}
|
||||
json.Max_reconnect_interval = utils.StringPointer("test")
|
||||
|
||||
if err := fscocfg.loadFromJSONCfg(json); err == nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRemoteHostloadFromJsonCfg(t *testing.T) {
|
||||
@@ -799,24 +806,30 @@ func TestAsteriskConnCfgloadFromJsonCfg(t *testing.T) {
|
||||
t.Errorf("Expected: %+v ,received: %+v", expected, asconcfg)
|
||||
}
|
||||
json := &AstConnJsonCfg{
|
||||
Address: utils.StringPointer("127.0.0.1:8088"),
|
||||
User: utils.StringPointer("cgrates"),
|
||||
Password: utils.StringPointer("CGRateS.org"),
|
||||
Connect_attempts: utils.IntPointer(3),
|
||||
Reconnects: utils.IntPointer(5),
|
||||
Address: utils.StringPointer("127.0.0.1:8088"),
|
||||
User: utils.StringPointer("cgrates"),
|
||||
Password: utils.StringPointer("CGRateS.org"),
|
||||
Connect_attempts: utils.IntPointer(3),
|
||||
Reconnects: utils.IntPointer(5),
|
||||
Max_reconnect_interval: utils.StringPointer("1"),
|
||||
}
|
||||
expected = AsteriskConnCfg{
|
||||
Address: "127.0.0.1:8088",
|
||||
User: "cgrates",
|
||||
Password: "CGRateS.org",
|
||||
ConnectAttempts: 3,
|
||||
Reconnects: 5,
|
||||
Address: "127.0.0.1:8088",
|
||||
User: "cgrates",
|
||||
Password: "CGRateS.org",
|
||||
ConnectAttempts: 3,
|
||||
Reconnects: 5,
|
||||
MaxReconnectInterval: 1 * time.Nanosecond,
|
||||
}
|
||||
if err = asconcfg.loadFromJSONCfg(json); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(expected, asconcfg) {
|
||||
t.Errorf("Expected: %+v , received: %+v", utils.ToJSON(expected), utils.ToJSON(asconcfg))
|
||||
}
|
||||
json.Max_reconnect_interval = utils.StringPointer("test")
|
||||
if err = asconcfg.loadFromJSONCfg(json); err == nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestAsteriskAgentCfgClone(t *testing.T) {
|
||||
|
||||
@@ -56,6 +56,11 @@ func TestStatSCfgloadFromJsonCfgCase1(t *testing.T) {
|
||||
} else if !reflect.DeepEqual(expected, jsonCfg.statsCfg) {
|
||||
t.Errorf("Expected %+v \n, received %+v", utils.ToJSON(expected), utils.ToJSON(jsonCfg.statsCfg))
|
||||
}
|
||||
jsonCfg.statsCfg.Opts.loadFromJSONCfg(nil)
|
||||
if reflect.DeepEqual(nil, jsonCfg.statsCfg.Opts) {
|
||||
|
||||
t.Error("expected nil")
|
||||
}
|
||||
}
|
||||
|
||||
func TestStatSCfgloadFromJsonCfgCase2(t *testing.T) {
|
||||
|
||||
@@ -99,6 +99,27 @@ func TestStoreDbCfgloadFromJsonCfgCase1(t *testing.T) {
|
||||
} else if !reflect.DeepEqual(expected.RmtConns, jsonCfg.storDbCfg.RmtConns) {
|
||||
t.Errorf("Expected %+v \n, recevied %+v", utils.ToJSON(expected.RmtConns), utils.ToJSON(jsonCfg.storDbCfg.RmtConns))
|
||||
}
|
||||
|
||||
var dbOpts *StorDBOpts
|
||||
var jsonDbOpts *DBOptsJson
|
||||
dbOpts.loadFromJSONCfg(jsonDbOpts)
|
||||
if reflect.DeepEqual(nil, dbOpts) {
|
||||
t.Error("expected nil")
|
||||
}
|
||||
jsonDOpts := &DBOptsJson{
|
||||
|
||||
SQLConnMaxLifetime: utils.StringPointer("test"),
|
||||
}
|
||||
if err := jsonCfg.storDbCfg.Opts.loadFromJSONCfg(jsonDOpts); err == nil {
|
||||
t.Error(err)
|
||||
}
|
||||
jjsonDOpts := &DBOptsJson{
|
||||
|
||||
MongoQueryTimeout: utils.StringPointer("test"),
|
||||
}
|
||||
if err := jsonCfg.storDbCfg.Opts.loadFromJSONCfg(jjsonDOpts); err == nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestStoreDbCfgloadFromJsonCfgCase2(t *testing.T) {
|
||||
|
||||
@@ -57,6 +57,12 @@ func TestThresholdSCfgloadFromJsonCfgCase1(t *testing.T) {
|
||||
} else if !reflect.DeepEqual(expected, jsonCfg.thresholdSCfg) {
|
||||
t.Errorf("Expected %+v \n, received %+v", utils.ToJSON(expected), utils.ToJSON(jsonCfg.thresholdSCfg))
|
||||
}
|
||||
var optsCfg *ThresholdsOpts
|
||||
var jsonOpt *ThresholdsOptsJson
|
||||
optsCfg.loadFromJSONCfg(jsonOpt)
|
||||
if reflect.DeepEqual(nil, optsCfg) {
|
||||
t.Error("expected nil")
|
||||
}
|
||||
}
|
||||
|
||||
func TestThresholdSCfgloadFromJsonCfgCase2(t *testing.T) {
|
||||
|
||||
@@ -621,7 +621,6 @@ func TestDifference(t *testing.T) {
|
||||
} else if diff != time.Date(2009, 11, 10, 22, 59, 40, 0, time.UTC) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", time.Date(2009, 11, 10, 22, 59, 40, 0, time.UTC), diff)
|
||||
}
|
||||
|
||||
if _, err := Difference("time.Second", time.Date(2009, 11, 10, 22, 59, 40, 0, time.UTC), "20000000"); err != nil {
|
||||
|
||||
t.Errorf("%v", err)
|
||||
|
||||
Reference in New Issue
Block a user