Remaked test and case for dumping prefixes for exportEvent

This commit is contained in:
porosnicuadrian
2021-07-07 15:50:58 +03:00
committed by Dan Christian Bogos
parent 3e13436e13
commit 5daad44e32
2 changed files with 52 additions and 10 deletions

View File

@@ -64,7 +64,11 @@ func (eeR *ExportRequest) FieldAsInterface(fldPath []string) (val interface{}, e
return nil, fmt.Errorf("unsupported field prefix: <%s>", fldPath[0])
}
}
val, err = dp.FieldAsInterface(fldPath[1:])
if len(fldPath) != 1 {
val, err = dp.FieldAsInterface(fldPath[1:])
} else {
val = dp
}
case utils.MetaUCH:
var ok bool
if val, ok = Cache.Get(utils.CacheUCH, strings.Join(fldPath[1:], utils.NestingSep)); !ok {

View File

@@ -28,7 +28,7 @@ import (
"github.com/cgrates/cgrates/utils"
)
func TestEventRequestParseFieldDateTimeDaily(t *testing.T) {
func TestExportReqParseFieldDateTimeDaily(t *testing.T) {
EventReq := NewExportRequest(map[string]utils.MapStorage{}, "", nil, nil)
fctTemp := &config.FCTemplate{
Type: utils.MetaDateTime,
@@ -56,7 +56,7 @@ func TestEventRequestParseFieldDateTimeDaily(t *testing.T) {
}
}
func TestEventReqParseFieldDateTimeTimeZone(t *testing.T) {
func TestExportReqParseFieldDateTimeTimeZone(t *testing.T) {
EventReq := NewExportRequest(map[string]utils.MapStorage{}, "", nil, nil)
fctTemp := &config.FCTemplate{
Type: utils.MetaDateTime,
@@ -84,7 +84,7 @@ func TestEventReqParseFieldDateTimeTimeZone(t *testing.T) {
}
}
func TestEventReqParseFieldDateTimeMonthly(t *testing.T) {
func TestExportReqParseFieldDateTimeMonthly(t *testing.T) {
EventReq := NewExportRequest(map[string]utils.MapStorage{}, "", nil, nil)
fctTemp := &config.FCTemplate{
Type: utils.MetaDateTime,
@@ -111,7 +111,7 @@ func TestEventReqParseFieldDateTimeMonthly(t *testing.T) {
}
}
func TestEventReqParseFieldDateTimeMonthlyEstimated(t *testing.T) {
func TestExportReqParseFieldDateTimeMonthlyEstimated(t *testing.T) {
EventReq := NewExportRequest(map[string]utils.MapStorage{}, "", nil, nil)
fctTemp := &config.FCTemplate{
Type: utils.MetaDateTime,
@@ -138,7 +138,7 @@ func TestEventReqParseFieldDateTimeMonthlyEstimated(t *testing.T) {
}
}
func TestEventReqParseFieldDateTimeYearly(t *testing.T) {
func TestExportReqParseFieldDateTimeYearly(t *testing.T) {
EventReq := NewExportRequest(map[string]utils.MapStorage{}, "", nil, nil)
fctTemp := &config.FCTemplate{
Type: utils.MetaDateTime,
@@ -165,7 +165,7 @@ func TestEventReqParseFieldDateTimeYearly(t *testing.T) {
}
}
func TestEventReqParseFieldDateTimeMetaUnlimited(t *testing.T) {
func TestExportReqParseFieldDateTimeMetaUnlimited(t *testing.T) {
EventReq := NewExportRequest(map[string]utils.MapStorage{}, "", nil, nil)
fctTemp := &config.FCTemplate{
Type: utils.MetaDateTime,
@@ -192,7 +192,7 @@ func TestEventReqParseFieldDateTimeMetaUnlimited(t *testing.T) {
}
}
func TestEventReqParseFieldDateTimeEmpty(t *testing.T) {
func TestExportReqParseFieldDateTimeEmpty(t *testing.T) {
EventReq := NewExportRequest(map[string]utils.MapStorage{}, "", nil, nil)
fctTemp := &config.FCTemplate{
Type: utils.MetaDateTime,
@@ -219,7 +219,7 @@ func TestEventReqParseFieldDateTimeEmpty(t *testing.T) {
}
}
func TestEventReqParseFieldDateTimeMonthEnd(t *testing.T) {
func TestExportReqParseFieldDateTimeMonthEnd(t *testing.T) {
EventReq := NewExportRequest(map[string]utils.MapStorage{}, "", nil, nil)
fctTemp := &config.FCTemplate{
Type: utils.MetaDateTime,
@@ -246,7 +246,7 @@ func TestEventReqParseFieldDateTimeMonthEnd(t *testing.T) {
}
}
func TestAgentRequestParseFieldDateTimeError(t *testing.T) {
func TestExportReqParseFieldDateTimeError(t *testing.T) {
EventReq := NewExportRequest(map[string]utils.MapStorage{}, "", nil, nil)
fctTemp := &config.FCTemplate{
Type: utils.MetaDateTime,
@@ -260,3 +260,41 @@ func TestAgentRequestParseFieldDateTimeError(t *testing.T) {
t.Errorf("Expected <%+v> but received <%+v>", expected, err)
}
}
func TestExportReqFieldAsINterfaceOnePath(t *testing.T) {
mS := map[string]utils.MapStorage{
utils.MetaReq: {
utils.AccountField: "1004",
utils.Usage: "20m",
utils.AnswerTime: time.Date(2018, time.January, 7, 16, 60, 0, 0, time.UTC),
},
utils.MetaOpts: {
utils.APIKey: "attr12345",
},
utils.MetaVars: {
utils.RequestType: utils.MetaRated,
utils.Subsystems: utils.MetaChargers,
},
}
eventReq := NewExportRequest(mS, "", nil, nil)
fldPath := []string{utils.MetaReq}
if val, err := eventReq.FieldAsInterface(fldPath); err != nil {
t.Error(err)
} else if !reflect.DeepEqual(val, mS[utils.MetaReq]) {
t.Errorf("Expected %+v \n, received %+v", val, mS[utils.MetaReq])
}
fldPath = []string{utils.MetaOpts}
if val, err := eventReq.FieldAsInterface(fldPath); err != nil {
t.Error(err)
} else if !reflect.DeepEqual(val, mS[utils.MetaOpts]) {
t.Errorf("Expected %+v \n, received %+v", val, mS[utils.MetaOpts])
}
fldPath = []string{utils.MetaVars}
if val, err := eventReq.FieldAsInterface(fldPath); err != nil {
t.Error(err)
} else if !reflect.DeepEqual(val, mS[utils.MetaVars]) {
t.Errorf("Expected %+v \n, received %+v", val, mS[utils.MetaVars])
}
}