mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Add coverage tests for config
This commit is contained in:
committed by
Dan Christian Bogos
parent
8894cc19ee
commit
69d0fa7705
@@ -230,3 +230,56 @@ func TestCacheCfgClone(t *testing.T) {
|
||||
t.Errorf("Expected clone to not modify the cloned")
|
||||
}
|
||||
}
|
||||
|
||||
func TestCacheCfgloadFromJSONCfg(t *testing.T) {
|
||||
str := "test"
|
||||
bl := true
|
||||
nm := 1
|
||||
slc := []string{str}
|
||||
tm := 1 * time.Second
|
||||
tms := "1s"
|
||||
mcp := map[string]*CacheParamCfg{
|
||||
str: {
|
||||
Limit: nm,
|
||||
TTL: tm,
|
||||
StaticTTL: bl,
|
||||
Precache: bl,
|
||||
Remote: bl,
|
||||
Replicate: bl,
|
||||
},
|
||||
}
|
||||
cCfg := &CacheCfg{
|
||||
Partitions: map[string]*CacheParamCfg{},
|
||||
ReplicationConns: []string{},
|
||||
RemoteConns: []string{},
|
||||
}
|
||||
mc := map[string]*CacheParamJsonCfg{
|
||||
str: {
|
||||
Limit: &nm,
|
||||
Ttl: &tms,
|
||||
Static_ttl: &bl,
|
||||
Precache: &bl,
|
||||
Remote: &bl,
|
||||
Replicate: &bl,
|
||||
},
|
||||
}
|
||||
jsn := &CacheJsonCfg{
|
||||
Partitions: &mc,
|
||||
Replication_conns: &slc,
|
||||
Remote_conns: &slc,
|
||||
}
|
||||
exp := &CacheCfg{
|
||||
Partitions: mcp,
|
||||
ReplicationConns: slc,
|
||||
RemoteConns: slc,
|
||||
}
|
||||
|
||||
err := cCfg.loadFromJSONCfg(jsn)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(cCfg, exp) {
|
||||
t.Errorf("\nexpected %s\nreceived %s\n", utils.ToJSON(exp), utils.ToJSON(cCfg))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5891,3 +5891,19 @@ func TestCGRConfigGetDP(t *testing.T) {
|
||||
t.Errorf("Expected %+v, received %+v", exp, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestConfignewCGRConfigFromPathWithoutEnv(t *testing.T) {
|
||||
flPath := "/usr/share/cgrates/conf/samples/NotExists/cgrates.json"
|
||||
rcv, err := newCGRConfigFromPathWithoutEnv(flPath)
|
||||
if err != nil {
|
||||
if err.Error() != `path:"/usr/share/cgrates/conf/samples/NotExists/cgrates.json" is not reachable` {
|
||||
t.Error(err)
|
||||
}
|
||||
} else {
|
||||
t.Error("was expecting an error")
|
||||
}
|
||||
|
||||
if rcv == nil {
|
||||
t.Error(rcv)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1747,3 +1747,147 @@ func TestERsCfgappendERsReaders(t *testing.T) {
|
||||
t.Errorf("\nexpected %s\nreceived %s\n", utils.ToJSON(exp), utils.ToJSON(erS.Readers[1]))
|
||||
}
|
||||
}
|
||||
|
||||
func TestErsCfgloadFromJSONCfg(t *testing.T) {
|
||||
tm := 1 * time.Second
|
||||
nm := 1
|
||||
str := "test"
|
||||
str2 := "~test)`"
|
||||
bl := true
|
||||
tms := "1s"
|
||||
fc := []*FCTemplate{{
|
||||
Tag: str,
|
||||
Type: str,
|
||||
Path: str,
|
||||
Filters: []string{str},
|
||||
Value: RSRParsers{},
|
||||
Width: nm,
|
||||
Strip: str,
|
||||
Padding: str,
|
||||
Mandatory: bl,
|
||||
AttributeID: str,
|
||||
NewBranch: bl,
|
||||
Timezone: str,
|
||||
Blocker: bl,
|
||||
Layout: str,
|
||||
CostShiftDigits: nm,
|
||||
RoundingDecimals: &nm,
|
||||
MaskDestID: str,
|
||||
MaskLen: nm,
|
||||
pathSlice: []string{str},
|
||||
}}
|
||||
fc2 := []*FCTemplate{{
|
||||
Tag: str2,
|
||||
Type: utils.MetaTemplate,
|
||||
Path: str2,
|
||||
Filters: []string{str2},
|
||||
Value: RSRParsers{{
|
||||
Rules: str2,
|
||||
path: str2,
|
||||
}},
|
||||
Width: nm,
|
||||
Strip: str2,
|
||||
Padding: str2,
|
||||
Mandatory: bl,
|
||||
AttributeID: str2,
|
||||
NewBranch: bl,
|
||||
Timezone: str2,
|
||||
Blocker: bl,
|
||||
Layout: str2,
|
||||
CostShiftDigits: nm,
|
||||
RoundingDecimals: &nm,
|
||||
MaskDestID: str2,
|
||||
MaskLen: nm,
|
||||
pathSlice: []string{str2},
|
||||
}}
|
||||
er := &EventReaderCfg{
|
||||
ID: str,
|
||||
Type: str,
|
||||
RunDelay: tm,
|
||||
ConcurrentReqs: nm,
|
||||
SourcePath: str,
|
||||
ProcessedPath: str,
|
||||
Opts: &EventReaderOpts{},
|
||||
Tenant: RSRParsers{},
|
||||
Timezone: str,
|
||||
Filters: []string{str},
|
||||
Flags: utils.FlagsWithParams{},
|
||||
Fields: fc,
|
||||
PartialCommitFields: fc2,
|
||||
CacheDumpFields: fc,
|
||||
}
|
||||
fcj := &[]*FcTemplateJsonCfg{}
|
||||
fcj2 := &[]*FcTemplateJsonCfg{
|
||||
{
|
||||
Tag: &str2,
|
||||
Type: &str2,
|
||||
Path: &str2,
|
||||
Attribute_id: &str2,
|
||||
Filters: &[]string{str2},
|
||||
Value: &str2,
|
||||
Width: &nm,
|
||||
Strip: &str2,
|
||||
Padding: &str2,
|
||||
Mandatory: &bl,
|
||||
New_branch: &bl,
|
||||
Timezone: &str2,
|
||||
Blocker: &bl,
|
||||
Layout: &str2,
|
||||
Cost_shift_digits: &nm,
|
||||
Rounding_decimals: &nm,
|
||||
Mask_destinationd_id: &str2,
|
||||
Mask_length: &nm,
|
||||
},
|
||||
}
|
||||
jsnCfg := &EventReaderJsonCfg{
|
||||
Type: &str,
|
||||
Run_delay: &tms,
|
||||
Concurrent_requests: &nm,
|
||||
Source_path: &str,
|
||||
Processed_path: &str,
|
||||
Opts: &EventReaderOptsJson{},
|
||||
Tenant: &str,
|
||||
Timezone: &str,
|
||||
Filters: &[]string{str},
|
||||
Flags: &[]string{str},
|
||||
Fields: fcj,
|
||||
Partial_commit_fields: fcj2,
|
||||
Cache_dump_fields: fcj,
|
||||
}
|
||||
|
||||
err := er.loadFromJSONCfg(jsnCfg, nil, "")
|
||||
|
||||
if err != nil {
|
||||
if err.Error() != "Unclosed unspilit syntax" {
|
||||
t.Error(err)
|
||||
}
|
||||
} else {
|
||||
t.Error("was expecting an error")
|
||||
}
|
||||
|
||||
jsnCfg2 := &EventReaderJsonCfg{
|
||||
Type: &str,
|
||||
Run_delay: &tms,
|
||||
Concurrent_requests: &nm,
|
||||
Source_path: &str,
|
||||
Processed_path: &str,
|
||||
Opts: &EventReaderOptsJson{},
|
||||
Tenant: &str,
|
||||
Timezone: &str,
|
||||
Filters: &[]string{str},
|
||||
Flags: &[]string{str},
|
||||
Fields: fcj,
|
||||
Partial_commit_fields: fcj,
|
||||
Cache_dump_fields: fcj,
|
||||
}
|
||||
msgTemplates := map[string][]*FCTemplate{
|
||||
str2: fc2,
|
||||
}
|
||||
err = er.loadFromJSONCfg(jsnCfg2, msgTemplates, "")
|
||||
|
||||
if err != nil {
|
||||
if err.Error() != "Unclosed unspilit syntax" {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -529,3 +529,27 @@ func TestLockGetLockFilePath(t *testing.T) {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestLoadersCfgGetLockFilePath(t *testing.T) {
|
||||
str := "test"
|
||||
bl := true
|
||||
l := LoaderSCfg{
|
||||
ID: str,
|
||||
Enabled: bl,
|
||||
Tenant: str,
|
||||
DryRun: bl,
|
||||
RunDelay: 1 * time.Second,
|
||||
LockFilePath: str,
|
||||
CacheSConns: []string{str},
|
||||
FieldSeparator: str,
|
||||
TpInDir: str,
|
||||
TpOutDir: str,
|
||||
Data: []*LoaderDataType{},
|
||||
}
|
||||
|
||||
rcv := l.GetLockFilePath()
|
||||
|
||||
if rcv != "test/test" {
|
||||
t.Error(rcv)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -490,3 +490,44 @@ func TestRemoveRPCCons(t *testing.T) {
|
||||
t.Errorf("Expected: %+v\nReceived: %+v", utils.ToJSON(expectedRPCCons), utils.ToJSON(rpc))
|
||||
}
|
||||
}
|
||||
|
||||
func TestRPCConnAsMApInterface(t *testing.T) {
|
||||
str := "test"
|
||||
nm := 1
|
||||
tm := 1 * time.Second
|
||||
bl := true
|
||||
rh := &RemoteHost{
|
||||
ID: str,
|
||||
Address: str,
|
||||
Transport: str,
|
||||
ConnectAttempts: nm,
|
||||
Reconnects: nm,
|
||||
MaxReconnectInterval: tm,
|
||||
ConnectTimeout: tm,
|
||||
ReplyTimeout: tm,
|
||||
TLS: bl,
|
||||
ClientKey: str,
|
||||
ClientCertificate: str,
|
||||
CaCertificate: str,
|
||||
}
|
||||
|
||||
rcv := rh.AsMapInterface()
|
||||
exp := map[string]any{
|
||||
utils.AddressCfg: rh.Address,
|
||||
utils.TransportCfg: rh.Transport,
|
||||
utils.IDCfg: rh.ID,
|
||||
utils.TLSNoCaps: rh.TLS,
|
||||
utils.KeyPathCgr: rh.ClientKey,
|
||||
utils.CertPathCgr: rh.ClientCertificate,
|
||||
utils.CAPathCgr: rh.CaCertificate,
|
||||
utils.ConnectAttemptsCfg: rh.ConnectAttempts,
|
||||
utils.ReconnectsCfg: rh.Reconnects,
|
||||
utils.MaxReconnectIntervalCfg: rh.MaxReconnectInterval,
|
||||
utils.ConnectTimeoutCfg: rh.ConnectTimeout,
|
||||
utils.ReplyTimeoutCfg: rh.ReplyTimeout,
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(rcv, exp) {
|
||||
t.Errorf("\nexpected %s\nreceived %s\n", utils.ToJSON(exp), utils.ToJSON(rcv))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user