本文整理汇总了Golang中github.com/cgrates/cgrates/utils.Float64Pointer函数的典型用法代码示例。如果您正苦于以下问题:Golang Float64Pointer函数的具体用法?Golang Float64Pointer怎么用?Golang Float64Pointer使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Float64Pointer函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: RateCdrs
// Called by rate/re-rate API
func (self *CdrServer) RateCdrs(cgrIds, runIds, tors, cdrHosts, cdrSources, reqTypes, directions, tenants, categories, accounts, subjects, destPrefixes, ratedAccounts, ratedSubjects []string,
orderIdStart, orderIdEnd int64, timeStart, timeEnd time.Time, rerateErrors, rerateRated, sendToStats bool) error {
var costStart, costEnd *float64
if rerateErrors {
costStart = utils.Float64Pointer(-1.0)
if !rerateRated {
costEnd = utils.Float64Pointer(0.0)
}
} else if rerateRated {
costStart = utils.Float64Pointer(0.0)
}
cdrs, _, err := self.cdrDb.GetStoredCdrs(&utils.CdrsFilter{CgrIds: cgrIds, RunIds: runIds, Tors: tors, CdrHosts: cdrHosts, CdrSources: cdrSources,
ReqTypes: reqTypes, Directions: directions, Tenants: tenants, Categories: categories, Accounts: accounts,
Subjects: subjects, DestPrefixes: destPrefixes, RatedAccounts: ratedAccounts, RatedSubjects: ratedSubjects,
OrderIdStart: orderIdStart, OrderIdEnd: orderIdEnd, AnswerTimeStart: &timeStart, AnswerTimeEnd: &timeEnd,
MinCost: costStart, MaxCost: costEnd})
if err != nil {
return err
}
for _, cdr := range cdrs {
if err := self.processCdr(cdr); err != nil {
Logger.Err(fmt.Sprintf("<CDRS> Processing CDR %+v, got error: %s", cdr, err.Error()))
}
}
return nil
}
开发者ID:gale320,项目名称:cgrates,代码行数:27,代码来源:cdrs.go
示例2: TestApierV2itSetAccountActionTriggers
func TestApierV2itSetAccountActionTriggers(t *testing.T) {
attrs := AttrSetAccountActionTriggers{
Tenant: "cgrates.org",
Account: "dan",
GroupID: utils.StringPointer("MONITOR_MAX_BALANCE"),
ThresholdType: utils.StringPointer(utils.TRIGGER_MAX_BALANCE),
ThresholdValue: utils.Float64Pointer(50),
BalanceType: utils.StringPointer(utils.MONETARY),
ActionsID: utils.StringPointer("DISABLE_ACCOUNT"),
}
var reply string
if err := apierRPC.Call("ApierV2.SetAccountActionTriggers", attrs, &reply); err != nil {
t.Error(err)
}
var ats engine.ActionTriggers
if err := apierRPC.Call("ApierV2.GetAccountActionTriggers", v1.AttrAcntAction{Tenant: "cgrates.org", Account: "dan"}, &ats); err != nil {
t.Error(err)
} else if len(ats) != 1 || ats[0].ID != *attrs.GroupID || ats[0].ThresholdValue != 50.0 {
t.Errorf("Received: %+v", ats)
}
attrs.ThresholdValue = utils.Float64Pointer(55) // Change the threshold
if err := apierRPC.Call("ApierV2.SetAccountActionTriggers", attrs, &reply); err != nil {
t.Error(err)
}
if err := apierRPC.Call("ApierV2.GetAccountActionTriggers", v1.AttrAcntAction{Tenant: "cgrates.org", Account: "dan"}, &ats); err != nil {
t.Error(err)
} else if len(ats) != 1 || ats[0].ID != *attrs.GroupID || ats[0].ThresholdValue != 55.0 {
t.Errorf("Received: %+v", ats)
}
}
开发者ID:cgrates,项目名称:cgrates,代码行数:30,代码来源:apierv2_it_test.go
示例3: testOnStorITCacheActions
func testOnStorITCacheActions(t *testing.T) {
acts := Actions{
&Action{
Id: "MINI",
ActionType: TOPUP_RESET,
ExpirationString: UNLIMITED,
Weight: 10,
Balance: &BalanceFilter{
Type: utils.StringPointer(utils.MONETARY),
Uuid: utils.StringPointer(utils.GenUUID()),
Directions: utils.StringMapPointer(utils.NewStringMap(utils.OUT)),
Value: &utils.ValueFormula{Static: 10,
Params: make(map[string]interface{})},
Weight: utils.Float64Pointer(10),
Disabled: utils.BoolPointer(false),
Timings: make([]*RITiming, 0),
Blocker: utils.BoolPointer(false),
},
},
&Action{
Id: "MINI",
ActionType: TOPUP,
ExpirationString: UNLIMITED,
Weight: 10,
Balance: &BalanceFilter{
Type: utils.StringPointer(utils.VOICE),
Uuid: utils.StringPointer(utils.GenUUID()),
Directions: utils.StringMapPointer(utils.NewStringMap(utils.OUT)),
Value: &utils.ValueFormula{Static: 100,
Params: make(map[string]interface{})},
Weight: utils.Float64Pointer(10),
RatingSubject: utils.StringPointer("test"),
DestinationIDs: utils.StringMapPointer(utils.NewStringMap("NAT")),
Disabled: utils.BoolPointer(false),
Timings: make([]*RITiming, 0),
Blocker: utils.BoolPointer(false),
},
},
}
if err := onStor.SetActions(acts[0].Id, acts, utils.NonTransactional); err != nil {
t.Error(err)
}
if _, hasIt := cache.Get(utils.ACTION_PREFIX + acts[0].Id); hasIt {
t.Error("Already in cache")
}
if err := onStor.CacheDataFromDB(utils.ACTION_PREFIX, []string{acts[0].Id}, false); err != nil {
t.Error(err)
}
if itm, hasIt := cache.Get(utils.ACTION_PREFIX + acts[0].Id); !hasIt {
t.Error("Did not cache")
} else if rcv := itm.(Actions); !reflect.DeepEqual(acts, rcv) {
t.Errorf("Expecting: %+v, received: %+v", acts, rcv)
}
}
开发者ID:cgrates,项目名称:cgrates,代码行数:54,代码来源:onstor_it_test.go
示例4: TestV2CdrsMongoGetCdrs
func TestV2CdrsMongoGetCdrs(t *testing.T) {
if !*testLocal {
return
}
var reply []*engine.ExternalCdr
req := utils.RpcCdrsFilter{NotCdrSources: []string{"CDRS"}}
if err := cdrsMongoRpc.Call("ApierV2.GetCdrs", req, &reply); err != nil {
t.Error("Unexpected error: ", err.Error())
} else if len(reply) != 4 {
for _, cdr := range reply {
t.Logf("CDR: %s %s %s", cdr.CgrId, cdr.CdrSource, cdr.MediationRunId)
}
t.Error("Unexpected number of CDRs returned: ", len(reply))
}
// CDRs with errors
req = utils.RpcCdrsFilter{NotCdrSources: []string{"CDRS"}, MinCost: utils.Float64Pointer(-1.0), MaxCost: utils.Float64Pointer(0.0)}
if err := cdrsMongoRpc.Call("ApierV2.GetCdrs", req, &reply); err != nil {
t.Error("Unexpected error: ", err.Error())
} else if len(reply) != 2 {
t.Error("Unexpected number of CDRs returned: ", reply)
}
// CDRs Rated
req = utils.RpcCdrsFilter{NotCdrSources: []string{"CDRS"}, MinCost: utils.Float64Pointer(-1.0)}
if err := cdrsMongoRpc.Call("ApierV2.GetCdrs", req, &reply); err != nil {
t.Error("Unexpected error: ", err.Error())
} else if len(reply) != 4 {
for _, cdr := range reply {
t.Logf("CDR: %s %s %s %f", cdr.CgrId, cdr.CdrSource, cdr.MediationRunId, cdr.Cost)
}
t.Error("Unexpected number of CDRs returned: ", reply)
}
// CDRs non rated OR SkipRated
req = utils.RpcCdrsFilter{NotCdrSources: []string{"CDRS"}, MaxCost: utils.Float64Pointer(-1.0)}
if err := cdrsMongoRpc.Call("ApierV2.GetCdrs", req, &reply); err != nil {
t.Error("Unexpected error: ", err.Error())
} else if len(reply) != 0 {
for _, cdr := range reply {
t.Logf("CDR: %s %s %s %f", cdr.CgrId, cdr.CdrSource, cdr.MediationRunId, cdr.Cost)
}
t.Error("Unexpected number of CDRs returned: ", reply)
}
// Skip Errors
req = utils.RpcCdrsFilter{NotCdrSources: []string{"CDRS"}, MinCost: utils.Float64Pointer(0.0), MaxCost: utils.Float64Pointer(-1.0)}
if err := cdrsMongoRpc.Call("ApierV2.GetCdrs", req, &reply); err != nil {
t.Error("Unexpected error: ", err.Error())
} else if len(reply) != 2 {
for _, cdr := range reply {
t.Logf("CDR: %s %s %s %f", cdr.CgrId, cdr.CdrSource, cdr.MediationRunId, cdr.Cost)
}
t.Error("Unexpected number of CDRs returned: ", reply)
}
}
开发者ID:henrylee2cn,项目名称:cgrates,代码行数:52,代码来源:cdrs_mongo_local_test.go
示例5: TestBalanceMatchFilterDiffId
func TestBalanceMatchFilterDiffId(t *testing.T) {
mb1 := &Balance{ID: "T1", Weight: 1, precision: 1, RatingSubject: "1", DestinationIDs: utils.StringMap{}}
mb2 := &BalanceFilter{ID: utils.StringPointer("T2"), Weight: utils.Float64Pointer(1), RatingSubject: utils.StringPointer("1"), DestinationIDs: nil}
if mb1.MatchFilter(mb2, false) {
t.Errorf("Match filter failure: %+v != %+v", mb1, mb2)
}
}
开发者ID:iwada,项目名称:cgrates,代码行数:7,代码来源:balances_test.go
示例6: TestBalanceMatchFilter
func TestBalanceMatchFilter(t *testing.T) {
mb1 := &Balance{Weight: 1, precision: 1, RatingSubject: "1", DestinationIDs: utils.StringMap{}}
mb2 := &BalanceFilter{Weight: utils.Float64Pointer(1), RatingSubject: nil, DestinationIDs: nil}
if !mb1.MatchFilter(mb2, false) {
t.Errorf("Match filter failure: %+v == %+v", mb1, mb2)
}
}
开发者ID:iwada,项目名称:cgrates,代码行数:7,代码来源:balances_test.go
示例7: TestBalanceMatchFilterId
func TestBalanceMatchFilterId(t *testing.T) {
mb1 := &Balance{ID: "T1", Weight: 2, precision: 2, RatingSubject: "2", DestinationIDs: utils.NewStringMap("NAT")}
mb2 := &BalanceFilter{ID: utils.StringPointer("T1"), Weight: utils.Float64Pointer(1), RatingSubject: utils.StringPointer("1"), DestinationIDs: nil}
if !mb1.MatchFilter(mb2, false) {
t.Errorf("Match filter failure: %+v == %+v", mb1, mb2)
}
}
开发者ID:iwada,项目名称:cgrates,代码行数:7,代码来源:balances_test.go
示例8: TestNewCgrJsonCfgFromFile
func TestNewCgrJsonCfgFromFile(t *testing.T) {
cgrJsonCfg, err := NewCgrJsonCfgFromFile("cfg_data.json")
if err != nil {
t.Error(err)
}
eCfg := &GeneralJsonCfg{Default_reqtype: utils.StringPointer(utils.META_PSEUDOPREPAID)}
if gCfg, err := cgrJsonCfg.GeneralJsonCfg(); err != nil {
t.Error(err)
} else if !reflect.DeepEqual(eCfg, gCfg) {
t.Error("Received: ", gCfg)
}
cdrFields := []*CdrFieldJsonCfg{
&CdrFieldJsonCfg{Cdr_field_id: utils.StringPointer(utils.TOR), Value: utils.StringPointer("~7:s/^(voice|data|sms|generic)$/*$1/")},
&CdrFieldJsonCfg{Cdr_field_id: utils.StringPointer(utils.ANSWER_TIME), Value: utils.StringPointer("1")},
&CdrFieldJsonCfg{Cdr_field_id: utils.StringPointer(utils.USAGE), Value: utils.StringPointer(`~9:s/^(\d+)$/${1}s/`)},
}
eCfgCdrc := map[string]*CdrcJsonCfg{
"CDRC-CSV1": &CdrcJsonCfg{
Enabled: utils.BoolPointer(true),
Cdr_in_dir: utils.StringPointer("/tmp/cgrates/cdrc1/in"),
Cdr_out_dir: utils.StringPointer("/tmp/cgrates/cdrc1/out"),
Cdr_source_id: utils.StringPointer("csv1"),
},
"CDRC-CSV2": &CdrcJsonCfg{
Enabled: utils.BoolPointer(true),
Data_usage_multiply_factor: utils.Float64Pointer(0.000976563),
Run_delay: utils.IntPointer(1),
Cdr_in_dir: utils.StringPointer("/tmp/cgrates/cdrc2/in"),
Cdr_out_dir: utils.StringPointer("/tmp/cgrates/cdrc2/out"),
Cdr_source_id: utils.StringPointer("csv2"),
Content_fields: &cdrFields,
},
}
if cfg, err := cgrJsonCfg.CdrcJsonCfg(); err != nil {
t.Error(err)
} else if !reflect.DeepEqual(eCfgCdrc, cfg) {
t.Error("Received: ", cfg["CDRC-CSV2"])
}
eCfgSmFs := &SmFsJsonCfg{
Enabled: utils.BoolPointer(true),
Connections: &[]*FsConnJsonCfg{
&FsConnJsonCfg{
Server: utils.StringPointer("1.2.3.4:8021"),
Password: utils.StringPointer("ClueCon"),
Reconnects: utils.IntPointer(5),
},
&FsConnJsonCfg{
Server: utils.StringPointer("2.3.4.5:8021"),
Password: utils.StringPointer("ClueCon"),
Reconnects: utils.IntPointer(5),
},
},
}
if smFsCfg, err := cgrJsonCfg.SmFsJsonCfg(); err != nil {
t.Error(err)
} else if !reflect.DeepEqual(eCfgSmFs, smFsCfg) {
t.Error("Received: ", smFsCfg)
}
}
开发者ID:foehn,项目名称:cgrates,代码行数:59,代码来源:config_json_test.go
示例9: AddTriggeredAction
// Deprecated in rc8, replaced by AddAccountActionTriggers
func (self *ApierV1) AddTriggeredAction(attr AttrAddActionTrigger, reply *string) error {
if missing := utils.MissingStructFields(&attr, []string{"Tenant", "Account"}); len(missing) != 0 {
return utils.NewErrMandatoryIeMissing(missing...)
}
at := &engine.ActionTrigger{
ID: attr.ActionTriggersId,
ThresholdType: attr.ThresholdType,
ThresholdValue: attr.ThresholdValue,
Balance: new(engine.BalanceFilter),
Weight: attr.Weight,
ActionsID: attr.ActionsId,
}
if attr.BalanceId != "" {
at.Balance.ID = utils.StringPointer(attr.BalanceId)
}
if attr.BalanceType != "" {
at.Balance.Type = utils.StringPointer(attr.BalanceType)
}
if attr.BalanceDirection != "" {
at.Balance.Directions = &utils.StringMap{attr.BalanceDirection: true}
}
if attr.BalanceDestinationIds != "" {
dstIDsMp := utils.StringMapFromSlice(strings.Split(attr.BalanceDestinationIds, utils.INFIELD_SEP))
at.Balance.DestinationIDs = &dstIDsMp
}
if attr.BalanceRatingSubject != "" {
at.Balance.RatingSubject = utils.StringPointer(attr.BalanceRatingSubject)
}
if attr.BalanceWeight != 0.0 {
at.Balance.Weight = utils.Float64Pointer(attr.BalanceWeight)
}
if balExpiryTime, err := utils.ParseTimeDetectLayout(attr.BalanceExpiryTime, self.Config.DefaultTimezone); err != nil {
return utils.NewErrServerError(err)
} else {
at.Balance.ExpirationDate = &balExpiryTime
}
if attr.BalanceSharedGroup != "" {
at.Balance.SharedGroups = &utils.StringMap{attr.BalanceSharedGroup: true}
}
acntID := utils.AccountKey(attr.Tenant, attr.Account)
_, err := engine.Guardian.Guard(func() (interface{}, error) {
acnt, err := self.AccountDb.GetAccount(acntID)
if err != nil {
return 0, err
}
acnt.ActionTriggers = append(acnt.ActionTriggers, at)
if err = self.AccountDb.SetAccount(acnt); err != nil {
return 0, err
}
return 0, nil
}, 0, acntID)
if err != nil {
return err
}
*reply = OK
return nil
}
开发者ID:cgrates,项目名称:cgrates,代码行数:59,代码来源:triggers.go
示例10: RateCdrs
// Called by rate/re-rate API
func (self *CdrServer) RateCdrs(cgrIds, runIds, tors, cdrHosts, cdrSources, reqTypes, directions, tenants, categories, accounts, subjects, destPrefixes, ratedAccounts, ratedSubjects []string,
orderIdStart, orderIdEnd int64, timeStart, timeEnd time.Time, rerateErrors, rerateRated, sendToStats bool) error {
var costStart, costEnd *float64
if rerateErrors {
costStart = utils.Float64Pointer(-1.0)
if !rerateRated {
costEnd = utils.Float64Pointer(0.0)
}
} else if rerateRated {
costStart = utils.Float64Pointer(0.0)
}
cdrs, _, err := self.cdrDb.GetStoredCdrs(&utils.CdrsFilter{CgrIds: cgrIds, RunIds: runIds, Tors: tors, CdrHosts: cdrHosts, CdrSources: cdrSources,
ReqTypes: reqTypes, Directions: directions, Tenants: tenants, Categories: categories, Accounts: accounts,
Subjects: subjects, DestPrefixes: destPrefixes, RatedAccounts: ratedAccounts, RatedSubjects: ratedSubjects,
OrderIdStart: orderIdStart, OrderIdEnd: orderIdEnd, AnswerTimeStart: &timeStart, AnswerTimeEnd: &timeEnd,
MinCost: costStart, MaxCost: costEnd})
if err != nil {
return err
}
for _, cdr := range cdrs {
if cdr.MediationRunId == "" { // raw CDRs which were not calculated before
cdr.MediationRunId = utils.META_DEFAULT
}
// replace aliases for cases they were loaded after CDR received
if err := LoadAlias(&AttrMatchingAlias{
Destination: cdr.Destination,
Direction: cdr.Direction,
Tenant: cdr.Tenant,
Category: cdr.Category,
Account: cdr.Account,
Subject: cdr.Subject,
Context: utils.ALIAS_CONTEXT_RATING,
}, cdr, utils.EXTRA_FIELDS); err != nil && err != utils.ErrNotFound {
return err
}
// replace user profile fields
if err := LoadUserProfile(cdr, utils.EXTRA_FIELDS); err != nil {
return err
}
if err := self.rateStoreStatsReplicate(cdr); err != nil {
utils.Logger.Err(fmt.Sprintf("<CDRS> Processing CDR %+v, got error: %s", cdr, err.Error()))
}
}
return nil
}
开发者ID:perrault,项目名称:cgrates,代码行数:46,代码来源:cdrs.go
示例11: TestDfCdrcJsonCfg
func TestDfCdrcJsonCfg(t *testing.T) {
eFields := []*CdrFieldJsonCfg{}
cdrFields := []*CdrFieldJsonCfg{
&CdrFieldJsonCfg{Tag: utils.StringPointer("tor"), Cdr_field_id: utils.StringPointer(utils.TOR), Type: utils.StringPointer(utils.CDRFIELD),
Value: utils.StringPointer("2"), Mandatory: utils.BoolPointer(true)},
&CdrFieldJsonCfg{Tag: utils.StringPointer("accid"), Cdr_field_id: utils.StringPointer(utils.ACCID), Type: utils.StringPointer(utils.CDRFIELD),
Value: utils.StringPointer("3"), Mandatory: utils.BoolPointer(true)},
&CdrFieldJsonCfg{Tag: utils.StringPointer("reqtype"), Cdr_field_id: utils.StringPointer(utils.REQTYPE), Type: utils.StringPointer(utils.CDRFIELD),
Value: utils.StringPointer("4"), Mandatory: utils.BoolPointer(true)},
&CdrFieldJsonCfg{Tag: utils.StringPointer("direction"), Cdr_field_id: utils.StringPointer(utils.DIRECTION), Type: utils.StringPointer(utils.CDRFIELD),
Value: utils.StringPointer("5"), Mandatory: utils.BoolPointer(true)},
&CdrFieldJsonCfg{Tag: utils.StringPointer("tenant"), Cdr_field_id: utils.StringPointer(utils.TENANT), Type: utils.StringPointer(utils.CDRFIELD),
Value: utils.StringPointer("6"), Mandatory: utils.BoolPointer(true)},
&CdrFieldJsonCfg{Tag: utils.StringPointer("category"), Cdr_field_id: utils.StringPointer(utils.CATEGORY), Type: utils.StringPointer(utils.CDRFIELD),
Value: utils.StringPointer("7"), Mandatory: utils.BoolPointer(true)},
&CdrFieldJsonCfg{Tag: utils.StringPointer("account"), Cdr_field_id: utils.StringPointer(utils.ACCOUNT), Type: utils.StringPointer(utils.CDRFIELD),
Value: utils.StringPointer("8"), Mandatory: utils.BoolPointer(true)},
&CdrFieldJsonCfg{Tag: utils.StringPointer("subject"), Cdr_field_id: utils.StringPointer(utils.SUBJECT), Type: utils.StringPointer(utils.CDRFIELD),
Value: utils.StringPointer("9"), Mandatory: utils.BoolPointer(true)},
&CdrFieldJsonCfg{Tag: utils.StringPointer("destination"), Cdr_field_id: utils.StringPointer(utils.DESTINATION), Type: utils.StringPointer(utils.CDRFIELD),
Value: utils.StringPointer("10"), Mandatory: utils.BoolPointer(true)},
&CdrFieldJsonCfg{Tag: utils.StringPointer("setup_time"), Cdr_field_id: utils.StringPointer(utils.SETUP_TIME), Type: utils.StringPointer(utils.CDRFIELD),
Value: utils.StringPointer("11"), Mandatory: utils.BoolPointer(true)},
&CdrFieldJsonCfg{Tag: utils.StringPointer("answer_time"), Cdr_field_id: utils.StringPointer(utils.ANSWER_TIME), Type: utils.StringPointer(utils.CDRFIELD),
Value: utils.StringPointer("12"), Mandatory: utils.BoolPointer(true)},
&CdrFieldJsonCfg{Tag: utils.StringPointer("usage"), Cdr_field_id: utils.StringPointer(utils.USAGE), Type: utils.StringPointer(utils.CDRFIELD),
Value: utils.StringPointer("13"), Mandatory: utils.BoolPointer(true)},
}
eCfg := map[string]*CdrcJsonCfg{
"*default": &CdrcJsonCfg{
Enabled: utils.BoolPointer(false),
Dry_run: utils.BoolPointer(false),
Cdrs: utils.StringPointer("internal"),
Cdr_format: utils.StringPointer("csv"),
Field_separator: utils.StringPointer(","),
Timezone: utils.StringPointer(""),
Run_delay: utils.IntPointer(0),
Max_open_files: utils.IntPointer(1024),
Data_usage_multiply_factor: utils.Float64Pointer(1024.0),
Cdr_in_dir: utils.StringPointer("/var/log/cgrates/cdrc/in"),
Cdr_out_dir: utils.StringPointer("/var/log/cgrates/cdrc/out"),
Failed_calls_prefix: utils.StringPointer("missed_calls"),
Cdr_source_id: utils.StringPointer("freeswitch_csv"),
Cdr_filter: utils.StringPointer(""),
Continue_on_success: utils.BoolPointer(false),
Partial_record_cache: utils.StringPointer("10s"),
Header_fields: &eFields,
Content_fields: &cdrFields,
Trailer_fields: &eFields,
},
}
if cfg, err := dfCgrJsonCfg.CdrcJsonCfg(); err != nil {
t.Error(err)
} else if !reflect.DeepEqual(eCfg, cfg) {
t.Error("Received: ", cfg["*default"])
}
}
开发者ID:kevinlovesing,项目名称:cgrates,代码行数:57,代码来源:config_json_test.go
示例12: TestApierV2itAddBalance
func TestApierV2itAddBalance(t *testing.T) {
attrs := &utils.AttrSetBalance{
Tenant: "cgrates.org",
Account: "dan",
BalanceType: utils.MONETARY,
BalanceID: utils.StringPointer(utils.META_DEFAULT),
Value: utils.Float64Pointer(5.0),
Weight: utils.Float64Pointer(10.0),
}
var reply string
if err := apierRPC.Call("ApierV2.SetBalance", attrs, &reply); err != nil {
t.Fatal(err)
}
var acnt engine.Account
if err := apierRPC.Call("ApierV2.GetAccount", &utils.AttrGetAccount{Tenant: "cgrates.org", Account: "dan"}, &acnt); err != nil {
t.Error(err)
} else if acnt.BalanceMap[utils.MONETARY][0].Value != 5.0 {
t.Errorf("Unexpected balance received: %+v", acnt.BalanceMap[utils.MONETARY][0])
}
}
开发者ID:cgrates,项目名称:cgrates,代码行数:20,代码来源:apierv2_it_test.go
示例13: TestApierV2itFraudMitigation
func TestApierV2itFraudMitigation(t *testing.T) {
if !*testIT {
return
}
attrs := &utils.AttrSetBalance{
Tenant: "cgrates.org",
Account: "dan",
BalanceType: utils.MONETARY,
BalanceID: utils.StringPointer(utils.META_DEFAULT),
Value: utils.Float64Pointer(60.0),
Weight: utils.Float64Pointer(10.0),
}
var reply string
if err := apierRPC.Call("ApierV2.SetBalance", attrs, &reply); err != nil {
t.Fatal(err)
}
var acnt engine.Account
if err := apierRPC.Call("ApierV2.GetAccount", &utils.AttrGetAccount{Tenant: "cgrates.org", Account: "dan"}, &acnt); err != nil {
t.Error(err)
} else if len(acnt.BalanceMap) != 1 || acnt.BalanceMap[utils.MONETARY][0].Value != 60.0 {
t.Errorf("Unexpected balance received: %+v", acnt.BalanceMap[utils.MONETARY][0])
} else if !acnt.Disabled {
t.Fatalf("Received account: %+v", acnt)
}
attrSetAcnt := AttrSetAccount{
Tenant: "cgrates.org",
Account: "dan",
Disabled: utils.BoolPointer(false),
}
if err := apierRPC.Call("ApierV2.SetAccount", attrSetAcnt, &reply); err != nil {
t.Fatal(err)
}
if err := apierRPC.Call("ApierV2.GetAccount", &utils.AttrGetAccount{Tenant: "cgrates.org", Account: "dan"}, &acnt); err != nil {
t.Error(err)
} else if len(acnt.BalanceMap) != 1 || acnt.BalanceMap[utils.MONETARY][0].Value != 60.0 {
t.Errorf("Unexpected balance received: %+v", acnt.BalanceMap[utils.MONETARY][0])
} else if acnt.Disabled {
t.Fatalf("Received account: %+v", acnt)
}
}
开发者ID:rinor,项目名称:cgrates,代码行数:40,代码来源:apierv2_it_test.go
示例14: TestV2CDRsPSQLGetCdrs
func TestV2CDRsPSQLGetCdrs(t *testing.T) {
if !*testLocal {
return
}
var reply []*engine.ExternalCDR
req := utils.RPCCDRsFilter{}
if err := cdrsPsqlRpc.Call("ApierV2.GetCdrs", req, &reply); err != nil {
t.Error("Unexpected error: ", err.Error())
} else if len(reply) != 4 { // 1 injected, 1 rated, 1 *raw and it's pair in *default run
t.Error("Unexpected number of CDRs returned: ", len(reply))
}
// CDRs with rating errors
req = utils.RPCCDRsFilter{RunIDs: []string{utils.META_DEFAULT}, MinCost: utils.Float64Pointer(-1.0), MaxCost: utils.Float64Pointer(0.0)}
if err := cdrsPsqlRpc.Call("ApierV2.GetCdrs", req, &reply); err != nil {
t.Error("Unexpected error: ", err.Error())
} else if len(reply) != 1 {
t.Error("Unexpected number of CDRs returned: ", reply)
}
// CDRs Rated
req = utils.RPCCDRsFilter{RunIDs: []string{utils.META_DEFAULT}}
if err := cdrsPsqlRpc.Call("ApierV2.GetCdrs", req, &reply); err != nil {
t.Error("Unexpected error: ", err.Error())
} else if len(reply) != 2 {
t.Error("Unexpected number of CDRs returned: ", reply)
}
// Raw CDRs
req = utils.RPCCDRsFilter{RunIDs: []string{utils.MetaRaw}}
if err := cdrsPsqlRpc.Call("ApierV2.GetCdrs", req, &reply); err != nil {
t.Error("Unexpected error: ", err.Error())
} else if len(reply) != 2 {
t.Error("Unexpected number of CDRs returned: ", reply)
}
// Skip Errors
req = utils.RPCCDRsFilter{RunIDs: []string{utils.META_DEFAULT}, MinCost: utils.Float64Pointer(0.0), MaxCost: utils.Float64Pointer(-1.0)}
if err := cdrsPsqlRpc.Call("ApierV2.GetCdrs", req, &reply); err != nil {
t.Error("Unexpected error: ", err.Error())
} else if len(reply) != 1 {
t.Error("Unexpected number of CDRs returned: ", reply)
}
}
开发者ID:iwada,项目名称:cgrates,代码行数:40,代码来源:cdrs_psql_local_test.go
示例15: TestBalanceMatchActionTriggerWeight
func TestBalanceMatchActionTriggerWeight(t *testing.T) {
at := &ActionTrigger{Balance: &BalanceFilter{Weight: utils.Float64Pointer(1)}}
b := &Balance{Weight: 1}
if !b.MatchActionTrigger(at) {
t.Errorf("Error matching action trigger: %+v %+v", b, at)
}
b.Weight = 2
if b.MatchActionTrigger(at) {
t.Errorf("Error matching action trigger: %+v %+v", b, at)
}
b.Weight = 0
if b.MatchActionTrigger(at) {
t.Errorf("Error matching action trigger: %+v %+v", b, at)
}
b.Weight = 1
at.Balance.Weight = nil
if !b.MatchActionTrigger(at) {
t.Errorf("Error matching action trigger: %+v %+v", b, at)
}
}
开发者ID:iwada,项目名称:cgrates,代码行数:20,代码来源:balances_test.go
示例16: TestV2CdrsMysqlGetCdrs
func TestV2CdrsMysqlGetCdrs(t *testing.T) {
if !*testLocal {
return
}
var reply []*engine.ExternalCdr
req := utils.RpcCdrsFilter{}
if err := cdrsRpc.Call("ApierV2.GetCdrs", req, &reply); err != nil {
t.Error("Unexpected error: ", err.Error())
} else if len(reply) != 4 {
t.Error("Unexpected number of CDRs returned: ", len(reply))
}
// CDRs with errors
req = utils.RpcCdrsFilter{MinCost: utils.Float64Pointer(-1.0), MaxCost: utils.Float64Pointer(0.0)}
if err := cdrsRpc.Call("ApierV2.GetCdrs", req, &reply); err != nil {
t.Error("Unexpected error: ", err.Error())
} else if len(reply) != 2 {
t.Error("Unexpected number of CDRs returned: ", reply)
}
// CDRs Rated
req = utils.RpcCdrsFilter{MinCost: utils.Float64Pointer(-1.0)}
if err := cdrsRpc.Call("ApierV2.GetCdrs", req, &reply); err != nil {
t.Error("Unexpected error: ", err.Error())
} else if len(reply) != 3 {
t.Error("Unexpected number of CDRs returned: ", reply)
}
// CDRs non rated OR SkipRated
req = utils.RpcCdrsFilter{MaxCost: utils.Float64Pointer(-1.0)}
if err := cdrsRpc.Call("ApierV2.GetCdrs", req, &reply); err != nil {
t.Error("Unexpected error: ", err.Error())
} else if len(reply) != 1 {
t.Error("Unexpected number of CDRs returned: ", reply)
}
// Skip Errors
req = utils.RpcCdrsFilter{MinCost: utils.Float64Pointer(0.0), MaxCost: utils.Float64Pointer(-1.0)}
if err := cdrsRpc.Call("ApierV2.GetCdrs", req, &reply); err != nil {
t.Error("Unexpected error: ", err.Error())
} else if len(reply) != 2 {
t.Error("Unexpected number of CDRs returned: ", reply)
}
}
开发者ID:nikbyte,项目名称:cgrates,代码行数:40,代码来源:cdrs_mysql_local_test.go
示例17: migrateAccountsInt
//.........这里部分代码省略.........
}
for index, oldUcBal := range oldUc.Balances {
b := &engine.Balance{
Uuid: oldUcBal.Uuid,
ID: oldUcBal.Id,
Value: oldUcBal.Value,
Directions: oldUcBal.Directions,
ExpirationDate: oldUcBal.ExpirationDate,
Weight: oldUcBal.Weight,
DestinationIDs: oldUcBal.DestinationIds,
RatingSubject: oldUcBal.RatingSubject,
Categories: oldUcBal.Categories,
SharedGroups: oldUcBal.SharedGroups,
Timings: oldUcBal.Timings,
TimingIDs: oldUcBal.TimingIDs,
Disabled: oldUcBal.Disabled,
Factor: oldUcBal.Factor,
Blocker: oldUcBal.Blocker,
}
bf := &engine.BalanceFilter{}
bf.LoadFromBalance(b)
cf := &engine.CounterFilter{
Value: oldUcBal.Value,
Filter: bf,
}
newUc.Counters[index] = cf
}
newAcc.UnitCounters[oldUc.BalanceType] = append(newAcc.UnitCounters[oldUc.BalanceType], newUc)
}
// action triggers
for index, oldAtr := range oldAcc.ActionTriggers {
at := &engine.ActionTrigger{
ID: oldAtr.ID,
UniqueID: oldAtr.UniqueID,
ThresholdType: oldAtr.ThresholdType,
ThresholdValue: oldAtr.ThresholdValue,
Recurrent: oldAtr.Recurrent,
MinSleep: oldAtr.MinSleep,
Weight: oldAtr.Weight,
ActionsID: oldAtr.ActionsId,
MinQueuedItems: oldAtr.MinQueuedItems,
Executed: oldAtr.Executed,
}
bf := &engine.BalanceFilter{}
if oldAtr.BalanceId != "" {
bf.ID = utils.StringPointer(oldAtr.BalanceId)
}
if oldAtr.BalanceType != "" {
bf.Type = utils.StringPointer(oldAtr.BalanceType)
}
if oldAtr.BalanceRatingSubject != "" {
bf.RatingSubject = utils.StringPointer(oldAtr.BalanceRatingSubject)
}
if !oldAtr.BalanceDirections.IsEmpty() {
bf.Directions = utils.StringMapPointer(oldAtr.BalanceDirections)
}
if !oldAtr.BalanceDestinationIds.IsEmpty() {
bf.DestinationIDs = utils.StringMapPointer(oldAtr.BalanceDestinationIds)
}
if !oldAtr.BalanceTimingTags.IsEmpty() {
bf.TimingIDs = utils.StringMapPointer(oldAtr.BalanceTimingTags)
}
if !oldAtr.BalanceCategories.IsEmpty() {
bf.Categories = utils.StringMapPointer(oldAtr.BalanceCategories)
}
if !oldAtr.BalanceSharedGroups.IsEmpty() {
bf.SharedGroups = utils.StringMapPointer(oldAtr.BalanceSharedGroups)
}
if oldAtr.BalanceWeight != 0 {
bf.Weight = utils.Float64Pointer(oldAtr.BalanceWeight)
}
if oldAtr.BalanceDisabled != false {
bf.Disabled = utils.BoolPointer(oldAtr.BalanceDisabled)
}
if !oldAtr.BalanceExpirationDate.IsZero() {
bf.ExpirationDate = utils.TimePointer(oldAtr.BalanceExpirationDate)
}
at.Balance = bf
newAcc.ActionTriggers[index] = at
}
newAcc.InitCounters()
newAccounts = append(newAccounts, newAcc)
migratedKeys = append(migratedKeys, key)
}
// write data back
for _, newAcc := range newAccounts {
result, err := mig.ms.Marshal(newAcc)
if err != nil {
return err
}
if err := mig.db.Cmd("SET", utils.ACCOUNT_PREFIX+newAcc.ID, result).Err; err != nil {
return err
}
}
notMigrated := len(keys) - len(migratedKeys)
if notMigrated > 0 {
log.Printf("WARNING: there are %d accounts that failed migration!", notMigrated)
}
return err
}
开发者ID:iwada,项目名称:cgrates,代码行数:101,代码来源:migrator_rc8int.go
示例18: TestLoadActions
func TestLoadActions(t *testing.T) {
if len(csvr.actions) != 15 {
t.Error("Failed to load actions: ", len(csvr.actions))
}
as1 := csvr.actions["MINI"]
expected := []*Action{
&Action{
Id: "MINI",
ActionType: TOPUP_RESET,
ExpirationString: UNLIMITED,
ExtraParameters: "",
Weight: 10,
Balance: &BalanceFilter{
Type: utils.StringPointer(utils.MONETARY),
Uuid: as1[0].Balance.Uuid,
Directions: utils.StringMapPointer(utils.NewStringMap(utils.OUT)),
Value: &utils.ValueFormula{Static: 10},
Weight: utils.Float64Pointer(10),
DestinationIDs: nil,
TimingIDs: nil,
SharedGroups: nil,
Categories: nil,
Disabled: utils.BoolPointer(false),
Blocker: utils.BoolPointer(false),
},
},
&Action{
Id: "MINI",
ActionType: TOPUP,
ExpirationString: UNLIMITED,
ExtraParameters: "",
Weight: 10,
Balance: &BalanceFilter{
Type: utils.StringPointer(utils.VOICE),
Uuid: as1[1].Balance.Uuid,
Directions: utils.StringMapPointer(utils.NewStringMap(utils.OUT)),
Value: &utils.ValueFormula{Static: 100},
Weight: utils.Float64Pointer(10),
RatingSubject: utils.StringPointer("test"),
DestinationIDs: utils.StringMapPointer(utils.NewStringMap("NAT")),
TimingIDs: nil,
SharedGroups: nil,
Categories: nil,
Disabled: utils.BoolPointer(false),
Blocker: utils.BoolPointer(false),
},
},
}
if !reflect.DeepEqual(as1, expected) {
t.Errorf("Error loading action1: %s", utils.ToIJSON(as1))
}
as2 := csvr.actions["SHARED"]
expected = []*Action{
&Action{
Id: "SHARED",
ActionType: TOPUP,
ExpirationString: UNLIMITED,
Weight: 10,
Balance: &BalanceFilter{
Type: utils.StringPointer(utils.MONETARY),
Directions: utils.StringMapPointer(utils.NewStringMap(utils.OUT)),
DestinationIDs: nil,
Uuid: as2[0].Balance.Uuid,
Value: &utils.ValueFormula{Static: 100},
Weight: utils.Float64Pointer(10),
SharedGroups: utils.StringMapPointer(utils.NewStringMap("SG1")),
TimingIDs: nil,
Categories: nil,
Disabled: utils.BoolPointer(false),
Blocker: utils.BoolPointer(false),
},
},
}
if !reflect.DeepEqual(as2, expected) {
t.Errorf("Error loading action: %s", utils.ToIJSON(as2))
}
as3 := csvr.actions["DEFEE"]
expected = []*Action{
&Action{
Id: "DEFEE",
ActionType: CDRLOG,
ExtraParameters: `{"Category":"^ddi","MediationRunId":"^did_run"}`,
Weight: 10,
Balance: &BalanceFilter{
Uuid: as3[0].Balance.Uuid,
Directions: nil,
DestinationIDs: nil,
TimingIDs: nil,
Categories: nil,
SharedGroups: nil,
Blocker: utils.BoolPointer(false),
Disabled: utils.BoolPointer(false),
},
},
}
if !reflect.DeepEqual(as3, expected) {
t.Errorf("Error loading action: %+v", as3[0].Balance)
}
}
开发者ID:iwada,项目名称:cgrates,代码行数:99,代码来源:loader_csv_test.go
示例19: testGetCDRs
//.........这里部分代码省略.........
if CDRs, _, err := cdrStorage.GetCDRs(&utils.CDRsFilter{DestinationPrefixes: []string{"10"}}, false); err != nil {
return err
} else if len(CDRs) != 10 {
return fmt.Errorf("Filter on DestinationPrefix, unexpected number of CDRs returned: %+v", CDRs)
}
// Filter on multiple destPrefixes
if CDRs, _, err := cdrStorage.GetCDRs(&utils.CDRsFilter{DestinationPrefixes: []string{"1002", "1003"}}, false); err != nil {
return err
} else if len(CDRs) != 7 {
return fmt.Errorf("Filter on DestinationPrefix, unexpected number of CDRs returned: %+v", CDRs)
}
// Filter on not destPrefix
if CDRs, _, err := cdrStorage.GetCDRs(&utils.CDRsFilter{NotDestinationPrefixes: []string{"10"}}, false); err != nil {
return err
} else if len(CDRs) != 0 {
return fmt.Errorf("Filter on NotDestinationPrefix, unexpected number of CDRs returned: %+v", CDRs)
}
// Filter on not destPrefixes
if CDRs, _, err := cdrStorage.GetCDRs(&utils.CDRsFilter{NotDestinationPrefixes: []string{"1001", "1002"}}, false); err != nil {
return err
} else if len(CDRs) != 5 {
return fmt.Errorf("Filter on NotDestinationPrefix, unexpected number of CDRs returned: %+v", CDRs)
}
// Filter on hasPrefix and not HasPrefix
if CDRs, _, err := cdrStorage.GetCDRs(&utils.CDRsFilter{DestinationPrefixes: []string{"1002", "1003"},
NotDestinationPrefixes: []string{"1002"}}, false); err != nil {
return err
} else if len(CDRs) != 2 {
return fmt.Errorf("Filter on DestinationPrefix and NotDestinationPrefix, unexpected number of CDRs returned: %+v", CDRs)
}
// Filter on MaxCost
var orderIdStart, orderIdEnd int64 // Capture also orderIds for the next test
if CDRs, _, err := cdrStorage.GetCDRs(&utils.CDRsFilter{MaxCost: utils.Float64Pointer(0.0)}, false); err != nil {
return err
} else if len(CDRs) != 5 {
return fmt.Errorf("Filter on MaxCost, unexpected number of CDRs returned: ", CDRs)
} else {
for i, cdr := range CDRs {
if i == 0 {
orderIdStart = cdr.OrderID
}
if cdr.OrderID < orderIdStart {
orderIdStart = cdr.OrderID
}
if cdr.OrderID > orderIdEnd {
orderIdEnd = cdr.OrderID
}
}
}
// Filter on orderIdStart
if CDRs, _, err := cdrStorage.GetCDRs(&utils.CDRsFilter{OrderIDStart: &orderIdStart}, false); err != nil {
return err
} else if len(CDRs) != 10 {
return fmt.Errorf("Filter on OrderIDStart, unexpected number of CDRs returned: %d", len(CDRs))
}
// Filter on orderIdStart and orderIdEnd
if CDRs, _, err := cdrStorage.GetCDRs(&utils.CDRsFilter{OrderIDStart: &orderIdStart, OrderIDEnd: &orderIdEnd}, false); err != nil {
return err
} else if len(CDRs) != 8 {
return fmt.Errorf("Filter on OrderIDStart OrderIDEnd, unexpected number of CDRs returned: %d", len(CDRs))
}
var timeStart, timeEnd time.Time
// Filter on timeStart
timeStart = time.Date(2015, 12, 28, 0, 0, 0, 0, time.UTC)
if CDRs, _, err := cdrStorage.GetCDRs(&utils.CDRsFilter{AnswerTimeStart: &timeStart}, false); err != nil {
开发者ID:eloycoto,项目名称:cgrates,代码行数:67,代码来源:storage_cdrs_it_test.go
示例20: TestPSQLGetStoredCdrs
|
请发表评论