diff --git a/engine/actions_test.go b/engine/actions_test.go index f8d6656a4..e46e04b34 100644 --- a/engine/actions_test.go +++ b/engine/actions_test.go @@ -2818,6 +2818,11 @@ func BenchmarkUUID(b *testing.B) { } func TestResetAccountCDR(t *testing.T) { + cfg := config.NewDefaultCGRConfig() + idb := NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) + dm := NewDataManager(idb, cfg.CacheCfg(), nil) + fltrs := NewFilterS(cfg, nil, dm) + SetCdrStorage(idb) var extraData interface{} acc := &Account{ ID: "cgrates.org:1001", @@ -2857,9 +2862,9 @@ func TestResetAccountCDR(t *testing.T) { balanceValue: 10, }, } - if err := resetAccountCDR(nil, a, acs, nil, extraData); err == nil { - t.Error(err) - } else if err = resetAccountCDR(acc, a, acs, nil, extraData); err == nil { + if err := resetAccountCDR(nil, a, acs, fltrs, extraData); err == nil || err.Error() != "nil account" { + t.Errorf("expected ,received <%+v>", err) + } else if err = resetAccountCDR(acc, a, acs, fltrs, extraData); err == nil { t.Error(err) } } @@ -2890,6 +2895,42 @@ func TestSetRecurrentAction(t *testing.T) { } func TestActionSetDDestinations(t *testing.T) { + cfg := config.NewDefaultCGRConfig() + cfg.RalsCfg().StatSConns = []string{utils.ConcatenatedKey(utils.MetaInternal, utils.StatSConnsCfg)} + cfg.GeneralCfg().DefaultTenant = "cgrates.org" + ccMock := &ccMock{ + calls: map[string]func(args interface{}, reply interface{}) error{ + utils.StatSv1GetStatQueue: func(args, reply interface{}) error { + rpl := &StatQueue{ + Tenant: "cgrates", + ID: "id", + SQMetrics: map[string]StatMetric{ + utils.MetaDDC: &StatDDC{ + FilterIDs: []string{"filters"}, + Count: 7, + }, + }, + SQItems: []SQItem{ + { + EventID: "event1", + }, { + EventID: "event2", + }, + }, + } + *reply.(*StatQueue) = *rpl + return nil + }, + }, + } + clientconn := make(chan rpcclient.ClientConnector, 1) + clientconn <- ccMock + + connMgr := NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + utils.ConcatenatedKey(utils.MetaInternal, utils.StatSConnsCfg): clientconn, + }) + SetConnManager(connMgr) + config.SetCgrConfig(cfg) ub := &Account{ ID: "ACCID", ActionTriggers: ActionTriggers{ @@ -2911,7 +2952,7 @@ func TestActionSetDDestinations(t *testing.T) { DestinationIDs: utils.StringMap{ "*ddc_dest": true, - "*dest": false, + "*ddcdest": false, }}, }, utils.MetaVoice: { @@ -2932,7 +2973,7 @@ func TestActionSetDDestinations(t *testing.T) { a := &Action{ Id: "CDRLog1", ActionType: utils.CDRLog, - ExtraParameters: "{\"BalanceID\":\"~*acnt.BalanceID\",\"ActionID\":\"~*act.ActionID\",\"BalanceValue\":\"~*acnt.BalanceValue\"}", + ExtraParameters: "{\"BalanceID\";\"~*acnt.BalanceID\";\"ActionID\";\"~*act.ActionID\";\"BalanceValue\";\"~*acnt.BalanceValue\"}", Weight: 50, } acs := Actions{ @@ -3019,12 +3060,31 @@ func TestActionPublishAccount(t *testing.T) { }, } if err := publishAccount(ub, a, acs, nil, nil); err != nil { - t.Error(err) + t.Errorf("received %v", err) } } func TestExportAction(t *testing.T) { + cfg := config.NewDefaultCGRConfig() + cfg.ApierCfg().EEsConns = []string{utils.ConcatenatedKey(utils.MetaInternal, utils.EEsConnsCfg)} + config.SetCgrConfig(cfg) + ccMock := &ccMock{ + calls: map[string]func(args, reply interface{}) error{ + utils.EeSv1ProcessEvent: func(args, reply interface{}) error { + rpl := &map[string]map[string]interface{}{} + *reply.(*map[string]map[string]interface{}) = *rpl + + return nil + }, + }, + } + clientconn := make(chan rpcclient.ClientConnector, 1) + clientconn <- ccMock + connMgr := NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + utils.ConcatenatedKey(utils.MetaInternal, utils.EEsConnsCfg): clientconn, + }) + SetConnManager(connMgr) ub := &Account{ ID: "ACCID", ActionTriggers: ActionTriggers{ @@ -3085,7 +3145,67 @@ func TestExportAction(t *testing.T) { balanceValue: 10, }, } - if err := export(ub, a, acs, nil, utils.CGREvent{Tenant: "cgrates.org", ID: "id"}); err == nil { - t.Error(err) + if err := export(ub, a, acs, nil, utils.CGREvent{Tenant: "cgrates.org", ID: "id"}); err != nil { + t.Errorf("received %v", err) } } +func TestResetStatQueue(t *testing.T) { + cfg := config.NewDefaultCGRConfig() + cfg.SchedulerCfg().StatSConns = []string{utils.ConcatenatedKey(utils.MetaInternal, utils.StatSConnsCfg)} + + ccMock := &ccMock{ + calls: map[string]func(args interface{}, reply interface{}) error{ + utils.StatSv1ResetStatQueue: func(args, reply interface{}) error { + rpl := "reset" + *reply.(*string) = rpl + return nil + }, + }, + } + clientconn := make(chan rpcclient.ClientConnector, 1) + clientconn <- ccMock + connMgr := NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + utils.ConcatenatedKey(utils.MetaInternal, utils.StatSConnsCfg): clientconn, + }) + SetConnManager(connMgr) + config.SetCgrConfig(cfg) + ub := &Account{} + a := &Action{ + ExtraParameters: "cgrates.org:id", + } + acs := Actions{} + if err := resetStatQueue(ub, a, acs, nil, nil); err == nil { + t.Errorf("received <%+v>", err) + } + +} + +func TestResetTreshold(t *testing.T) { + cfg := config.NewDefaultCGRConfig() + cfg.SchedulerCfg().ThreshSConns = []string{utils.ConcatenatedKey(utils.MetaInternal, utils.ThreshSConnsCfg)} + ccMock := &ccMock{ + calls: map[string]func(args interface{}, reply interface{}) error{ + utils.ThresholdSv1ResetThreshold: func(args, reply interface{}) error { + rpl := "threshold_reset" + *reply.(*string) = rpl + return nil + }, + }, + } + clientconn := make(chan rpcclient.ClientConnector, 1) + clientconn <- ccMock + connMgr := NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + utils.ConcatenatedKey(utils.MetaInternal, utils.ThreshSConnsCfg): clientconn, + }) + SetConnManager(connMgr) + config.SetCgrConfig(cfg) + ub := &Account{} + a := &Action{ + ExtraParameters: "cgrates.org:id", + } + acs := Actions{} + if err := resetThreshold(ub, a, acs, nil, nil); err != nil { + t.Errorf("received <%+v>", err) + } + +} diff --git a/engine/balances_test.go b/engine/balances_test.go index 8705819c0..0ae0623e6 100644 --- a/engine/balances_test.go +++ b/engine/balances_test.go @@ -18,6 +18,7 @@ along with this program. If not, see package engine import ( + "reflect" "testing" "time" @@ -595,12 +596,46 @@ func TestBalanceDebitUnits(t *testing.T) { Value: 12.22, ExpirationDate: time.Date(2022, 11, 1, 20, 0, 0, 0, time.UTC), Blocker: true, - Disabled: true, + Disabled: false, precision: 2, + RatingSubject: "*zero34", } fltrs := FilterS{cfg, dm, nil} + config.SetCgrConfig(cfg) + exp := &CallCost{Category: "postpaid", + Tenant: "foehn", + Subject: "foehn", Account: "foehn", + Destination: "0034678096720", ToR: "*voice", + Cost: 0, + Timespans: TimeSpans{ + {TimeStart: time.Date(2015, 4, 24, 7, 59, 4, 0, time.UTC), + TimeEnd: time.Date(2015, 4, 24, 8, 2, 0, 0, time.UTC), + Cost: 0, + RateInterval: &RateInterval{ + Rating: &RIRate{ + ConnectFee: 0, + RoundingDecimals: 0, + MaxCost: 0, + Rates: RateGroups{ + { + GroupIntervalStart: 0, + Value: 0, + RateIncrement: 34, + RateUnit: 34}, + }}, + Weight: 0}, + DurationIndex: 26, + MatchedSubject: "uuid", + MatchedPrefix: "0034678096720", + MatchedDestId: "*any", + RatingPlanId: "*none", + CompressFactor: 0}}, + RatedUsage: 0, + } - if _, err := b.debitUnits(cd, ub, moneyBalances, true, false, true, &fltrs); err != nil { - t.Error(err) + if val, err := b.debitUnits(cd, ub, moneyBalances, true, false, true, &fltrs); err != nil { + t.Errorf("received %v", err) + } else if reflect.DeepEqual(val, exp) { + t.Errorf("expected %+v ,received %+v", utils.ToJSON(exp), utils.ToJSON(val)) } } diff --git a/engine/calldesc_test.go b/engine/calldesc_test.go index 2c02133ff..9e6275d61 100644 --- a/engine/calldesc_test.go +++ b/engine/calldesc_test.go @@ -1196,8 +1196,8 @@ func TestMaxDebitWithAccountShared(t *testing.T) { t.Errorf("Error debiting shared balance: %+v", other.BalanceMap[utils.MetaMonetary][0]) } cd.account.Disabled = true - if _, err := cd.getAccount(); err == nil { - t.Error("expected nil") + if _, err := cd.getAccount(); err == nil || err != utils.ErrAccountDisabled { + t.Errorf("expected %v,received %v", utils.ErrAccountDisabled, err) } } @@ -2552,19 +2552,42 @@ func TestValidateCallData(t *testing.T) { } func TestCDRefundRounding(t *testing.T) { + cfg := config.NewDefaultCGRConfig() + cfg.GeneralCfg().LockingTimeout = 4 * time.Second + config.SetCgrConfig(cfg) cd := &CallDescriptor{ Category: "call", Tenant: "cgrates.org", Subject: "1001", Account: "1001", Destination: "1002", + Increments: Increments{ + &Increment{ + BalanceInfo: &DebitInfo{ + AccountID: "acc_id", + Unit: &UnitInfo{}, + }, + Duration: 1 * time.Minute, + Cost: 21, + }, + &Increment{ + BalanceInfo: &DebitInfo{ + AccountID: "acc_id2", + Unit: &UnitInfo{}, + }, + Duration: 1 * time.Minute, + Cost: 21, + }, + }, } - cfg := config.NewDefaultCGRConfig() - dataDB := NewInternalDB(nil, nil, true, nil) + + dataDB := NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) dm := NewDataManager(dataDB, cfg.CacheCfg(), nil) fltrs := NewFilterS(cfg, nil, dm) - if _, err := cd.RefundRounding(fltrs); err != nil { - t.Error(err) + if val, err := cd.RefundRounding(fltrs); err != nil { + t.Errorf("received <%v>", err) + } else if reflect.DeepEqual(val, nil) { + t.Errorf("received %v", val) } } diff --git a/engine/cdrs_test.go b/engine/cdrs_test.go index 91dbb0bdf..5ecb08774 100644 --- a/engine/cdrs_test.go +++ b/engine/cdrs_test.go @@ -476,3 +476,40 @@ func TestCDRefundEventCost(t *testing.T) { t.Error(err) } } + +/* +func TestV2ProcessEvent(t *testing.T) { + + cfg := config.NewDefaultCGRConfig() + ccMock := &ccMock{ + calls: map[string]func(args interface{}, reply interface{}) error{ + utils.ResponderRefundIncrements: func(args, reply interface{}) error { + return nil + }, + }, + } + + clientconn := make(chan rpcclient.ClientConnector, 1) + clientconn <- ccMock + connMgr := NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + utils.ConcatenatedKey(utils.MetaInternal, utils.ResponderRefundIncrements): clientconn, + }) + cfg.CdrsCfg().RaterConns = []string{utils.ConcatenatedKey(utils.MetaInternal, utils.ResponderRefundIncrements)} + db := NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) + dm := NewDataManager(db, cfg.CacheCfg(), nil) + cdrS := &CDRServer{ + cgrCfg: cfg, + cdrDb: db, + dm: dm, + connMgr: connMgr, + } + arg:=&ArgV1ProcessEvent{ + Flags: []string{}, + + } + evs:=&[]*utils.EventWithFlags{ + + } + if err:=cdrS.V2ProcessEvent() +} +*/ diff --git a/engine/destinations_test.go b/engine/destinations_test.go index 2eb1a9016..51eba1a2b 100644 --- a/engine/destinations_test.go +++ b/engine/destinations_test.go @@ -19,6 +19,7 @@ package engine import ( "encoding/json" + "reflect" "testing" "github.com/cgrates/cgrates/utils" @@ -171,10 +172,13 @@ func TestDynamicDPFieldAsInterface(t *testing.T) { } func TestDPNewLibNumber(t *testing.T) { - if _, err := newLibPhoneNumberDP("+3554735474"); err != nil { + exp := &libphonenumberDP{} + if val, err := newLibPhoneNumberDP("+3554735474"); err != nil { t.Errorf("received <%v>", err) + } else if reflect.DeepEqual(val, exp) { + t.Errorf("expected %v,received %v", utils.ToJSON(exp), utils.ToJSON(val)) } else if _, err = newLibPhoneNumberDP("some"); err == nil { - t.Error("expected error") + t.Error("expected error ,received nil") } }