Skip to content

Commit

Permalink
fixing unit tests on ersCfg
Browse files Browse the repository at this point in the history
  • Loading branch information
gezimbll authored and danbogos committed Mar 13, 2024
1 parent 66940db commit cff5d22
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 51 deletions.
7 changes: 4 additions & 3 deletions config/config_json_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2019,9 +2019,10 @@ func TestDfEventReaderCfg(t *testing.T) {
Value: utils.StringPointer("~*req.13"), Mandatory: utils.BoolPointer(true)},
}
eCfg := &ERsJsonCfg{
Enabled: utils.BoolPointer(false),
Sessions_conns: &[]string{utils.MetaInternal},
Ees_conns: &[]string{},
Enabled: utils.BoolPointer(false),
Sessions_conns: &[]string{utils.MetaInternal},
Ees_conns: &[]string{},
Concurrent_events: utils.IntPointer(1),
Readers: &[]*EventReaderJsonCfg{
{
Id: utils.StringPointer(utils.MetaDefault),
Expand Down
25 changes: 14 additions & 11 deletions config/config_test.go

Large diffs are not rendered by default.

21 changes: 11 additions & 10 deletions config/erscfg.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,6 @@ func (erS *ERsCfg) loadFromJSONCfg(jsnCfg *ERsJsonCfg, msgTemplates map[string][
erS.Enabled = *jsnCfg.Enabled
}

if jsnCfg.Concurrent_events != nil {
erS.ConcurrentEvents = *jsnCfg.Concurrent_events
if erS.ConcurrentEvents < 1 {
erS.ConcurrentEvents = 1
}
}

if jsnCfg.Sessions_conns != nil {
erS.SessionSConns = make([]string, 0, len(*jsnCfg.Sessions_conns))
for _, fID := range *jsnCfg.Sessions_conns {
Expand All @@ -74,6 +67,14 @@ func (erS *ERsCfg) loadFromJSONCfg(jsnCfg *ERsJsonCfg, msgTemplates map[string][
}
}
}

if jsnCfg.Concurrent_events != nil {
erS.ConcurrentEvents = *jsnCfg.Concurrent_events
if erS.ConcurrentEvents < 1 {
erS.ConcurrentEvents = 1
}
}

if jsnCfg.Partial_cache_ttl != nil {
if erS.PartialCacheTTL, err = utils.ParseDurationWithNanosecs(*jsnCfg.Partial_cache_ttl); err != nil {
return
Expand Down Expand Up @@ -133,9 +134,9 @@ func (erS *ERsCfg) Clone() (cln *ERsCfg) {
// AsMapInterface returns the config as a map[string]any
func (erS *ERsCfg) AsMapInterface(separator string) (initialMP map[string]any) {
initialMP = map[string]any{
utils.EnabledCfg: erS.Enabled,
utils.ConcurrentEvents: erS.ConcurrentEvents,
utils.PartialCacheTTLCfg: "0",
utils.EnabledCfg: erS.Enabled,
utils.ConcurrentEventsCfg: erS.ConcurrentEvents,
utils.PartialCacheTTLCfg: "0",
}
if erS.PartialCacheTTL != 0 {
initialMP[utils.PartialCacheTTLCfg] = erS.PartialCacheTTL.String()
Expand Down
61 changes: 35 additions & 26 deletions config/erscfg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,10 @@ func TestERSClone(t *testing.T) {
}
}`
expectedERsCfg := &ERsCfg{
Enabled: true,
SessionSConns: []string{"*internal:*sessions"},
EEsConns: []string{},
Enabled: true,
SessionSConns: []string{"*internal:*sessions"},
EEsConns: []string{},
ConcurrentEvents: 1,
Readers: []*EventReaderCfg{
{
ID: utils.MetaDefault,
Expand Down Expand Up @@ -235,9 +236,10 @@ func TestEventReaderloadFromJsonCase3(t *testing.T) {

func TestERSLoadFromjsonCfg(t *testing.T) {
expectedERsCfg := &ERsCfg{
Enabled: true,
SessionSConns: []string{"conn1", "conn3"},
EEsConns: []string{},
Enabled: true,
SessionSConns: []string{"conn1", "conn3"},
EEsConns: []string{},
ConcurrentEvents: 1,
Readers: []*EventReaderCfg{
{
ID: utils.MetaDefault,
Expand Down Expand Up @@ -460,8 +462,9 @@ func TestERSloadFromJsonCase2(t *testing.T) {

func TestERSloadFromJsonCase3(t *testing.T) {
cfgJSON := &ERsJsonCfg{
Enabled: utils.BoolPointer(true),
Sessions_conns: &[]string{"*conn1"},
Enabled: utils.BoolPointer(true),
Sessions_conns: &[]string{"*conn1"},
Concurrent_events: utils.IntPointer(1),
Readers: &[]*EventReaderJsonCfg{
{
Id: utils.StringPointer("file_reader1"),
Expand Down Expand Up @@ -489,9 +492,10 @@ func TestERSloadFromJsonCase3(t *testing.T) {
},
}
expectedERsCfg := &ERsCfg{
Enabled: true,
SessionSConns: []string{"*conn1"},
EEsConns: []string{},
Enabled: true,
SessionSConns: []string{"*conn1"},
EEsConns: []string{},
ConcurrentEvents: 1,
Readers: []*EventReaderCfg{
{
ID: utils.MetaDefault,
Expand Down Expand Up @@ -649,9 +653,10 @@ func TestERSloadFromJsonCase4(t *testing.T) {
},
}
expectedERsCfg := &ERsCfg{
Enabled: true,
SessionSConns: []string{"*conn1"},
EEsConns: []string{},
Enabled: true,
SessionSConns: []string{"*conn1"},
EEsConns: []string{},
ConcurrentEvents: 1,
Readers: []*EventReaderCfg{
{
ID: utils.MetaDefault,
Expand Down Expand Up @@ -802,9 +807,10 @@ func TestEventReaderCacheDumpFieldsloadFromJsonCfg(t *testing.T) {

func TestEventReaderSameID(t *testing.T) {
expectedERsCfg := &ERsCfg{
Enabled: true,
SessionSConns: []string{"conn1"},
EEsConns: []string{},
Enabled: true,
SessionSConns: []string{"conn1"},
EEsConns: []string{},
ConcurrentEvents: 1,
Readers: []*EventReaderCfg{
{
ID: utils.MetaDefault,
Expand Down Expand Up @@ -974,9 +980,10 @@ func TestERsCfgAsMapInterfaceCase1(t *testing.T) {
}
}`
eMap := map[string]any{
utils.EnabledCfg: true,
utils.SessionSConnsCfg: []string{"conn1", "conn3"},
utils.EEsConnsCfg: []string{},
utils.EnabledCfg: true,
utils.SessionSConnsCfg: []string{"conn1", "conn3"},
utils.EEsConnsCfg: []string{},
utils.ConcurrentEventsCfg: 1,
utils.ReadersCfg: []map[string]any{
{
utils.FiltersCfg: []string{},
Expand Down Expand Up @@ -1119,9 +1126,10 @@ func TestERSCfgAsMapInterfaceCase2(t *testing.T) {
}
}`
eMap := map[string]any{
utils.EnabledCfg: true,
utils.SessionSConnsCfg: []string{"conn1", "conn3"},
utils.EEsConnsCfg: []string{},
utils.EnabledCfg: true,
utils.SessionSConnsCfg: []string{"conn1", "conn3"},
utils.EEsConnsCfg: []string{},
utils.ConcurrentEventsCfg: 1,
utils.ReadersCfg: []map[string]any{
{
utils.FiltersCfg: []string{},
Expand Down Expand Up @@ -1272,9 +1280,10 @@ func TestERsloadFromJsonCfg(t *testing.T) {
},
}
expectedERsCfg := &ERsCfg{
Enabled: true,
SessionSConns: []string{"*conn1"},
EEsConns: []string{},
Enabled: true,
SessionSConns: []string{"*conn1"},
EEsConns: []string{},
ConcurrentEvents: 1,
Readers: []*EventReaderCfg{
{
ID: utils.MetaDefault,
Expand Down
2 changes: 1 addition & 1 deletion utils/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -2449,7 +2449,7 @@ const (
const (
IDCfg = "id"
CacheCfg = "cache"
ConcurrentEvents = "concurrent_events"
ConcurrentEventsCfg = "concurrent_events"
FieldSepCfg = "field_separator"
RunDelayCfg = "run_delay"
SourcePathCfg = "source_path"
Expand Down

0 comments on commit cff5d22

Please sign in to comment.