mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-12 02:26:26 +05:00
Merge pull request #1791 from adragusin/master
Updated Clone function in action plan
This commit is contained in:
@@ -688,3 +688,80 @@ func TestConfigSanityStorDB(t *testing.T) {
|
||||
t.Errorf("Expecting: %+q received: %+q", expected, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestConfigSanityDataDB(t *testing.T) {
|
||||
cfg, _ = NewDefaultCGRConfig()
|
||||
cfg.dataDbCfg.DataDbType = utils.INTERNAL
|
||||
cfg.cacheCfg = CacheCfg{
|
||||
utils.CacheDiameterMessages: &CacheParamCfg{
|
||||
Limit: 0,
|
||||
},
|
||||
}
|
||||
expected := "<CacheS> *diameter_messages needs to be != 0 when DataBD is *internal, found 0."
|
||||
if err := cfg.checkConfigSanity(); err == nil || err.Error() != expected {
|
||||
t.Errorf("Expecting: %+q received: %+q", expected, err)
|
||||
}
|
||||
|
||||
cfg.cacheCfg = CacheCfg{
|
||||
utils.CacheDiameterMessages: &CacheParamCfg{
|
||||
Limit: 1,
|
||||
},
|
||||
}
|
||||
if err := cfg.checkConfigSanity(); err != nil {
|
||||
t.Errorf("Expecting: nil received: %+q", err)
|
||||
}
|
||||
|
||||
cfg.cacheCfg = CacheCfg{
|
||||
"test": &CacheParamCfg{
|
||||
Limit: 1,
|
||||
},
|
||||
}
|
||||
expected = "<CacheS> test needs to be 0 when DataBD is *internal, received : 1"
|
||||
if err := cfg.checkConfigSanity(); err == nil || err.Error() != expected {
|
||||
t.Errorf("Expecting: %+q received: %+q", expected, err)
|
||||
}
|
||||
cfg.cacheCfg["test"].Limit = 0
|
||||
|
||||
cfg.resourceSCfg.Enabled = true
|
||||
expected = "<ResourceS> StoreInterval needs to be -1 when DataBD is *internal, received : 0"
|
||||
if err := cfg.checkConfigSanity(); err == nil || err.Error() != expected {
|
||||
t.Errorf("Expecting: %+q received: %+q", expected, err)
|
||||
}
|
||||
cfg.resourceSCfg.Enabled = false
|
||||
|
||||
cfg.statsCfg.Enabled = true
|
||||
expected = "<Stats> StoreInterval needs to be -1 when DataBD is *internal, received : 0"
|
||||
if err := cfg.checkConfigSanity(); err == nil || err.Error() != expected {
|
||||
t.Errorf("Expecting: %+q received: %+q", expected, err)
|
||||
}
|
||||
cfg.statsCfg.Enabled = false
|
||||
|
||||
cfg.thresholdSCfg.Enabled = true
|
||||
expected = "<ThresholdS> StoreInterval needs to be -1 when DataBD is *internal, received : 0"
|
||||
if err := cfg.checkConfigSanity(); err == nil || err.Error() != expected {
|
||||
t.Errorf("Expecting: %+q received: %+q", expected, err)
|
||||
}
|
||||
cfg.thresholdSCfg.Enabled = false
|
||||
|
||||
cfg.dataDbCfg.Items = map[string]*ItemRmtRplOpt{
|
||||
"test1": &ItemRmtRplOpt{
|
||||
Remote: true,
|
||||
},
|
||||
}
|
||||
expected = "Remote connections required by: <test1>"
|
||||
if err := cfg.checkConfigSanity(); err == nil || err.Error() != expected {
|
||||
t.Errorf("Expecting: %+q received: %+q", expected, err)
|
||||
}
|
||||
|
||||
cfg.dataDbCfg.Items = map[string]*ItemRmtRplOpt{
|
||||
"test2": &ItemRmtRplOpt{
|
||||
Remote: false,
|
||||
Replicate: true,
|
||||
},
|
||||
}
|
||||
expected = "Replicate connections required by: <test2>"
|
||||
if err := cfg.checkConfigSanity(); err == nil || err.Error() != expected {
|
||||
t.Errorf("Expecting: %+q received: %+q", expected, err)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -80,14 +80,36 @@ func (apl *ActionPlan) RemoveAccountID(accID string) (found bool) {
|
||||
return
|
||||
}
|
||||
|
||||
// Clone clones *ActionPlan
|
||||
func (apl *ActionPlan) Clone() (interface{}, error) {
|
||||
cln := new(ActionPlan)
|
||||
if err := utils.Clone(*apl, cln); err != nil {
|
||||
return nil, err
|
||||
cln := &ActionPlan{
|
||||
Id: apl.Id,
|
||||
AccountIDs: apl.AccountIDs.Clone(),
|
||||
}
|
||||
if apl.ActionTimings != nil {
|
||||
cln.ActionTimings = make([]*ActionTiming, len(apl.ActionTimings))
|
||||
for i, act := range apl.ActionTimings {
|
||||
cln.ActionTimings[i] = act.Clone()
|
||||
}
|
||||
}
|
||||
return cln, nil
|
||||
}
|
||||
|
||||
// Clone clones ActionTiming
|
||||
func (at *ActionTiming) Clone() (cln *ActionTiming) {
|
||||
if at == nil {
|
||||
return
|
||||
}
|
||||
cln = &ActionTiming{
|
||||
Uuid: at.Uuid,
|
||||
ActionsID: at.ActionsID,
|
||||
Weight: at.Weight,
|
||||
ExtraData: at.ExtraData,
|
||||
Timing: at.Timing.Clone(),
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (at *ActionTiming) GetNextStartTime(now time.Time) (t time.Time) {
|
||||
if !at.stCache.IsZero() {
|
||||
return at.stCache
|
||||
|
||||
@@ -91,7 +91,16 @@ func TestActionPlanClone(t *testing.T) {
|
||||
at1 := &ActionPlan{
|
||||
Id: "test",
|
||||
AccountIDs: utils.StringMap{"one": true, "two": true, "three": true},
|
||||
//ActionTimings: []*ActionTiming{},
|
||||
ActionTimings: []*ActionTiming{
|
||||
&ActionTiming{
|
||||
Uuid: "Uuid_test1",
|
||||
ActionsID: "ActionsID_test1",
|
||||
Weight: 0.8,
|
||||
Timing: &RateInterval{
|
||||
Weight: 0.7,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
clned, err := at1.Clone()
|
||||
if err != nil {
|
||||
@@ -99,7 +108,7 @@ func TestActionPlanClone(t *testing.T) {
|
||||
}
|
||||
at1Cloned := clned.(*ActionPlan)
|
||||
if !reflect.DeepEqual(at1, at1Cloned) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", at1, at1Cloned)
|
||||
t.Errorf("\nExpecting: %+v,\n received: %+v", at1, at1Cloned)
|
||||
}
|
||||
}
|
||||
func TestActionTimindSetActions(t *testing.T) {
|
||||
|
||||
@@ -425,3 +425,48 @@ func (il *RateIntervalTimeSorter) Sort() []*RateInterval {
|
||||
sort.Sort(il)
|
||||
return il.ris
|
||||
}
|
||||
|
||||
// Clone clones RateInterval
|
||||
func (i *RateInterval) Clone() (cln *RateInterval) {
|
||||
if i == nil {
|
||||
return
|
||||
}
|
||||
cln = &RateInterval{
|
||||
Timing: i.Timing.Clone(),
|
||||
Rating: i.Rating.Clone(),
|
||||
Weight: i.Weight,
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Clone clones RITiming
|
||||
func (rit *RITiming) Clone() (cln *RITiming) {
|
||||
if rit == nil {
|
||||
return
|
||||
}
|
||||
cln = &RITiming{
|
||||
Years: rit.Years,
|
||||
Months: rit.Months,
|
||||
MonthDays: rit.MonthDays,
|
||||
WeekDays: rit.WeekDays,
|
||||
StartTime: rit.StartTime,
|
||||
EndTime: rit.EndTime,
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Clone clones RIRate
|
||||
func (rit *RIRate) Clone() (cln *RIRate) {
|
||||
if rit == nil {
|
||||
return
|
||||
}
|
||||
cln = &RIRate{
|
||||
ConnectFee: rit.ConnectFee,
|
||||
RoundingMethod: rit.RoundingMethod,
|
||||
RoundingDecimals: rit.RoundingDecimals,
|
||||
MaxCost: rit.MaxCost,
|
||||
MaxCostStrategy: rit.MaxCostStrategy,
|
||||
Rates: rit.Rates,
|
||||
}
|
||||
return cln
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user