From 594f7bb5576042c88e825f0e61a8ca6fbd749ca7 Mon Sep 17 00:00:00 2001 From: porosnicuadrian Date: Tue, 12 Jan 2021 16:34:54 +0200 Subject: [PATCH] Change name from ExternalAttributeProfile to APIAttributeProfile --- apier/v2/attributes.go | 6 +++--- apier/v2/attributes_it_test.go | 6 +++--- console/attributes_profile_set.go | 2 +- engine/libattributes.go | 6 +++--- engine/libattributes_test.go | 6 +++--- general_tests/export_it_test.go | 13 ++++++++++--- loaders/loader_it_test.go | 4 ++-- migrator/rateprofiles_it_test.go | 29 ++++++++++++++++++++++++++--- 8 files changed, 51 insertions(+), 21 deletions(-) diff --git a/apier/v2/attributes.go b/apier/v2/attributes.go index 9bb9ef382..94faa6905 100644 --- a/apier/v2/attributes.go +++ b/apier/v2/attributes.go @@ -26,20 +26,20 @@ import ( ) type AttributeWithCache struct { - *engine.ExternalAttributeProfile + *engine.APIAttributeProfile Cache *string Opts map[string]interface{} } //SetAttributeProfile add/update a new Attribute Profile func (APIerSv2 *APIerSv2) SetAttributeProfile(arg *AttributeWithCache, reply *string) error { - if missing := utils.MissingStructFields(arg.ExternalAttributeProfile, []string{utils.ID}); len(missing) != 0 { + if missing := utils.MissingStructFields(arg.APIAttributeProfile, []string{utils.ID}); len(missing) != 0 { return utils.NewErrMandatoryIeMissing(missing...) } if arg.Tenant == utils.EmptyString { arg.Tenant = APIerSv2.Config.GeneralCfg().DefaultTenant } - alsPrf, err := arg.ExternalAttributeProfile.AsAttributeProfile() + alsPrf, err := arg.APIAttributeProfile.AsAttributeProfile() if err != nil { return utils.APIErrorHandler(err) } diff --git a/apier/v2/attributes_it_test.go b/apier/v2/attributes_it_test.go index 0edab7c2e..439f3b014 100644 --- a/apier/v2/attributes_it_test.go +++ b/apier/v2/attributes_it_test.go @@ -115,7 +115,7 @@ func testAttributeSRPCConn(t *testing.T) { func testAttributeSSetAlsPrf(t *testing.T) { extAlsPrf := &AttributeWithCache{ - ExternalAttributeProfile: &engine.ExternalAttributeProfile{ + APIAttributeProfile: &engine.APIAttributeProfile{ Tenant: "cgrates.org", ID: "ExternalAttribute", Contexts: []string{utils.MetaSessionS, utils.MetaCDRs}, @@ -173,7 +173,7 @@ func testAttributeSSetAlsPrf(t *testing.T) { func testAttributeSUpdateAlsPrf(t *testing.T) { extAlsPrf := &AttributeWithCache{ - ExternalAttributeProfile: &engine.ExternalAttributeProfile{ + APIAttributeProfile: &engine.APIAttributeProfile{ Tenant: "cgrates.org", ID: "ExternalAttribute", Contexts: []string{utils.MetaSessionS, utils.MetaCDRs}, @@ -247,7 +247,7 @@ func testAttributeSKillEngine(t *testing.T) { func testAttributeSSetAlsPrfWithoutTenant(t *testing.T) { extAlsPrf := &AttributeWithCache{ - ExternalAttributeProfile: &engine.ExternalAttributeProfile{ + APIAttributeProfile: &engine.APIAttributeProfile{ ID: "ExternalAttribute", Contexts: []string{utils.MetaSessionS, utils.MetaCDRs}, FilterIDs: []string{"*string:~*req.Account:1001"}, diff --git a/console/attributes_profile_set.go b/console/attributes_profile_set.go index ed840560f..8db48c0d4 100644 --- a/console/attributes_profile_set.go +++ b/console/attributes_profile_set.go @@ -51,7 +51,7 @@ func (self *CmdSetAttributes) RpcMethod() string { func (self *CmdSetAttributes) RpcParams(reset bool) interface{} { if reset || self.rpcParams == nil { - self.rpcParams = &v2.AttributeWithCache{ExternalAttributeProfile: new(engine.ExternalAttributeProfile)} + self.rpcParams = &v2.AttributeWithCache{APIAttributeProfile: new(engine.APIAttributeProfile)} } return self.rpcParams } diff --git a/engine/libattributes.go b/engine/libattributes.go index a5eb24593..77333366f 100644 --- a/engine/libattributes.go +++ b/engine/libattributes.go @@ -88,8 +88,8 @@ type ExternalAttribute struct { Value string } -// ExternalAttributeProfile used by APIs -type ExternalAttributeProfile struct { +// APIAttributeProfile used by APIs +type APIAttributeProfile struct { Tenant string ID string Contexts []string // bind this AttributeProfile to multiple contexts @@ -101,7 +101,7 @@ type ExternalAttributeProfile struct { } // AsAttributeProfile converts the external attribute format to the actual AttributeProfile -func (ext *ExternalAttributeProfile) AsAttributeProfile() (attr *AttributeProfile, err error) { +func (ext *APIAttributeProfile) AsAttributeProfile() (attr *AttributeProfile, err error) { attr = new(AttributeProfile) if len(ext.Attributes) == 0 { return nil, utils.NewErrMandatoryIeMissing("Attributes") diff --git a/engine/libattributes_test.go b/engine/libattributes_test.go index 052aa522a..d4c447e63 100644 --- a/engine/libattributes_test.go +++ b/engine/libattributes_test.go @@ -29,7 +29,7 @@ import ( ) func TestConvertExternalToProfile(t *testing.T) { - external := &ExternalAttributeProfile{ + external := &APIAttributeProfile{ Tenant: "cgrates.org", ID: "ATTR_ID", Contexts: []string{utils.MetaSessionS, utils.MetaCDRs}, @@ -77,7 +77,7 @@ func TestConvertExternalToProfile(t *testing.T) { } func TestConvertExternalToProfileMissing(t *testing.T) { - external := &ExternalAttributeProfile{ + external := &APIAttributeProfile{ Tenant: "cgrates.org", ID: "ATTR_ID", Contexts: []string{utils.MetaSessionS, utils.MetaCDRs}, @@ -98,7 +98,7 @@ func TestConvertExternalToProfileMissing(t *testing.T) { } func TestConvertExternalToProfileMissing2(t *testing.T) { - external := &ExternalAttributeProfile{ + external := &APIAttributeProfile{ Tenant: "cgrates.org", ID: "ATTR_ID", Contexts: []string{utils.MetaSessionS, utils.MetaCDRs}, diff --git a/general_tests/export_it_test.go b/general_tests/export_it_test.go index cc0f8a71c..23fe834ab 100644 --- a/general_tests/export_it_test.go +++ b/general_tests/export_it_test.go @@ -364,6 +364,14 @@ func testExpVerifyRoutes(t *testing.T) { } func testExpVerifyRateProfiles(t *testing.T) { + minDec, err := utils.NewDecimalFromUnit("1m") + if err != nil { + t.Error(err) + } + secDec, err := utils.NewDecimalFromUnit("1s") + if err != nil { + t.Error(err) + } var reply *engine.RateProfile minDecimal, err := utils.NewDecimalFromUnit("1m") if err != nil { @@ -393,10 +401,9 @@ func testExpVerifyRateProfiles(t *testing.T) { IntervalRates: []*engine.IntervalRate{ { IntervalStart: 0 * time.Second, - FixedFee: utils.NewDecimal(0, 0), RecurrentFee: utils.NewDecimal(1, 2), - Unit: minDecimal, - Increment: secDecimal, + Unit: minDec, + Increment: secDec, }, }, }, diff --git a/loaders/loader_it_test.go b/loaders/loader_it_test.go index 99f9dd93f..e38e93db7 100644 --- a/loaders/loader_it_test.go +++ b/loaders/loader_it_test.go @@ -866,12 +866,12 @@ cgrates.org,NewRes1 {Tag: "Tenant", Path: "Tenant", Type: utils.MetaComposed, - Value: config.NewRSRParsersMustCompile("~*req.0", utils.InfieldSep), + Value: config.NewRSRParsersMustCompile("~*req.0", utils.FieldsSep), Mandatory: true}, {Tag: "ID", Path: "ID", Type: utils.MetaComposed, - Value: config.NewRSRParsersMustCompile("~*req.1", utils.InfieldSep), + Value: config.NewRSRParsersMustCompile("~*req.1", utils.FieldsSep), Mandatory: true}, }, } diff --git a/migrator/rateprofiles_it_test.go b/migrator/rateprofiles_it_test.go index ac3adbe07..73a9161fe 100644 --- a/migrator/rateprofiles_it_test.go +++ b/migrator/rateprofiles_it_test.go @@ -177,6 +177,14 @@ func testRatePrfITFlush(t *testing.T) { } func testRatePrfITMigrateAndMove(t *testing.T) { + minDec, err := utils.NewDecimalFromUnit("1m") + if err != nil { + t.Error(err) + } + secDec, err := utils.NewDecimalFromUnit("1s") + if err != nil { + t.Error(err) + } rPrf := &engine.RateProfile{ Tenant: "cgrates.org", ID: "RP1", @@ -184,21 +192,36 @@ func testRatePrfITMigrateAndMove(t *testing.T) { Weight: 0, RoundingMethod: "*up", RoundingDecimals: 4, - - MaxCostStrategy: "*free", + MinCost: utils.NewDecimal(1, 1), + MaxCost: utils.NewDecimal(6, 1), + MaxCostStrategy: "*free", Rates: map[string]*engine.Rate{ "FIRST_GI": { ID: "FIRST_GI", FilterIDs: []string{"*gi:~*req.Usage:0"}, Weight: 0, + IntervalRates: []*engine.IntervalRate{ + { + RecurrentFee: utils.NewDecimal(12, 2), + Unit: minDec, + Increment: minDec, + }, + }, Blocker: false, }, "SECOND_GI": { ID: "SECOND_GI", FilterIDs: []string{"*gi:~*req.Usage:1m"}, Weight: 10, - Blocker: false, + IntervalRates: []*engine.IntervalRate{ + { + RecurrentFee: utils.NewDecimal(6, 2), + Unit: minDec, + Increment: secDec, + }, + }, + Blocker: false, }, }, }