mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Added more tests for empty fields in ees
This commit is contained in:
committed by
Dan Christian Bogos
parent
45204cec17
commit
4e80f5e703
@@ -205,6 +205,25 @@ func testElasticExportEvents(t *testing.T) {
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
eventSMSNoFields := &utils.CGREventWithOpts{
|
||||
CGREvent: &utils.CGREvent{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "SMSEvent",
|
||||
Time: utils.TimePointer(time.Now()),
|
||||
Event: map[string]interface{}{
|
||||
utils.CGRID: utils.Sha1("sms2", time.Unix(1383813745, 0).UTC().String()),
|
||||
utils.ToR: utils.SMS,
|
||||
utils.Tenant: "cgrates.org",
|
||||
utils.Category: "call",
|
||||
utils.Account: "1001",
|
||||
utils.Subject: "1001",
|
||||
utils.Destination: "1002",
|
||||
utils.RunID: utils.MetaDefault,
|
||||
"ExporterUsed": "ElasticExporterWithNoFields",
|
||||
},
|
||||
},
|
||||
}
|
||||
var reply map[string]utils.MapStorage
|
||||
if err := elasticRpc.Call(utils.EventExporterSv1ProcessEvent, eventVoice, &reply); err != nil {
|
||||
t.Error(err)
|
||||
@@ -215,6 +234,9 @@ func testElasticExportEvents(t *testing.T) {
|
||||
if err := elasticRpc.Call(utils.EventExporterSv1ProcessEvent, eventSMS, &reply); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if err := elasticRpc.Call(utils.EventExporterSv1ProcessEvent, eventSMSNoFields, &reply); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func testElasticVerifyExports(t *testing.T) {
|
||||
@@ -301,6 +323,21 @@ func testElasticVerifyExports(t *testing.T) {
|
||||
if !reflect.DeepEqual(eMp, hit.(map[string]interface{})["_source"]) {
|
||||
t.Errorf("Expected %+v, received: %+v", eMp, hit.(map[string]interface{})["_source"])
|
||||
}
|
||||
case utils.Sha1("sms2", time.Unix(1383813745, 0).UTC().String()) + ":*default":
|
||||
eMp := map[string]interface{}{
|
||||
utils.CGRID: utils.Sha1("sms2", time.Unix(1383813745, 0).UTC().String()),
|
||||
utils.ToR: utils.SMS,
|
||||
utils.Tenant: "cgrates.org",
|
||||
utils.Category: "call",
|
||||
utils.Account: "1001",
|
||||
utils.Subject: "1001",
|
||||
utils.Destination: "1002",
|
||||
utils.RunID: utils.MetaDefault,
|
||||
"ExporterUsed": "ElasticExporterWithNoFields",
|
||||
}
|
||||
if !reflect.DeepEqual(eMp, hit.(map[string]interface{})["_source"]) {
|
||||
t.Errorf("Expected %+v, received: %+v", eMp, hit.(map[string]interface{})["_source"])
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -102,6 +102,10 @@ func (fCsv *FileCSVee) ExportEvent(cgrEv *utils.CGREvent) (err error) {
|
||||
fCsv.Unlock()
|
||||
}()
|
||||
fCsv.dc[utils.NumberOfEvents] = fCsv.dc[utils.NumberOfEvents].(int64) + 1
|
||||
fields := fCsv.cgrCfg.EEsCfg().Exporters[fCsv.cfgIdx].ContentFields()
|
||||
if len(fields) == 0 { // use the default fields in case of empty fields for exporter
|
||||
fields = fCsv.cgrCfg.EEsCfg().GetDefaultExporter().ContentFields()
|
||||
}
|
||||
|
||||
var csvRecord []string
|
||||
req := utils.MapStorage(cgrEv.Event)
|
||||
@@ -111,7 +115,7 @@ func (fCsv *FileCSVee) ExportEvent(cgrEv *utils.CGREvent) (err error) {
|
||||
fCsv.cgrCfg.GeneralCfg().DefaultTimezone),
|
||||
fCsv.filterS)
|
||||
|
||||
if err = eeReq.SetFields(fCsv.cgrCfg.EEsCfg().Exporters[fCsv.cfgIdx].ContentFields()); err != nil {
|
||||
if err = eeReq.SetFields(fields); err != nil {
|
||||
return
|
||||
}
|
||||
for el := eeReq.cnt.GetFirstElement(); el != nil; el = el.Next() {
|
||||
|
||||
@@ -74,30 +74,35 @@ func (httpPost *HTTPPost) ExportEvent(cgrEv *utils.CGREvent) (err error) {
|
||||
httpPost.dc[utils.NumberOfEvents] = httpPost.dc[utils.NumberOfEvents].(int64) + 1
|
||||
|
||||
urlVals := url.Values{}
|
||||
req := utils.MapStorage(cgrEv.Event)
|
||||
eeReq := NewEventExporterRequest(req, httpPost.dc,
|
||||
httpPost.cgrCfg.EEsCfg().Exporters[httpPost.cfgIdx].Tenant,
|
||||
httpPost.cgrCfg.GeneralCfg().DefaultTenant,
|
||||
utils.FirstNonEmpty(httpPost.cgrCfg.EEsCfg().Exporters[httpPost.cfgIdx].Timezone,
|
||||
httpPost.cgrCfg.GeneralCfg().DefaultTimezone),
|
||||
httpPost.filterS)
|
||||
|
||||
if err = eeReq.SetFields(httpPost.cgrCfg.EEsCfg().Exporters[httpPost.cfgIdx].ContentFields()); err != nil {
|
||||
return
|
||||
}
|
||||
for el := eeReq.cnt.GetFirstElement(); el != nil; el = el.Next() {
|
||||
var nmIt utils.NMInterface
|
||||
if nmIt, err = eeReq.cnt.Field(el.Value); err != nil {
|
||||
if len(httpPost.cgrCfg.EEsCfg().Exporters[httpPost.cfgIdx].ContentFields()) == 0 {
|
||||
for k, v := range cgrEv.Event {
|
||||
urlVals.Set(k, utils.IfaceAsString(v))
|
||||
}
|
||||
} else {
|
||||
req := utils.MapStorage(cgrEv.Event)
|
||||
eeReq := NewEventExporterRequest(req, httpPost.dc,
|
||||
httpPost.cgrCfg.EEsCfg().Exporters[httpPost.cfgIdx].Tenant,
|
||||
httpPost.cgrCfg.GeneralCfg().DefaultTenant,
|
||||
utils.FirstNonEmpty(httpPost.cgrCfg.EEsCfg().Exporters[httpPost.cfgIdx].Timezone,
|
||||
httpPost.cgrCfg.GeneralCfg().DefaultTimezone),
|
||||
httpPost.filterS)
|
||||
if err = eeReq.SetFields(httpPost.cgrCfg.EEsCfg().Exporters[httpPost.cfgIdx].ContentFields()); err != nil {
|
||||
return
|
||||
}
|
||||
itm, isNMItem := nmIt.(*config.NMItem)
|
||||
if !isNMItem {
|
||||
return fmt.Errorf("cannot encode reply value: %s, err: not NMItems", utils.ToJSON(el.Value))
|
||||
for el := eeReq.cnt.GetFirstElement(); el != nil; el = el.Next() {
|
||||
var nmIt utils.NMInterface
|
||||
if nmIt, err = eeReq.cnt.Field(el.Value); err != nil {
|
||||
return
|
||||
}
|
||||
itm, isNMItem := nmIt.(*config.NMItem)
|
||||
if !isNMItem {
|
||||
return fmt.Errorf("cannot encode reply value: %s, err: not NMItems", utils.ToJSON(el.Value))
|
||||
}
|
||||
if itm == nil {
|
||||
continue // all attributes, not writable to diameter packet
|
||||
}
|
||||
urlVals.Set(strings.Join(itm.Path, utils.NestingSep), utils.IfaceAsString(itm.Data))
|
||||
}
|
||||
if itm == nil {
|
||||
continue // all attributes, not writable to diameter packet
|
||||
}
|
||||
urlVals.Set(strings.Join(itm.Path, utils.NestingSep), utils.IfaceAsString(itm.Data))
|
||||
}
|
||||
updateEEMetrics(httpPost.dc, cgrEv.Event, httpPost.cgrCfg.GeneralCfg().DefaultTimezone)
|
||||
if err = httpPost.httpPoster.PostValues(urlVals); err != nil &&
|
||||
|
||||
@@ -200,6 +200,28 @@ func testHTTPExportEvent(t *testing.T) {
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
eventSMSNoFields := &utils.CGREventWithOpts{
|
||||
CGREvent: &utils.CGREvent{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "SMSEvent",
|
||||
Time: utils.TimePointer(time.Now()),
|
||||
Event: map[string]interface{}{
|
||||
utils.CGRID: utils.Sha1("sms2", time.Unix(1383813745, 0).UTC().String()),
|
||||
utils.ToR: utils.SMS,
|
||||
utils.OriginID: "sms2",
|
||||
utils.RequestType: utils.META_RATED,
|
||||
utils.Tenant: "cgrates.org",
|
||||
utils.Category: "call",
|
||||
utils.Account: "1001",
|
||||
utils.Subject: "1001",
|
||||
utils.Destination: "1002",
|
||||
utils.RunID: utils.MetaDefault,
|
||||
"ExporterUsed": "HTTPPostExporterWithNoFields",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
var reply map[string]utils.MapStorage
|
||||
if err := httpPostRpc.Call(utils.EventExporterSv1ProcessEvent, eventVoice, &reply); err != nil {
|
||||
t.Error(err)
|
||||
@@ -255,4 +277,14 @@ func testHTTPExportEvent(t *testing.T) {
|
||||
t.Errorf("Expected %+v, received: %+v", strVal, rcv)
|
||||
}
|
||||
}
|
||||
if err := httpPostRpc.Call(utils.EventExporterSv1ProcessEvent, eventSMSNoFields, &reply); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
time.Sleep(10 * time.Millisecond)
|
||||
// verify HTTPValues for eventSMS
|
||||
for key, strVal := range eventSMSNoFields.Event {
|
||||
if rcv := httpValues.Get(key); rcv != strVal {
|
||||
t.Errorf("Expected %+v, received: %+v", strVal, rcv)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user