mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
engine tests passing
This commit is contained in:
@@ -187,14 +187,13 @@ func (ub *Account) getBalancesForPrefix(prefix, category string, direction strin
|
||||
if b.HasDirection() && b.Directions[direction] == false {
|
||||
continue
|
||||
}
|
||||
|
||||
b.account = ub
|
||||
if len(b.DestinationIds) > 0 && b.DestinationIds[utils.ANY] == false {
|
||||
for _, p := range utils.SplitPrefix(prefix, MIN_PREFIX_MATCH) {
|
||||
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)] == false {
|
||||
if b.DestinationIds[dId.(string)] == true {
|
||||
b.precision = len(p)
|
||||
usefulBalances = append(usefulBalances, b)
|
||||
break
|
||||
|
||||
@@ -491,6 +491,8 @@ func TestMaxSessionTimeWithMaxRate(t *testing.T) {
|
||||
for _, at := range ap {
|
||||
at.Execute()
|
||||
}
|
||||
//acc, _ := accountingStorage.GetAccount("cgrates.org:12345")
|
||||
//log.Print("ACC: ", utils.ToIJSON(acc))
|
||||
cd := &CallDescriptor{
|
||||
Direction: "*out",
|
||||
Category: "call",
|
||||
|
||||
@@ -848,15 +848,16 @@ func TestLoadActions(t *testing.T) {
|
||||
ExpirationString: UNLIMITED,
|
||||
Weight: 10,
|
||||
Balance: &Balance{
|
||||
Directions: utils.NewStringMap(utils.OUT),
|
||||
Uuid: as2[0].Balance.Uuid,
|
||||
Value: 100,
|
||||
Weight: 10,
|
||||
SharedGroup: "SG1",
|
||||
Directions: utils.NewStringMap(utils.OUT),
|
||||
DestinationIds: utils.StringMap{},
|
||||
Uuid: as2[0].Balance.Uuid,
|
||||
Value: 100,
|
||||
Weight: 10,
|
||||
SharedGroup: "SG1",
|
||||
},
|
||||
},
|
||||
}
|
||||
if !reflect.DeepEqual(as2, expected) {
|
||||
if !reflect.DeepEqual(as2[0], expected[0]) {
|
||||
t.Errorf("Error loading action: %+v", as2[0].Balance)
|
||||
}
|
||||
as3 := csvr.actions["DEFEE"]
|
||||
@@ -867,12 +868,14 @@ func TestLoadActions(t *testing.T) {
|
||||
ExtraParameters: `{"Category":"^ddi","MediationRunId":"^did_run"}`,
|
||||
Weight: 10,
|
||||
Balance: &Balance{
|
||||
Uuid: as3[0].Balance.Uuid,
|
||||
Uuid: as3[0].Balance.Uuid,
|
||||
Directions: utils.StringMap{},
|
||||
DestinationIds: utils.StringMap{},
|
||||
},
|
||||
},
|
||||
}
|
||||
if !reflect.DeepEqual(as3, expected) {
|
||||
t.Errorf("Error loading action: %+v", as3[0])
|
||||
t.Errorf("Error loading action: %+v", as3[0].Balance)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -73,8 +73,8 @@ func TestResponderGetDerivedMaxSessionTime(t *testing.T) {
|
||||
}
|
||||
b10 := &Balance{Value: 10, Weight: 10, DestinationIds: utils.NewStringMap("DE_TMOBILE")}
|
||||
b20 := &Balance{Value: 20, Weight: 10, DestinationIds: utils.NewStringMap("DE_TMOBILE")}
|
||||
rifsAccount := &Account{Id: utils.ConcatenatedKey(testTenant, "rif"), BalanceMap: map[string]BalanceChain{utils.VOICE + utils.OUT: BalanceChain{b10}}}
|
||||
dansAccount := &Account{Id: utils.ConcatenatedKey(testTenant, "dan"), BalanceMap: map[string]BalanceChain{utils.VOICE + utils.OUT: BalanceChain{b20}}}
|
||||
rifsAccount := &Account{Id: utils.ConcatenatedKey(testTenant, "rif"), BalanceMap: map[string]BalanceChain{utils.VOICE: BalanceChain{b10}}}
|
||||
dansAccount := &Account{Id: utils.ConcatenatedKey(testTenant, "dan"), BalanceMap: map[string]BalanceChain{utils.VOICE: BalanceChain{b20}}}
|
||||
if err := accountingStorage.SetAccount(rifsAccount); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
@@ -96,15 +96,15 @@ func TestResponderGetDerivedMaxSessionTime(t *testing.T) {
|
||||
ratingStorage.CacheRatingAll()
|
||||
if rifStoredAcnt, err := accountingStorage.GetAccount(utils.ConcatenatedKey(testTenant, "rif")); err != nil {
|
||||
t.Error(err)
|
||||
//} else if rifStoredAcnt.BalanceMap[utils.VOICE+utils.OUT].Equal(rifsAccount.BalanceMap[utils.VOICE+utils.OUT]) {
|
||||
// t.Errorf("Expected: %+v, received: %+v", rifsAccount.BalanceMap[utils.VOICE+utils.OUT][0], rifStoredAcnt.BalanceMap[utils.VOICE+utils.OUT][0])
|
||||
} else if rifStoredAcnt.BalanceMap[utils.VOICE+utils.OUT][0].GetValue() != rifsAccount.BalanceMap[utils.VOICE+utils.OUT][0].GetValue() {
|
||||
t.Error("BalanceValue: ", rifStoredAcnt.BalanceMap[utils.VOICE+utils.OUT][0].GetValue())
|
||||
//} else if rifStoredAcnt.BalanceMap[utils.VOICE].Equal(rifsAccount.BalanceMap[utils.VOICE]) {
|
||||
// t.Errorf("Expected: %+v, received: %+v", rifsAccount.BalanceMap[utils.VOICE][0], rifStoredAcnt.BalanceMap[utils.VOICE][0])
|
||||
} else if rifStoredAcnt.BalanceMap[utils.VOICE][0].GetValue() != rifsAccount.BalanceMap[utils.VOICE][0].GetValue() {
|
||||
t.Error("BalanceValue: ", rifStoredAcnt.BalanceMap[utils.VOICE][0].GetValue())
|
||||
}
|
||||
if danStoredAcnt, err := accountingStorage.GetAccount(utils.ConcatenatedKey(testTenant, "dan")); err != nil {
|
||||
t.Error(err)
|
||||
} else if danStoredAcnt.BalanceMap[utils.VOICE+utils.OUT][0].GetValue() != dansAccount.BalanceMap[utils.VOICE+utils.OUT][0].GetValue() {
|
||||
t.Error("BalanceValue: ", danStoredAcnt.BalanceMap[utils.VOICE+utils.OUT][0].GetValue())
|
||||
} else if danStoredAcnt.BalanceMap[utils.VOICE][0].GetValue() != dansAccount.BalanceMap[utils.VOICE][0].GetValue() {
|
||||
t.Error("BalanceValue: ", danStoredAcnt.BalanceMap[utils.VOICE][0].GetValue())
|
||||
}
|
||||
var dcs utils.DerivedChargers
|
||||
attrs := &utils.AttrDerivedChargers{Tenant: testTenant, Category: "call", Direction: "*out", Account: "dan", Subject: "dan"}
|
||||
@@ -430,8 +430,8 @@ func TestResponderGetLCR(t *testing.T) {
|
||||
}
|
||||
bRif12 := &Balance{Value: 40, Weight: 10, DestinationIds: utils.NewStringMap(dstDe.Id)}
|
||||
bIvo12 := &Balance{Value: 60, Weight: 10, DestinationIds: utils.NewStringMap(dstDe.Id)}
|
||||
rif12sAccount := &Account{Id: utils.ConcatenatedKey("tenant12", "rif12"), BalanceMap: map[string]BalanceChain{utils.VOICE + utils.OUT: BalanceChain{bRif12}}, AllowNegative: true}
|
||||
ivo12sAccount := &Account{Id: utils.ConcatenatedKey("tenant12", "ivo12"), BalanceMap: map[string]BalanceChain{utils.VOICE + utils.OUT: BalanceChain{bIvo12}}, AllowNegative: true}
|
||||
rif12sAccount := &Account{Id: utils.ConcatenatedKey("tenant12", "rif12"), BalanceMap: map[string]BalanceChain{utils.VOICE: BalanceChain{bRif12}}, AllowNegative: true}
|
||||
ivo12sAccount := &Account{Id: utils.ConcatenatedKey("tenant12", "ivo12"), BalanceMap: map[string]BalanceChain{utils.VOICE: BalanceChain{bIvo12}}, AllowNegative: true}
|
||||
for _, acnt := range []*Account{rif12sAccount, ivo12sAccount} {
|
||||
if err := accountingStorage.SetAccount(acnt); err != nil {
|
||||
t.Error(err)
|
||||
|
||||
@@ -266,9 +266,9 @@ func TestDifferentUuid(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Error("Error getting account: ", err)
|
||||
}
|
||||
if a1.BalanceMap[utils.VOICE+utils.OUT][0].Uuid == a2.BalanceMap[utils.VOICE+utils.OUT][0].Uuid ||
|
||||
a1.BalanceMap[utils.MONETARY+utils.OUT][0].Uuid == a2.BalanceMap[utils.MONETARY+utils.OUT][0].Uuid {
|
||||
t.Errorf("Identical uuids in different accounts: %+v <-> %+v", a1.BalanceMap[utils.VOICE+utils.OUT][0], a1.BalanceMap[utils.MONETARY+utils.OUT][0])
|
||||
if a1.BalanceMap[utils.VOICE][0].Uuid == a2.BalanceMap[utils.VOICE][0].Uuid ||
|
||||
a1.BalanceMap[utils.MONETARY][0].Uuid == a2.BalanceMap[utils.MONETARY][0].Uuid {
|
||||
t.Errorf("Identical uuids in different accounts: %+v <-> %+v", a1.BalanceMap[utils.VOICE][0], a1.BalanceMap[utils.MONETARY][0])
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -83,10 +83,15 @@ func (uc *UnitsCounter) addUnits(amount float64, prefixMap utils.StringMap) {
|
||||
for _, p := range utils.SplitPrefix(prefix, MIN_PREFIX_MATCH) {
|
||||
if x, err := cache2go.Get(utils.DESTINATION_PREFIX + p); err == nil {
|
||||
destIds := x.(map[interface{}]struct{})
|
||||
if _, found := destIds[mb.DestinationIds]; found {
|
||||
mb.AddValue(amount)
|
||||
counted = true
|
||||
break
|
||||
for key := range mb.DestinationIds {
|
||||
if _, found := destIds[key]; found {
|
||||
mb.AddValue(amount)
|
||||
counted = true
|
||||
break
|
||||
}
|
||||
if counted {
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
if counted {
|
||||
|
||||
@@ -86,9 +86,6 @@ func ParseStringMap(s string) StringMap {
|
||||
}
|
||||
|
||||
func (sm StringMap) Equal(om StringMap) bool {
|
||||
if len(sm) == 0 {
|
||||
return len(om) == 0
|
||||
}
|
||||
if len(sm) != len(om) {
|
||||
return false
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user