mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-20 22:58:44 +05:00
Update name for struct (extraOpts)
This commit is contained in:
committed by
Dan Christian Bogos
parent
1489ebbb51
commit
9002c8c964
@@ -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{
|
||||
|
||||
@@ -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))}
|
||||
|
||||
@@ -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{}{
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user