mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-17 14:19:54 +05:00
balance destinationIDs exceptions
This commit is contained in:
@@ -8,3 +8,4 @@ cgrates.org,1009,TEST_EXE,,,
|
||||
cgrates.org,1010,TEST_DATA_r,,true,
|
||||
cgrates.org,1011,TEST_VOICE,,,
|
||||
cgrates.org,1012,PREPAID_10,,,
|
||||
cgrates.org,1013,TEST_NEG,,,
|
||||
|
@@ -4,3 +4,4 @@ PREPAID_10,BONUS_1,ASAP,10
|
||||
TEST_EXE,TOPUP_EXE,ALWAYS,10
|
||||
TEST_DATA_r,TOPUP_DATA_r,ASAP,10
|
||||
TEST_VOICE,TOPUP_VOICE,ASAP,10
|
||||
TEST_NEG,TOPUP_NEG,ASAP,10
|
||||
|
||||
|
@@ -7,4 +7,5 @@ CDRST_LOG,*log,,,,,,,,,,,,,,false,false,10
|
||||
TOPUP_EXE,*topup,,,,*monetary,*out,,*any,,,*unlimited,,5,10,false,false,10
|
||||
TOPUP_DATA_r,*topup,,,,*monetary,*out,,DATA_DEST,,,*unlimited,,5000000,10,false,false,10
|
||||
TOPUP_DATA_r,*topup,,,,*data,*out,,DATA_DEST,datar,,*unlimited,,50000000000,10,false,false,10
|
||||
TOPUP_VOICE,*topup,,,,*voice,*out,,GERMANY_MOBILE,,,*unlimited,,50000,10,false,false,10
|
||||
TOPUP_VOICE,*topup,,,,*voice,*out,,GERMANY_MOBILE,,,*unlimited,,50000,10,false,false,10
|
||||
TOPUP_NEG,*topup,,,,*voice,*out,,GERMANY;!GERMANY_MOBILE,*zero1m,,*unlimited,,100,10,false,false,10
|
||||
|
||||
|
@@ -306,14 +306,21 @@ func (ub *Account) getBalancesForPrefix(prefix, category, direction, tor string,
|
||||
if x, err := cache2go.Get(utils.DESTINATION_PREFIX + p); err == nil {
|
||||
destIds := x.(map[interface{}]struct{})
|
||||
for dId, _ := range destIds {
|
||||
if b.DestinationIDs[dId.(string)] == true {
|
||||
b.precision = len(p)
|
||||
usefulBalances = append(usefulBalances, b)
|
||||
break
|
||||
includeDest, found := b.DestinationIDs[dId.(string)]
|
||||
utils.Logger.Debug("DID: " + dId.(string))
|
||||
if found {
|
||||
if includeDest {
|
||||
b.precision = len(p)
|
||||
usefulBalances = append(usefulBalances, b)
|
||||
break
|
||||
} else { // the balance had !, so now equals false => exclude balance
|
||||
b.precision = 1 // fake to exit the outer loop
|
||||
break
|
||||
}
|
||||
}
|
||||
if b.precision > 0 {
|
||||
/*if b.precision > 0 {
|
||||
break
|
||||
}
|
||||
}*/
|
||||
}
|
||||
}
|
||||
if b.precision > 0 {
|
||||
|
||||
@@ -187,3 +187,34 @@ func TestTpZeroCost(t *testing.T) {
|
||||
t.Errorf("Calling ApierV2.GetAccount received: %s", utils.ToIJSON(acnt))
|
||||
}
|
||||
}
|
||||
|
||||
func TestTpZeroNegativeCost(t *testing.T) {
|
||||
if !*testIntegration {
|
||||
return
|
||||
}
|
||||
tStart := time.Date(2016, 3, 31, 0, 0, 0, 0, time.UTC)
|
||||
cd := engine.CallDescriptor{
|
||||
Direction: "*out",
|
||||
Category: "call",
|
||||
Tenant: "cgrates.org",
|
||||
Subject: "free",
|
||||
Account: "1013",
|
||||
Destination: "+4915",
|
||||
DurationIndex: 0,
|
||||
TimeStart: tStart,
|
||||
TimeEnd: tStart.Add(time.Duration(20) * time.Second),
|
||||
}
|
||||
var cc engine.CallCost
|
||||
if err := tpRPC.Call("Responder.Debit", cd, &cc); err != nil {
|
||||
t.Error("Got error on Responder.GetCost: ", err.Error())
|
||||
} else if cc.GetDuration() != 20*time.Second {
|
||||
t.Errorf("Calling Responder.MaxDebit got callcost: %v", utils.ToIJSON(cc))
|
||||
}
|
||||
var acnt *engine.Account
|
||||
attrs := &utils.AttrGetAccount{Tenant: "cgrates.org", Account: "1013"}
|
||||
if err := tpRPC.Call("ApierV2.GetAccount", attrs, &acnt); err != nil {
|
||||
t.Error("Got error on ApierV2.GetAccount: ", err.Error())
|
||||
} else if acnt.BalanceMap[utils.VOICE][0].Value != 100.0 {
|
||||
t.Errorf("Calling ApierV2.GetAccount received: %s", utils.ToIJSON(acnt))
|
||||
}
|
||||
}
|
||||
|
||||
12
utils/map.go
12
utils/map.go
@@ -67,7 +67,11 @@ func NewStringMap(s ...string) StringMap {
|
||||
for _, v := range s {
|
||||
v = strings.TrimSpace(v)
|
||||
if v != "" {
|
||||
result[v] = true
|
||||
if strings.HasPrefix(v, "!") {
|
||||
result[v[1:]] = false
|
||||
} else {
|
||||
result[v] = true
|
||||
}
|
||||
}
|
||||
}
|
||||
return result
|
||||
@@ -128,7 +132,11 @@ func StringMapFromSlice(s []string) StringMap {
|
||||
for _, v := range s {
|
||||
v = strings.TrimSpace(v)
|
||||
if v != "" {
|
||||
result[v] = true
|
||||
if strings.HasPrefix(v, "!") {
|
||||
result[v[1:]] = false
|
||||
} else {
|
||||
result[v] = true
|
||||
}
|
||||
}
|
||||
}
|
||||
return result
|
||||
|
||||
33
utils/map_test.go
Normal file
33
utils/map_test.go
Normal file
@@ -0,0 +1,33 @@
|
||||
package utils
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestStringMapParse(t *testing.T) {
|
||||
sm := ParseStringMap("1;2;3;4")
|
||||
if len(sm) != 4 {
|
||||
t.Error("Error pasring map: ", sm)
|
||||
}
|
||||
}
|
||||
|
||||
func TestStringMapParseNegative(t *testing.T) {
|
||||
sm := ParseStringMap("1;2;!3;4")
|
||||
if len(sm) != 4 {
|
||||
t.Error("Error pasring map: ", sm)
|
||||
}
|
||||
if sm["3"] != false {
|
||||
t.Error("Error parsing negative: ", sm)
|
||||
}
|
||||
}
|
||||
|
||||
func TestStringMapCompare(t *testing.T) {
|
||||
sm := ParseStringMap("1;2;!3;4")
|
||||
if include, found := sm["2"]; include != true && found != true {
|
||||
t.Error("Error detecting positive: ", sm)
|
||||
}
|
||||
if include, found := sm["3"]; include != false && found != true {
|
||||
t.Error("Error detecting negative: ", sm)
|
||||
}
|
||||
if include, found := sm["5"]; include != false && found != false {
|
||||
t.Error("Error detecting missing: ", sm)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user