mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-25 00:58:45 +05:00
Added all merge functions
This commit is contained in:
committed by
Dan Christian Bogos
parent
7182d57b24
commit
c1e399de6d
@@ -864,3 +864,22 @@ func (bL *Balance) Set(path []string, val interface{}, newBranch bool) (err erro
|
||||
}
|
||||
return ErrWrongPath
|
||||
}
|
||||
|
||||
func (ap *Account) Merge(v2 interface{}) {
|
||||
vi := v2.(*Account)
|
||||
if len(vi.Tenant) != 0 {
|
||||
ap.Tenant = vi.Tenant
|
||||
}
|
||||
if len(vi.ID) != 0 {
|
||||
ap.ID = vi.ID
|
||||
}
|
||||
ap.FilterIDs = append(ap.FilterIDs, vi.FilterIDs...)
|
||||
ap.Weights = append(ap.Weights, vi.Weights...)
|
||||
ap.ThresholdIDs = append(ap.ThresholdIDs, vi.ThresholdIDs...)
|
||||
for k, v := range vi.Opts {
|
||||
ap.Opts[k] = v
|
||||
}
|
||||
for k, v := range vi.Balances {
|
||||
ap.Balances[k] = v
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1354,7 +1354,7 @@ func TestJoinConverter(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
expVal := "1,2,3,5"
|
||||
expVal := "1;2;3;5"
|
||||
if i, err := d.Convert("1;2;3;5"); err != nil {
|
||||
t.Error(err.Error())
|
||||
} else if expVal != i {
|
||||
@@ -1383,7 +1383,7 @@ func TestSplitConverter(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
expVal := []string{"1", "2", "3", "5"}
|
||||
if i, err := d.Convert("1,2,3,5"); err != nil {
|
||||
if i, err := d.Convert("1;2;3;5"); err != nil {
|
||||
t.Error(err.Error())
|
||||
} else if !reflect.DeepEqual(expVal, i) {
|
||||
t.Errorf("expecting: %q, received: %q", expVal, i)
|
||||
|
||||
@@ -676,3 +676,28 @@ func (rt *Rate) Set(path []string, val interface{}, newBranch bool) (err error)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (rp *RateProfile) Merge(v2 interface{}) {
|
||||
vi := v2.(*RateProfile)
|
||||
if len(vi.Tenant) != 0 {
|
||||
rp.Tenant = vi.Tenant
|
||||
}
|
||||
if len(vi.ID) != 0 {
|
||||
rp.ID = vi.ID
|
||||
}
|
||||
if len(vi.MaxCostStrategy) != 0 {
|
||||
rp.MaxCostStrategy = vi.MaxCostStrategy
|
||||
}
|
||||
rp.FilterIDs = append(rp.FilterIDs, vi.FilterIDs...)
|
||||
rp.Weights = append(rp.Weights, vi.Weights...)
|
||||
for k, v := range vi.Rates {
|
||||
rp.Rates[k] = v
|
||||
}
|
||||
o := decimal.New(0, 0)
|
||||
if vi.MinCost != nil && vi.MinCost.Cmp(o) != 0 {
|
||||
rp.MinCost = vi.MinCost
|
||||
}
|
||||
if vi.MaxCost != nil && vi.MinCost.Cmp(o) != 0 {
|
||||
rp.MaxCost = vi.MaxCost
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user