From ac822e117f1bcb56b3978007b66677fbf510f4ca Mon Sep 17 00:00:00 2001 From: adragusin Date: Fri, 3 Apr 2020 09:03:22 +0300 Subject: [PATCH] Added test after RoundingDecimal update --- config/fctemplate_test.go | 66 +++++++++++++++++++ engine/cdr_test.go | 133 -------------------------------------- 2 files changed, 66 insertions(+), 133 deletions(-) diff --git a/config/fctemplate_test.go b/config/fctemplate_test.go index 13f0a5ad6..b5b776006 100755 --- a/config/fctemplate_test.go +++ b/config/fctemplate_test.go @@ -315,3 +315,69 @@ func TestFCTemplateClone(t *testing.T) { t.Errorf("expected: %s ,received: %s", utils.ToJSON(initialSmpl), utils.ToJSON(cloned)) } } + +func TestRoundingDecimals(t *testing.T) { + jsonCfg := &FcTemplateJsonCfg{ + Tag: utils.StringPointer("Tenant"), + Type: utils.StringPointer("*composed"), + Path: utils.StringPointer("Tenant"), + Filters: &[]string{"Filter1", "Filter2"}, + Value: utils.StringPointer("cgrates.org"), + } + expected := &FCTemplate{ + Tag: "Tenant", + Type: "*composed", + Path: "Tenant", + Filters: []string{"Filter1", "Filter2"}, + Value: NewRSRParsersMustCompile("cgrates.org", true, utils.INFIELD_SEP), + RoundingDecimals: 5, + } + if rcv, err := NewFCTemplateFromFCTemplateJsonCfg(jsonCfg, utils.INFIELD_SEP, 5); err != nil { + t.Error(err) + } else if !reflect.DeepEqual(expected, rcv) { + t.Errorf("expected: %s\n ,received: %s", utils.ToJSON(expected), utils.ToJSON(rcv)) + } + + jsonCfg = &FcTemplateJsonCfg{ + Tag: utils.StringPointer("Tenant"), + Type: utils.StringPointer("*composed"), + Path: utils.StringPointer("Tenant"), + Filters: &[]string{"Filter1", "Filter2"}, + Value: utils.StringPointer("cgrates.org"), + Rounding_decimals: utils.IntPointer(3), + } + expected = &FCTemplate{ + Tag: "Tenant", + Type: "*composed", + Path: "Tenant", + Filters: []string{"Filter1", "Filter2"}, + Value: NewRSRParsersMustCompile("cgrates.org", true, utils.INFIELD_SEP), + RoundingDecimals: 3, + } + if rcv, err := NewFCTemplateFromFCTemplateJsonCfg(jsonCfg, utils.INFIELD_SEP, 5); err != nil { + t.Error(err) + } else if !reflect.DeepEqual(expected, rcv) { + t.Errorf("expected: %s\n ,received: %s", utils.ToJSON(expected), utils.ToJSON(rcv)) + } + + jsonCfg = &FcTemplateJsonCfg{ + Tag: utils.StringPointer("Tenant"), + Type: utils.StringPointer("*composed"), + Path: utils.StringPointer("Tenant"), + Filters: &[]string{"Filter1", "Filter2"}, + Value: utils.StringPointer("cgrates.org"), + } + expected = &FCTemplate{ + Tag: "Tenant", + Type: "*composed", + Path: "Tenant", + Filters: []string{"Filter1", "Filter2"}, + Value: NewRSRParsersMustCompile("cgrates.org", true, utils.INFIELD_SEP), + RoundingDecimals: 0, + } + if rcv, err := NewFCTemplateFromFCTemplateJsonCfg(jsonCfg, utils.INFIELD_SEP, 0); err != nil { + t.Error(err) + } else if !reflect.DeepEqual(expected, rcv) { + t.Errorf("expected: %s\n ,received: %s", utils.ToJSON(expected), utils.ToJSON(rcv)) + } +} diff --git a/engine/cdr_test.go b/engine/cdr_test.go index ed0149da6..0ba52bf20 100644 --- a/engine/cdr_test.go +++ b/engine/cdr_test.go @@ -1149,136 +1149,3 @@ func TestCDRexportFieldValue(t *testing.T) { } } - -// don't run this test -func testCDReRoundingDecimals(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, - Tenant: "cgrates.org", - Category: "call", - Account: "1001", - 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.MetaDefault, - Usage: time.Duration(10) * time.Second, - Cost: 1.32165, - ExtraFields: map[string]string{"field_extr1": "val_extr1", "fieldextr2": "valextr2"}, - } - - cfgCdrFld := &config.FCTemplate{ - Path: "*exp.Cost", - Type: utils.META_COMPOSED, - Value: config.NewRSRParsersMustCompile("~SetupTime", true, utils.INFIELD_SEP), - RoundingDecimals: 0, - } - - //5 is the default value for rounding decimals - eVal := "1.32165" - if val, err := cdr.exportFieldValue(cfgCdrFld, nil); err != nil { - t.Error(err) - } else if val != eVal { - t.Errorf("Expecting: %+v, received: %+v", eVal, val) - } - - cfgCdrFld.RoundingDecimals = 0 - config.CgrConfig().GeneralCfg().RoundingDecimals = 4 - eVal = "1.3216" - if val, err := cdr.exportFieldValue(cfgCdrFld, nil); err != nil { - t.Error(err) - } else if val != eVal { - t.Errorf("Expecting: %+v, received: %+v", eVal, val) - } - - config.CgrConfig().GeneralCfg().RoundingDecimals = 2 - eVal = "1.3216" - if val, err := cdr.exportFieldValue(cfgCdrFld, nil); err != nil { - t.Error(err) - } else if val != eVal { - t.Errorf("Expecting: %+v, received: %+v", eVal, val) - } - - cfgCdrFld.RoundingDecimals = 0 - config.CgrConfig().GeneralCfg().RoundingDecimals = 3 - eVal = "1.322" - if val, err := cdr.exportFieldValue(cfgCdrFld, nil); err != nil { - t.Error(err) - } else if val != eVal { - t.Errorf("Expecting: %+v, received: %+v", eVal, val) - } - - config.CgrConfig().GeneralCfg().RoundingDecimals = 1 - eVal = "1.322" - if val, err := cdr.exportFieldValue(cfgCdrFld, nil); err != nil { - t.Error(err) - } else if val != eVal { - t.Errorf("Expecting: %+v, received: %+v", eVal, val) - } - - cfgCdrFld.RoundingDecimals = 0 - config.CgrConfig().GeneralCfg().RoundingDecimals = 2 - eVal = "1.32" - if val, err := cdr.exportFieldValue(cfgCdrFld, nil); err != nil { - t.Error(err) - } else if val != eVal { - t.Errorf("Expecting: %+v, received: %+v", eVal, val) - } - - config.CgrConfig().GeneralCfg().RoundingDecimals = 4 - eVal = "1.32" - if val, err := cdr.exportFieldValue(cfgCdrFld, nil); err != nil { - t.Error(err) - } else if val != eVal { - t.Errorf("Expecting: %+v, received: %+v", eVal, val) - } - - cfgCdrFld.RoundingDecimals = 0 - config.CgrConfig().GeneralCfg().RoundingDecimals = 1 - eVal = "1.3" - if val, err := cdr.exportFieldValue(cfgCdrFld, nil); err != nil { - t.Error(err) - } else if val != eVal { - t.Errorf("Expecting: %+v, received: %+v", eVal, val) - } - - config.CgrConfig().GeneralCfg().RoundingDecimals = 4 - eVal = "1.3" - if val, err := cdr.exportFieldValue(cfgCdrFld, nil); err != nil { - t.Error(err) - } else if val != eVal { - t.Errorf("Expecting: %+v, received: %+v", eVal, val) - } - - cfgCdrFld.RoundingDecimals = 2 - eVal = "1.32" - if val, err := cdr.exportFieldValue(cfgCdrFld, nil); err != nil { - t.Error(err) - } else if val != eVal { - t.Errorf("Expecting: %+v, received: %+v", eVal, val) - } - config.CgrConfig().GeneralCfg().RoundingDecimals = 3 - if val, err := cdr.exportFieldValue(cfgCdrFld, nil); err != nil { - t.Error(err) - } else if val != eVal { - t.Errorf("Expecting: %+v, received: %+v", eVal, val) - } - - cfgCdrFld.RoundingDecimals = 3 - config.CgrConfig().GeneralCfg().RoundingDecimals = 4 - eVal = "1.322" - if val, err := cdr.exportFieldValue(cfgCdrFld, nil); err != nil { - t.Error(err) - } else if val != eVal { - t.Errorf("Expecting: %+v, received: %+v", eVal, val) - } - - //resetore roundingdecimals value - config.CgrConfig().GeneralCfg().RoundingDecimals = 5 -}