From 9002c8c9643f0711190d10e5f85d4038f0538425 Mon Sep 17 00:00:00 2001 From: TeoV Date: Fri, 30 Mar 2018 07:06:12 -0400 Subject: [PATCH] Update name for struct (extraOpts) --- apier/v1/suppliers_it_test.go | 23 +++++++++++++++++++++++ engine/libsuppliers.go | 8 ++++---- engine/spls_leastcost.go | 10 +++++----- engine/suppliers.go | 2 +- 4 files changed, 33 insertions(+), 10 deletions(-) diff --git a/apier/v1/suppliers_it_test.go b/apier/v1/suppliers_it_test.go index b45b27359..655ba2321 100644 --- a/apier/v1/suppliers_it_test.go +++ b/apier/v1/suppliers_it_test.go @@ -51,6 +51,7 @@ var sTestsSupplierSV1 = []func(t *testing.T){ testV1SplSGetWeightSuppliers, testV1SplSGetLeastCostSuppliers, testV1SplSGetLeastCostSuppliersWithMaxCost, + testV1SplSGetLeastCostSuppliersWithMaxCostNotFound, testV1SplSGetSupplierWithoutFilter, testV1SplSSetSupplierProfiles, testV1SplSUpdateSupplierProfiles, @@ -265,6 +266,28 @@ func testV1SplSGetLeastCostSuppliersWithMaxCost(t *testing.T) { } } +func testV1SplSGetLeastCostSuppliersWithMaxCostNotFound(t *testing.T) { + ev := &engine.ArgsGetSuppliers{ + MaxCost: 0.001, + CGREvent: utils.CGREvent{ + Tenant: "cgrates.org", + ID: "testV1SplSGetLeastCostSuppliers", + Event: map[string]interface{}{ + utils.Account: "1001", + utils.Subject: "1001", + utils.Destination: "1002", + utils.SetupTime: time.Date(2017, 12, 1, 14, 25, 0, 0, time.UTC), + utils.Usage: "1m20s", + }, + }, + } + var suplsReply engine.SortedSuppliers + if err := splSv1Rpc.Call(utils.SupplierSv1GetSuppliers, + ev, &suplsReply); err.Error() != utils.ErrNotFound.Error() { + t.Error(err) + } +} + func testV1SplSGetSupplierWithoutFilter(t *testing.T) { ev := &engine.ArgsGetSuppliers{ CGREvent: utils.CGREvent{ diff --git a/engine/libsuppliers.go b/engine/libsuppliers.go index 4d0d10046..d951a8c16 100644 --- a/engine/libsuppliers.go +++ b/engine/libsuppliers.go @@ -92,7 +92,7 @@ type SupplierWithParams struct { // SuppliersSorter is the interface which needs to be implemented by supplier sorters type SuppliersSorter interface { - SortSuppliers(string, []*Supplier, *utils.CGREvent, *extraOptions) (*SortedSuppliers, error) + SortSuppliers(string, []*Supplier, *utils.CGREvent, *extraOpts) (*SortedSuppliers, error) } // NewSupplierSortDispatcher constructs SupplierSortDispatcher @@ -108,12 +108,12 @@ func NewSupplierSortDispatcher(lcrS *SupplierService) (ssd SupplierSortDispatche type SupplierSortDispatcher map[string]SuppliersSorter func (ssd SupplierSortDispatcher) SortSuppliers(prflID, strategy string, - suppls []*Supplier, suplEv *utils.CGREvent, extraFilters *extraOptions) (sortedSuppls *SortedSuppliers, err error) { + suppls []*Supplier, suplEv *utils.CGREvent, extraOpts *extraOpts) (sortedSuppls *SortedSuppliers, err error) { sd, has := ssd[strategy] if !has { return nil, fmt.Errorf("unsupported sorting strategy: %s", strategy) } - return sd.SortSuppliers(prflID, suppls, suplEv, extraFilters) + return sd.SortSuppliers(prflID, suppls, suplEv, extraOpts) } func NewWeightSorter() *WeightSorter { @@ -126,7 +126,7 @@ type WeightSorter struct { } func (ws *WeightSorter) SortSuppliers(prflID string, - suppls []*Supplier, suplEv *utils.CGREvent, extraFilters *extraOptions) (sortedSuppls *SortedSuppliers, err error) { + suppls []*Supplier, suplEv *utils.CGREvent, extraOpts *extraOpts) (sortedSuppls *SortedSuppliers, err error) { sortedSuppls = &SortedSuppliers{ProfileID: prflID, Sorting: ws.sorting, SortedSuppliers: make([]*SortedSupplier, len(suppls))} diff --git a/engine/spls_leastcost.go b/engine/spls_leastcost.go index 14a5a3bcd..4c129bd23 100644 --- a/engine/spls_leastcost.go +++ b/engine/spls_leastcost.go @@ -36,20 +36,20 @@ type LeastCostSorter struct { } // LeastCostSorter sorts suppliers based on their cost -type extraOptions struct { - maxCost *float64 +type extraOpts struct { + maxCost float64 ignoreErrors bool } func (lcs *LeastCostSorter) SortSuppliers(prflID string, suppls []*Supplier, - ev *utils.CGREvent, extraFilters *extraOptions) (sortedSuppls *SortedSuppliers, err error) { + ev *utils.CGREvent, extraOpts *extraOpts) (sortedSuppls *SortedSuppliers, err error) { sortedSuppls = &SortedSuppliers{ProfileID: prflID, Sorting: lcs.sorting, SortedSuppliers: make([]*SortedSupplier, 0)} for _, s := range suppls { costData, err := lcs.spS.costForEvent(ev, s.AccountIDs, s.RatingPlanIDs) if err != nil { - if extraFilters.ignoreErrors { + if extraOpts.ignoreErrors { utils.Logger.Warning( fmt.Sprintf("<%s> profile: %s ignoring supplier with ID: %s, err: %s", utils.SupplierS, prflID, s.ID, err.Error())) @@ -62,7 +62,7 @@ func (lcs *LeastCostSorter) SortSuppliers(prflID string, suppls []*Supplier, utils.SupplierS, prflID, s.ID)) continue } - if costData[utils.Cost].(float64) > *extraFilters.maxCost && *extraFilters.maxCost != 0 { + if extraOpts.maxCost != 0 && costData[utils.Cost].(float64) > extraOpts.maxCost { continue } srtData := map[string]interface{}{ diff --git a/engine/suppliers.go b/engine/suppliers.go index a533c7946..20feba6d1 100644 --- a/engine/suppliers.go +++ b/engine/suppliers.go @@ -284,7 +284,7 @@ func (spS *SupplierService) sortedSuppliersForEvent(args *ArgsGetSuppliers) (sor spls = append(spls, s) } sortedSuppliers, err := spS.sorter.SortSuppliers(splPrfl.ID, splPrfl.Sorting, spls, &args.CGREvent, - &extraOptions{maxCost: utils.Float64Pointer(args.MaxCost), ignoreErrors: args.IgnoreError}) + &extraOpts{maxCost: args.MaxCost, ignoreErrors: args.IgnoreError}) if err != nil { return nil, err }