本文整理汇总了Golang中github.com/cgrates/cgrates/utils.Float64Pointer函数的典型用法代码示例。如果您正苦于以下问题:Golang Float64Pointer函数的具体用法?Golang Float64Pointer怎么用?Golang Float64Pointer使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Float64Pointer函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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
}
示例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)
}
}
示例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)
}
}
示例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)
}
}
示例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)
}
}
示例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)
}
}
示例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)
}
}
示例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)
}
}
示例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
}
示例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
}
示例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"])
}
}
示例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])
}
}
示例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)
}
}
示例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)
}
}
示例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)
}
}