From 9c5c10c28f2d4641573d8221e17e87770f3aa5c3 Mon Sep 17 00:00:00 2001 From: TeoV Date: Wed, 9 Aug 2017 11:54:41 -0400 Subject: [PATCH 1/4] Add Test for AsMapStringIface --- engine/cdr_test.go | 82 +++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 78 insertions(+), 4 deletions(-) diff --git a/engine/cdr_test.go b/engine/cdr_test.go index 7d305ec87..f6b66e3ad 100644 --- a/engine/cdr_test.go +++ b/engine/cdr_test.go @@ -1,3 +1,4 @@ + /* Real-time Online/Offline Charging System (OCS) for Telecom & ISP environments Copyright (C) ITsysCOM GmbH @@ -502,11 +503,84 @@ func TestCDRParseFieldValue(t *testing.T) { } } +func TestCDRAsMapStringIface(t *testing.T) { + cdr := &CDR{ + CGRID: utils.Sha1("dsafdsaf", time.Date(2013, 11, 7, 8, 42, 26, 0, time.UTC).String()), + OrderID: 123, + ToR: utils.VOICE, + OriginID: "dsafdsaf", + OriginHost: "192.168.1.1", + Source: utils.UNIT_TEST, + RequestType: utils.META_RATED, + Direction: "*out", + Tenant: "cgrates.org", + Category: "call", + Account: "1002", + Subject: "1001", + Destination: "+4986517174963", + SetupTime: time.Date(2013, 11, 7, 8, 42, 20, 0, time.UTC), + AnswerTime: time.Date(2013, 11, 7, 8, 42, 26, 0, time.UTC), + RunID: utils.DEFAULT_RUNID, + Usage: time.Duration(10) * time.Second, + Supplier: "SUPPL1", + ExtraFields: map[string]string{"field_extr1": "val_extr1", "fieldextr2": "valextr2"}, Cost: 1.01, + } + + var mp = make(map[string]interface{}) + for k, v := range cdr.ExtraFields { + mp[k] = v + } + mp[utils.CGRID] = cdr.CGRID + mp[utils.MEDI_RUNID] = cdr.RunID + mp[utils.ORDERID] = cdr.OrderID + mp[utils.CDRHOST] = cdr.OriginHost + mp[utils.CDRSOURCE] = cdr.Source + mp[utils.ACCID] = cdr.OriginID + mp[utils.TOR] = cdr.ToR + mp[utils.REQTYPE] = cdr.RequestType + mp[utils.DIRECTION] = cdr.Direction + mp[utils.TENANT] = cdr.Tenant + mp[utils.CATEGORY] = cdr.Category + mp[utils.ACCOUNT] = cdr.Account + mp[utils.SUBJECT] = cdr.Subject + mp[utils.DESTINATION] = cdr.Destination + mp[utils.SETUP_TIME] = cdr.SetupTime + mp[utils.PDD] = cdr.PDD + mp[utils.ANSWER_TIME] = cdr.AnswerTime + mp[utils.USAGE] = cdr.Usage + mp[utils.SUPPLIER] = cdr.Supplier + mp[utils.DISCONNECT_CAUSE] = cdr.DisconnectCause + mp[utils.CostSource] = cdr.CostSource + mp[utils.COST] = cdr.Cost + mp[utils.COST_DETAILS] = cdr.CostDetails + mp[utils.ExtraInfo] = cdr.ExtraInfo + mp[utils.RATED] = cdr.Rated + mp[utils.PartialField] = cdr.Partial + + if cdrMp,err := cdr.AsMapStringIface(); err !=nil { + t.Error(err) + }else if !reflect.DeepEqual(mp,cdrMp){ + t.Errorf("Expecting: %+v, received: %+v", mp, cdrMp) + } + +} + func TestCDRAsExportRecord(t *testing.T) { - cdr := &CDR{CGRID: utils.Sha1("dsafdsaf", time.Unix(1383813745, 0).UTC().String()), ToR: utils.VOICE, OriginID: "dsafdsaf", OriginHost: "192.168.1.1", - RequestType: utils.META_RATED, Direction: "*out", Tenant: "cgrates.org", - Category: "call", Account: "1001", Subject: "1001", Destination: "+4986517174963", SetupTime: time.Unix(1383813745, 0).UTC(), AnswerTime: time.Unix(1383813746, 0).UTC(), - Usage: time.Duration(10) * time.Second, RunID: utils.DEFAULT_RUNID, Cost: 1.01, + cdr := &CDR{ + CGRID: utils.Sha1("dsafdsaf", + time.Unix(1383813745, 0).UTC().String()), + ToR: utils.VOICE, OriginID: "dsafdsaf", + OriginHost: "192.168.1.1", + RequestType: utils.META_RATED, + Direction: "*out", Tenant: "cgrates.org", + Category: "call", + Account: "1001", + Subject: "1001", + Destination: "+4986517174963", + SetupTime: time.Unix(1383813745, 0).UTC(), + AnswerTime: time.Unix(1383813746, 0).UTC(), + Usage: time.Duration(10) * time.Second, + RunID: utils.DEFAULT_RUNID, Cost: 1.01, ExtraFields: map[string]string{"stop_time": "2014-06-11 19:19:00 +0000 UTC", "fieldextr2": "valextr2"}} val, _ := utils.ParseRSRFields(utils.DESTINATION, utils.INFIELD_SEP) From 62a7a51a50cfa0e8f14e55651c68024aec7b3dec Mon Sep 17 00:00:00 2001 From: TeoV Date: Wed, 9 Aug 2017 11:59:45 -0400 Subject: [PATCH 2/4] Small fix --- engine/cdr_test.go | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/engine/cdr_test.go b/engine/cdr_test.go index f6b66e3ad..971de80bd 100644 --- a/engine/cdr_test.go +++ b/engine/cdr_test.go @@ -1,4 +1,3 @@ - /* Real-time Online/Offline Charging System (OCS) for Telecom & ISP environments Copyright (C) ITsysCOM GmbH @@ -567,21 +566,21 @@ func TestCDRAsMapStringIface(t *testing.T) { func TestCDRAsExportRecord(t *testing.T) { cdr := &CDR{ - CGRID: utils.Sha1("dsafdsaf", - time.Unix(1383813745, 0).UTC().String()), - ToR: utils.VOICE, OriginID: "dsafdsaf", - OriginHost: "192.168.1.1", - RequestType: utils.META_RATED, - Direction: "*out", Tenant: "cgrates.org", - Category: "call", - Account: "1001", - Subject: "1001", - Destination: "+4986517174963", - SetupTime: time.Unix(1383813745, 0).UTC(), - AnswerTime: time.Unix(1383813746, 0).UTC(), - Usage: time.Duration(10) * time.Second, - RunID: utils.DEFAULT_RUNID, Cost: 1.01, - ExtraFields: map[string]string{"stop_time": "2014-06-11 19:19:00 +0000 UTC", "fieldextr2": "valextr2"}} + CGRID: utils.Sha1("dsafdsaf", + time.Unix(1383813745, 0).UTC().String()), + ToR: utils.VOICE, OriginID: "dsafdsaf", + OriginHost: "192.168.1.1", + RequestType: utils.META_RATED, + Direction: "*out", Tenant: "cgrates.org", + Category: "call", + Account: "1001", + Subject: "1001", + Destination: "+4986517174963", + SetupTime: time.Unix(1383813745, 0).UTC(), + AnswerTime: time.Unix(1383813746, 0).UTC(), + Usage: time.Duration(10) * time.Second, + RunID: utils.DEFAULT_RUNID, Cost: 1.01, + ExtraFields: map[string]string{"stop_time": "2014-06-11 19:19:00 +0000 UTC", "fieldextr2": "valextr2"}} val, _ := utils.ParseRSRFields(utils.DESTINATION, utils.INFIELD_SEP) cfgCdrFld := &config.CfgCdrField{Tag: "destination", Type: utils.META_COMPOSED, FieldId: utils.DESTINATION, Value: val, Timezone: "UTC"} From bd7f2562990e5b79f30a2cdd502623fcc60da784 Mon Sep 17 00:00:00 2001 From: TeoV Date: Thu, 10 Aug 2017 04:20:02 -0400 Subject: [PATCH 3/4] Small fix v2 --- engine/cdr_test.go | 70 +++++++++++++++++++++++----------------------- 1 file changed, 35 insertions(+), 35 deletions(-) diff --git a/engine/cdr_test.go b/engine/cdr_test.go index 971de80bd..66721581f 100644 --- a/engine/cdr_test.go +++ b/engine/cdr_test.go @@ -504,9 +504,9 @@ func TestCDRParseFieldValue(t *testing.T) { func TestCDRAsMapStringIface(t *testing.T) { cdr := &CDR{ - CGRID: utils.Sha1("dsafdsaf", time.Date(2013, 11, 7, 8, 42, 26, 0, time.UTC).String()), + CGRID: utils.Sha1("dsafdsaf", time.Date(2013, 11, 7, 8, 42, 26, 0, time.UTC).String()), OrderID: 123, - ToR: utils.VOICE, + ToR: utils.VOICE, OriginID: "dsafdsaf", OriginHost: "192.168.1.1", Source: utils.UNIT_TEST, @@ -522,46 +522,46 @@ func TestCDRAsMapStringIface(t *testing.T) { RunID: utils.DEFAULT_RUNID, Usage: time.Duration(10) * time.Second, Supplier: "SUPPL1", - ExtraFields: map[string]string{"field_extr1": "val_extr1", "fieldextr2": "valextr2"}, Cost: 1.01, + ExtraFields: map[string]string{"field_extr1": "val_extr1", "fieldextr2": "valextr2"}, + Cost: 1.01, } - var mp = make(map[string]interface{}) - for k, v := range cdr.ExtraFields { - mp[k] = v - } - mp[utils.CGRID] = cdr.CGRID - mp[utils.MEDI_RUNID] = cdr.RunID - mp[utils.ORDERID] = cdr.OrderID - mp[utils.CDRHOST] = cdr.OriginHost - mp[utils.CDRSOURCE] = cdr.Source - mp[utils.ACCID] = cdr.OriginID - mp[utils.TOR] = cdr.ToR - mp[utils.REQTYPE] = cdr.RequestType - mp[utils.DIRECTION] = cdr.Direction - mp[utils.TENANT] = cdr.Tenant - mp[utils.CATEGORY] = cdr.Category - mp[utils.ACCOUNT] = cdr.Account - mp[utils.SUBJECT] = cdr.Subject - mp[utils.DESTINATION] = cdr.Destination - mp[utils.SETUP_TIME] = cdr.SetupTime - mp[utils.PDD] = cdr.PDD - mp[utils.ANSWER_TIME] = cdr.AnswerTime - mp[utils.USAGE] = cdr.Usage - mp[utils.SUPPLIER] = cdr.Supplier - mp[utils.DISCONNECT_CAUSE] = cdr.DisconnectCause - mp[utils.CostSource] = cdr.CostSource - mp[utils.COST] = cdr.Cost - mp[utils.COST_DETAILS] = cdr.CostDetails - mp[utils.ExtraInfo] = cdr.ExtraInfo - mp[utils.RATED] = cdr.Rated - mp[utils.PartialField] = cdr.Partial - + mp := map[string]interface{} { + "field_extr1": "val_extr1", + "fieldextr2": "valextr2", + utils.CGRID: cdr.CGRID, + utils.MEDI_RUNID: utils.DEFAULT_RUNID, + utils.ORDERID: cdr.OrderID, + utils.CDRHOST: "192.168.1.1", + utils.CDRSOURCE: utils.UNIT_TEST, + utils.ACCID: "dsafdsaf", + utils.TOR: utils.VOICE, + utils.REQTYPE: utils.META_RATED, + utils.DIRECTION: "*out", + utils.TENANT: "cgrates.org", + utils.CATEGORY: "call", + utils.ACCOUNT: "1002", + utils.SUBJECT: "1001", + utils.DESTINATION: "+4986517174963", + utils.SETUP_TIME: time.Date(2013, 11, 7, 8, 42, 20, 0, time.UTC), + utils.PDD: time.Duration(0) * time.Second, + utils.ANSWER_TIME: time.Date(2013, 11, 7, 8, 42, 26, 0, time.UTC), + utils.USAGE: time.Duration(10) * time.Second, + utils.SUPPLIER: "SUPPL1", + utils.DISCONNECT_CAUSE:cdr.DisconnectCause, + utils.CostSource: cdr.CostSource, + utils.COST: 1.01, + utils.COST_DETAILS: cdr.CostDetails, + utils.RATED: false, + utils.PartialField: false, + utils.ExtraInfo:cdr.ExtraInfo, +} if cdrMp,err := cdr.AsMapStringIface(); err !=nil { t.Error(err) }else if !reflect.DeepEqual(mp,cdrMp){ t.Errorf("Expecting: %+v, received: %+v", mp, cdrMp) } - + } func TestCDRAsExportRecord(t *testing.T) { From 14033f7a627d60204069f1164bc09153d3c1227d Mon Sep 17 00:00:00 2001 From: TeoV Date: Thu, 10 Aug 2017 07:46:19 -0400 Subject: [PATCH 4/4] Small fix v3 --- engine/cdr_test.go | 128 ++++++++++++++++++++++----------------------- 1 file changed, 64 insertions(+), 64 deletions(-) diff --git a/engine/cdr_test.go b/engine/cdr_test.go index 66721581f..2a645dd7e 100644 --- a/engine/cdr_test.go +++ b/engine/cdr_test.go @@ -504,61 +504,61 @@ func TestCDRParseFieldValue(t *testing.T) { func TestCDRAsMapStringIface(t *testing.T) { cdr := &CDR{ - CGRID: utils.Sha1("dsafdsaf", time.Date(2013, 11, 7, 8, 42, 26, 0, time.UTC).String()), - OrderID: 123, - ToR: utils.VOICE, - OriginID: "dsafdsaf", - OriginHost: "192.168.1.1", - Source: utils.UNIT_TEST, + CGRID: utils.Sha1("dsafdsaf", time.Date(2013, 11, 7, 8, 42, 26, 0, time.UTC).String()), + OrderID: 123, + ToR: utils.VOICE, + OriginID: "dsafdsaf", + OriginHost: "192.168.1.1", + Source: utils.UNIT_TEST, RequestType: utils.META_RATED, - Direction: "*out", - Tenant: "cgrates.org", - Category: "call", - Account: "1002", - Subject: "1001", + Direction: "*out", + Tenant: "cgrates.org", + Category: "call", + Account: "1002", + Subject: "1001", Destination: "+4986517174963", - SetupTime: time.Date(2013, 11, 7, 8, 42, 20, 0, time.UTC), - AnswerTime: time.Date(2013, 11, 7, 8, 42, 26, 0, time.UTC), - RunID: utils.DEFAULT_RUNID, - Usage: time.Duration(10) * time.Second, - Supplier: "SUPPL1", + SetupTime: time.Date(2013, 11, 7, 8, 42, 20, 0, time.UTC), + AnswerTime: time.Date(2013, 11, 7, 8, 42, 26, 0, time.UTC), + RunID: utils.DEFAULT_RUNID, + Usage: time.Duration(10) * time.Second, + Supplier: "SUPPL1", ExtraFields: map[string]string{"field_extr1": "val_extr1", "fieldextr2": "valextr2"}, - Cost: 1.01, + Cost: 1.01, } - mp := map[string]interface{} { - "field_extr1": "val_extr1", - "fieldextr2": "valextr2", - utils.CGRID: cdr.CGRID, - utils.MEDI_RUNID: utils.DEFAULT_RUNID, - utils.ORDERID: cdr.OrderID, - utils.CDRHOST: "192.168.1.1", - utils.CDRSOURCE: utils.UNIT_TEST, - utils.ACCID: "dsafdsaf", - utils.TOR: utils.VOICE, - utils.REQTYPE: utils.META_RATED, - utils.DIRECTION: "*out", - utils.TENANT: "cgrates.org", - utils.CATEGORY: "call", - utils.ACCOUNT: "1002", - utils.SUBJECT: "1001", - utils.DESTINATION: "+4986517174963", - utils.SETUP_TIME: time.Date(2013, 11, 7, 8, 42, 20, 0, time.UTC), - utils.PDD: time.Duration(0) * time.Second, - utils.ANSWER_TIME: time.Date(2013, 11, 7, 8, 42, 26, 0, time.UTC), - utils.USAGE: time.Duration(10) * time.Second, - utils.SUPPLIER: "SUPPL1", - utils.DISCONNECT_CAUSE:cdr.DisconnectCause, - utils.CostSource: cdr.CostSource, - utils.COST: 1.01, - utils.COST_DETAILS: cdr.CostDetails, - utils.RATED: false, - utils.PartialField: false, - utils.ExtraInfo:cdr.ExtraInfo, -} - if cdrMp,err := cdr.AsMapStringIface(); err !=nil { + mp := map[string]interface{}{ + "field_extr1": "val_extr1", + "fieldextr2": "valextr2", + utils.CGRID: cdr.CGRID, + utils.MEDI_RUNID: utils.DEFAULT_RUNID, + utils.ORDERID: cdr.OrderID, + utils.CDRHOST: "192.168.1.1", + utils.CDRSOURCE: utils.UNIT_TEST, + utils.ACCID: "dsafdsaf", + utils.TOR: utils.VOICE, + utils.REQTYPE: utils.META_RATED, + utils.DIRECTION: "*out", + utils.TENANT: "cgrates.org", + utils.CATEGORY: "call", + utils.ACCOUNT: "1002", + utils.SUBJECT: "1001", + utils.DESTINATION: "+4986517174963", + utils.SETUP_TIME: time.Date(2013, 11, 7, 8, 42, 20, 0, time.UTC), + utils.PDD: time.Duration(0) * time.Second, + utils.ANSWER_TIME: time.Date(2013, 11, 7, 8, 42, 26, 0, time.UTC), + utils.USAGE: time.Duration(10) * time.Second, + utils.SUPPLIER: "SUPPL1", + utils.DISCONNECT_CAUSE: cdr.DisconnectCause, + utils.CostSource: cdr.CostSource, + utils.COST: 1.01, + utils.COST_DETAILS: cdr.CostDetails, + utils.RATED: false, + utils.PartialField: false, + utils.ExtraInfo: cdr.ExtraInfo, + } + if cdrMp, err := cdr.AsMapStringIface(); err != nil { t.Error(err) - }else if !reflect.DeepEqual(mp,cdrMp){ + } else if !reflect.DeepEqual(mp, cdrMp) { t.Errorf("Expecting: %+v, received: %+v", mp, cdrMp) } @@ -566,21 +566,21 @@ func TestCDRAsMapStringIface(t *testing.T) { func TestCDRAsExportRecord(t *testing.T) { cdr := &CDR{ - CGRID: utils.Sha1("dsafdsaf", - time.Unix(1383813745, 0).UTC().String()), - ToR: utils.VOICE, OriginID: "dsafdsaf", - OriginHost: "192.168.1.1", - RequestType: utils.META_RATED, - Direction: "*out", Tenant: "cgrates.org", - Category: "call", - Account: "1001", - Subject: "1001", - Destination: "+4986517174963", - SetupTime: time.Unix(1383813745, 0).UTC(), - AnswerTime: time.Unix(1383813746, 0).UTC(), - Usage: time.Duration(10) * time.Second, - RunID: utils.DEFAULT_RUNID, Cost: 1.01, - ExtraFields: map[string]string{"stop_time": "2014-06-11 19:19:00 +0000 UTC", "fieldextr2": "valextr2"}} + CGRID: utils.Sha1("dsafdsaf", + time.Unix(1383813745, 0).UTC().String()), + ToR: utils.VOICE, OriginID: "dsafdsaf", + OriginHost: "192.168.1.1", + RequestType: utils.META_RATED, + Direction: "*out", Tenant: "cgrates.org", + Category: "call", + Account: "1001", + Subject: "1001", + Destination: "+4986517174963", + SetupTime: time.Unix(1383813745, 0).UTC(), + AnswerTime: time.Unix(1383813746, 0).UTC(), + Usage: time.Duration(10) * time.Second, + RunID: utils.DEFAULT_RUNID, Cost: 1.01, + ExtraFields: map[string]string{"stop_time": "2014-06-11 19:19:00 +0000 UTC", "fieldextr2": "valextr2"}} val, _ := utils.ParseRSRFields(utils.DESTINATION, utils.INFIELD_SEP) cfgCdrFld := &config.CfgCdrField{Tag: "destination", Type: utils.META_COMPOSED, FieldId: utils.DESTINATION, Value: val, Timezone: "UTC"}