mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
improving coverage tests at engine
This commit is contained in:
committed by
Dan Christian Bogos
parent
3b62f06f1b
commit
8848bb6898
@@ -1006,7 +1006,7 @@ func TestERSCfgAsMapInterfaceCase2(t *testing.T) {
|
||||
"natsClientCertificateProcessed":"ClientCertificate",
|
||||
"natsClientKeyProcessed":"ClientKey",
|
||||
"natsJetStreamMaxWaitProcessed":"1m",
|
||||
|
||||
|
||||
},
|
||||
},
|
||||
],
|
||||
|
||||
@@ -18,6 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
package engine
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"reflect"
|
||||
"testing"
|
||||
"time"
|
||||
@@ -2419,3 +2420,195 @@ func BenchmarkGetSecondsForPrefix(b *testing.B) {
|
||||
ub1.getCreditForPrefix(cd)
|
||||
}
|
||||
}
|
||||
|
||||
func TestAccountSummaryFieldAsInterface(t *testing.T) {
|
||||
as := AccountSummary{
|
||||
BalanceSummaries: BalanceSummaries{
|
||||
&BalanceSummary{
|
||||
UUID: "uId",
|
||||
ID: "id",
|
||||
Type: "*data",
|
||||
Initial: 20.54,
|
||||
Value: 1,
|
||||
}},
|
||||
Tenant: "tenant",
|
||||
ID: "accID",
|
||||
}
|
||||
|
||||
if _, err := as.FieldAsInterface(nil); err == nil {
|
||||
t.Error(err)
|
||||
} else if _, err := as.FieldAsInterface([]string{"test"}); err == nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if val, err := as.FieldAsInterface([]string{"BalanceSummaries[0]"}); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(val, as.BalanceSummaries[0]) {
|
||||
t.Errorf("expected %v ,received %v", utils.ToJSON(val), utils.ToJSON(as.BalanceSummaries[0]))
|
||||
} else if _, err = as.FieldAsInterface([]string{"Tenant"}); err != nil {
|
||||
t.Error(err)
|
||||
} else if _, err = as.FieldAsInterface([]string{"Tenant", "Value"}); err == nil {
|
||||
t.Error(err)
|
||||
} else if _, err = as.FieldAsInterface([]string{"ID"}); err != nil {
|
||||
t.Error(err)
|
||||
} else if _, err = as.FieldAsInterface([]string{"ID", "test"}); err == nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if val, err := as.FieldAsInterface([]string{"BalanceSummaries"}); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(val, as.BalanceSummaries) {
|
||||
t.Errorf("expected %v ,received %v ", utils.ToJSON(val), utils.ToJSON(as.BalanceSummaries))
|
||||
}
|
||||
as.BalanceSummaries = BalanceSummaries{
|
||||
&BalanceSummary{
|
||||
|
||||
UUID: "uId",
|
||||
ID: "id",
|
||||
Type: "*data",
|
||||
Initial: 20.54,
|
||||
Value: 1,
|
||||
},
|
||||
&BalanceSummary{
|
||||
UUID: "uId2",
|
||||
ID: "id2",
|
||||
Type: "*data",
|
||||
Initial: 20.54,
|
||||
Value: 1,
|
||||
}}
|
||||
if _, err := as.FieldAsInterface([]string{"BalanceSummaries", "id3"}); err == nil {
|
||||
t.Error(err)
|
||||
|
||||
} else if val, err := as.FieldAsInterface([]string{"BalanceSummaries", "id2"}); err != nil {
|
||||
t.Error(err)
|
||||
|
||||
} else if !reflect.DeepEqual(val, as.BalanceSummaries[1]) {
|
||||
t.Errorf("expected %v ,received %v", utils.ToJSON(val), utils.ToJSON(as.BalanceSummaries[1]))
|
||||
}
|
||||
if _, err = as.FieldAsInterface([]string{"AllowNegative"}); err != nil {
|
||||
t.Error(err)
|
||||
} else if _, err = as.FieldAsInterface([]string{"AllowNegative", "test"}); err == nil {
|
||||
t.Error(err)
|
||||
} else if _, err = as.FieldAsInterface([]string{"Disabled"}); err != nil {
|
||||
t.Error(err)
|
||||
} else if _, err = as.FieldAsInterface([]string{"Disabled", "test"}); err == nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestAccountSummaryFieldAsString(t *testing.T) {
|
||||
as := AccountSummary{
|
||||
BalanceSummaries: BalanceSummaries{
|
||||
&BalanceSummary{
|
||||
UUID: "uId",
|
||||
ID: "id",
|
||||
Type: "*data",
|
||||
Initial: 20.54,
|
||||
Value: 1,
|
||||
}},
|
||||
}
|
||||
rec := &BalanceSummary{}
|
||||
if _, err := as.FieldAsString([]string{}); err == nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if val, err := as.FieldAsString([]string{"BalanceSummaries[0]"}); err != nil {
|
||||
t.Error(err)
|
||||
} else if err := json.Unmarshal([]byte(val), rec); err != nil {
|
||||
t.Error("Error converting value")
|
||||
} else if !reflect.DeepEqual(rec, as.BalanceSummaries[0]) {
|
||||
t.Errorf("expected %v ,received %v", utils.ToJSON(as.BalanceSummaries[0]), utils.ToJSON(rec))
|
||||
}
|
||||
|
||||
}
|
||||
func TestAccountFieldAsInterface(t *testing.T) {
|
||||
var acc *Account
|
||||
if _, err := acc.FieldAsInterface([]string{}); err != nil {
|
||||
t.Error(err)
|
||||
} else if _, err := acc.FieldAsInterface([]string{"test"}); err == nil {
|
||||
t.Error(err)
|
||||
}
|
||||
acc = &Account{
|
||||
ID: "id",
|
||||
BalanceMap: map[string]Balances{
|
||||
"first": {
|
||||
&Balance{
|
||||
Uuid: "uuid1",
|
||||
ID: "id",
|
||||
Value: 20.44,
|
||||
},
|
||||
&Balance{
|
||||
Uuid: "uuid2",
|
||||
ID: "id2",
|
||||
Value: 12.2,
|
||||
},
|
||||
}},
|
||||
UnitCounters: UnitCounters{
|
||||
"first": []*UnitCounter{
|
||||
{
|
||||
CounterType: "balance",
|
||||
Counters: CounterFilters{
|
||||
{
|
||||
Value: 20.44,
|
||||
Filter: &BalanceFilter{
|
||||
Uuid: utils.StringPointer("filterUuid"),
|
||||
ID: utils.StringPointer("filterId"),
|
||||
Type: utils.StringPointer("type"),
|
||||
},
|
||||
},
|
||||
},
|
||||
}}},
|
||||
ActionTriggers: ActionTriggers{
|
||||
{
|
||||
UniqueID: "uniId",
|
||||
ID: "id",
|
||||
ThresholdType: "*min_event_counter",
|
||||
ThresholdValue: 20.55,
|
||||
},
|
||||
{
|
||||
UniqueID: "uniId2",
|
||||
ID: "id2",
|
||||
ThresholdType: "*max_event_counter",
|
||||
ThresholdValue: 19.22,
|
||||
Recurrent: true,
|
||||
},
|
||||
},
|
||||
}
|
||||
if _, err := acc.FieldAsInterface([]string{"Balance"}); err == nil {
|
||||
t.Error(err)
|
||||
} else if _, err = acc.FieldAsInterface([]string{"BalanceMap[second]"}); err == nil {
|
||||
t.Error(err)
|
||||
} else if val, err := acc.FieldAsInterface([]string{"BalanceMap[first]"}); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(acc.BalanceMap["first"], val) {
|
||||
t.Errorf("expected %v ,received %v", utils.ToJSON(val), utils.ToJSON(acc.BalanceMap["first"]))
|
||||
} else if _, err := acc.FieldAsInterface([]string{"BalanceMap[first]", "UnitCounters[test]"}); err == nil {
|
||||
t.Error(err)
|
||||
} else if _, err := acc.FieldAsInterface([]string{"UnitCounters[test]"}); err == nil {
|
||||
t.Error(err)
|
||||
} else if val, err := acc.FieldAsInterface([]string{"UnitCounters[first]"}); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(val, acc.UnitCounters["first"]) {
|
||||
t.Errorf("expected %v ,received %v", val, acc.UnitCounters["first"])
|
||||
}
|
||||
if _, err := acc.FieldAsInterface([]string{"ActionTriggers[3]"}); err == nil {
|
||||
t.Error(err)
|
||||
} else if _, err := acc.FieldAsInterface([]string{"ActionTriggers[three]"}); err == nil {
|
||||
t.Error(err)
|
||||
} else if val, err := acc.FieldAsInterface([]string{"ActionTriggers[0]"}); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(val, acc.ActionTriggers[0]) {
|
||||
t.Errorf("expected %v ,received %v", utils.ToJSON(acc.ActionTriggers[0]), utils.ToJSON(val))
|
||||
} else if _, err = acc.FieldAsInterface([]string{"ActionTriggers[0]", "test"}); err == nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if _, err := acc.FieldAsInterface([]string{"ID"}); err != nil {
|
||||
t.Error(err)
|
||||
} else if _, err = acc.FieldAsInterface([]string{"ID", "test"}); err == nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if _, err := acc.FieldAsInterface([]string{"BalanceMap"}); err != nil {
|
||||
t.Error(err)
|
||||
} else if _, err = acc.FieldAsInterface([]string{"BalanceMap", "first[0]"}); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -116,3 +116,100 @@ func TestActionTriggersClone(t *testing.T) {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestActionTriggerFieldAsInterface(t *testing.T) {
|
||||
at := &ActionTrigger{}
|
||||
if _, err := at.FieldAsInterface([]string{}); err == nil {
|
||||
t.Error(err)
|
||||
} else if _, err = at.FieldAsInterface([]string{"test"}); err == nil {
|
||||
t.Error(err)
|
||||
}
|
||||
at = &ActionTrigger{
|
||||
ID: "id",
|
||||
UniqueID: "unId",
|
||||
ThresholdType: "*max_balance_counter",
|
||||
ThresholdValue: 16.1,
|
||||
Recurrent: true,
|
||||
MinSleep: 1 * time.Second,
|
||||
ExpirationDate: time.Date(2023, 02, 22, 1, 0, 0, 0, time.UTC),
|
||||
ActivationDate: time.Date(2022, 02, 22, 1, 0, 0, 0, time.UTC),
|
||||
Balance: &BalanceFilter{},
|
||||
Weight: 1.02,
|
||||
ActionsID: "acID",
|
||||
MinQueuedItems: 5,
|
||||
Executed: true,
|
||||
LastExecutionTime: time.Date(2022, 2, 22, 1, 0, 0, 0, time.UTC),
|
||||
}
|
||||
if _, err := at.FieldAsInterface([]string{"ID"}); err != nil {
|
||||
t.Error(err)
|
||||
} else if _, err = at.FieldAsInterface([]string{"ID", "test"}); err == nil {
|
||||
t.Error(err)
|
||||
} else if _, err = at.FieldAsInterface([]string{"UniqueID"}); err != nil {
|
||||
t.Error(err)
|
||||
} else if _, err = at.FieldAsInterface([]string{"UniqueID", "test"}); err == nil {
|
||||
t.Error(err)
|
||||
} else if _, err = at.FieldAsInterface([]string{"ThresholdType"}); err != nil {
|
||||
t.Error(err)
|
||||
} else if _, err = at.FieldAsInterface([]string{"ThresholdType", "test"}); err == nil {
|
||||
t.Error(err)
|
||||
} else if _, err = at.FieldAsInterface([]string{"ThresholdValue"}); err != nil {
|
||||
t.Error(err)
|
||||
} else if _, err = at.FieldAsInterface([]string{"ThresholdValue", "test"}); err == nil {
|
||||
t.Error(err)
|
||||
} else if _, err = at.FieldAsInterface([]string{"Recurrent"}); err != nil {
|
||||
t.Error(err)
|
||||
} else if _, err = at.FieldAsInterface([]string{"Recurrent", "test"}); err == nil {
|
||||
t.Error(err)
|
||||
} else if _, err = at.FieldAsInterface([]string{"MinSleep"}); err != nil {
|
||||
t.Error(err)
|
||||
} else if _, err = at.FieldAsInterface([]string{"MinSleep", "test"}); err == nil {
|
||||
t.Error(err)
|
||||
} else if _, err = at.FieldAsInterface([]string{"ExpirationDate"}); err != nil {
|
||||
t.Error(err)
|
||||
} else if _, err = at.FieldAsInterface([]string{"ExpirationDate", "test"}); err == nil {
|
||||
t.Error(err)
|
||||
} else if _, err = at.FieldAsInterface([]string{"ActivationDate"}); err != nil {
|
||||
t.Error(err)
|
||||
} else if _, err = at.FieldAsInterface([]string{"ActivationDate", "test"}); err == nil {
|
||||
t.Error(err)
|
||||
} else if _, err = at.FieldAsInterface([]string{"Balance"}); err != nil {
|
||||
t.Error(err)
|
||||
} else if _, err = at.FieldAsInterface([]string{"Balance", "test"}); err == nil {
|
||||
t.Error(err)
|
||||
} else if _, err = at.FieldAsInterface([]string{"Weight"}); err != nil {
|
||||
t.Error(err)
|
||||
} else if _, err = at.FieldAsInterface([]string{"Weight", "test"}); err == nil {
|
||||
t.Error(err)
|
||||
} else if _, err = at.FieldAsInterface([]string{"ActionsID"}); err != nil {
|
||||
t.Error(err)
|
||||
} else if _, err = at.FieldAsInterface([]string{"ActionsID", "test"}); err == nil {
|
||||
t.Error(err)
|
||||
} else if _, err = at.FieldAsInterface([]string{"MinQueuedItems"}); err != nil {
|
||||
t.Error(err)
|
||||
} else if _, err = at.FieldAsInterface([]string{"MinQueuedItems", "test"}); err == nil {
|
||||
t.Error(err)
|
||||
} else if _, err = at.FieldAsInterface([]string{"Executed"}); err != nil {
|
||||
t.Error(err)
|
||||
} else if _, err = at.FieldAsInterface([]string{"Executed", "test"}); err == nil {
|
||||
t.Error(err)
|
||||
} else if _, err = at.FieldAsInterface([]string{"LastExecutionTime"}); err != nil {
|
||||
t.Error(err)
|
||||
} else if _, err = at.FieldAsInterface([]string{"LastExecutionTime", "test"}); err == nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestActionTriggerFieldAsString(t *testing.T) {
|
||||
at := &ActionTrigger{
|
||||
ThresholdValue: 2.6,
|
||||
}
|
||||
if _, err := at.FieldAsString([]string{}); err == nil {
|
||||
t.Error(err)
|
||||
} else if val, err := at.FieldAsString([]string{"ThresholdValue"}); err != nil {
|
||||
t.Error(err)
|
||||
} else if val != "2.6" {
|
||||
t.Errorf("received %v", val)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1868,6 +1868,9 @@ func TestCallDescriptorUpdateFromCGREvent(t *testing.T) {
|
||||
TimeStart: time.Date(2015, 3, 23, 6, 0, 0, 0, time.UTC),
|
||||
TimeEnd: time.Date(2015, 3, 23, 6, 30, 0, 0, time.UTC),
|
||||
MaxCostSoFar: 0,
|
||||
ExtraFields: map[string]string{
|
||||
"Extra": "Value",
|
||||
},
|
||||
}
|
||||
cdExpected := &CallDescriptor{
|
||||
Category: "call",
|
||||
@@ -1878,8 +1881,11 @@ func TestCallDescriptorUpdateFromCGREvent(t *testing.T) {
|
||||
TimeStart: time.Date(2015, 3, 23, 6, 0, 0, 0, time.UTC),
|
||||
TimeEnd: time.Date(2015, 3, 23, 6, 30, 0, 0, time.UTC),
|
||||
MaxCostSoFar: 0,
|
||||
ExtraFields: map[string]string{
|
||||
"Extra": "Value",
|
||||
},
|
||||
}
|
||||
if err := cd.UpdateFromCGREvent(cgrEv, []string{utils.AccountField, utils.Subject}); err != nil {
|
||||
if err := cd.UpdateFromCGREvent(cgrEv, []string{utils.Usage, utils.AnswerTime, utils.Destination, utils.Category, utils.ToR, utils.Tenant, utils.AccountField, utils.Subject}); err != nil {
|
||||
t.Error(err)
|
||||
} else {
|
||||
if !reflect.DeepEqual(cd, cdExpected) {
|
||||
@@ -1907,6 +1913,24 @@ func TestCallDescriptorUpdateFromCGREvent(t *testing.T) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", cdExpected, cd)
|
||||
}
|
||||
}
|
||||
cgrEv = &utils.CGREvent{}
|
||||
if err = cd.UpdateFromCGREvent(cgrEv, []string{utils.Usage}); err == nil {
|
||||
t.Error(err)
|
||||
} else if err = cd.UpdateFromCGREvent(cgrEv, []string{utils.AnswerTime}); err == nil {
|
||||
t.Error(err)
|
||||
} else if err = cd.UpdateFromCGREvent(cgrEv, []string{utils.Destination}); err == nil {
|
||||
t.Error(err)
|
||||
} else if err = cd.UpdateFromCGREvent(cgrEv, []string{utils.Category}); err == nil {
|
||||
t.Error(err)
|
||||
} else if err = cd.UpdateFromCGREvent(cgrEv, []string{utils.ToR}); err == nil {
|
||||
t.Error(err)
|
||||
} else if err = cd.UpdateFromCGREvent(cgrEv, []string{utils.Tenant}); err == nil {
|
||||
t.Error(err)
|
||||
} else if err = cd.UpdateFromCGREvent(cgrEv, []string{utils.AccountField}); err == nil {
|
||||
t.Error(err)
|
||||
} else if err = cd.UpdateFromCGREvent(cgrEv, []string{utils.Subject}); err == nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2478,3 +2502,24 @@ func TestCDRefundIncrementspanic(t *testing.T) {
|
||||
t.Error("Error refunding money: ", utils.ToIJSON(ub.BalanceMap))
|
||||
}
|
||||
}
|
||||
func TestValidateCallData(t *testing.T) {
|
||||
|
||||
cd := &CallDescriptor{
|
||||
|
||||
TimeStart: time.Date(2022, 07, 02, 20, 0, 0, 0, time.UTC),
|
||||
TimeEnd: time.Date(2022, 07, 02, 20, 0, 0, 0, time.UTC),
|
||||
}
|
||||
if err := cd.ValidateCallData(); err == nil {
|
||||
t.Error(err)
|
||||
}
|
||||
cd.TimeEnd = time.Date(2022, 07, 02, 21, 0, 0, 0, time.UTC)
|
||||
cd.DurationIndex = 62 * time.Minute
|
||||
if err := cd.ValidateCallData(); err == nil {
|
||||
t.Error(err)
|
||||
}
|
||||
cd.DurationIndex = 60 * time.Minute
|
||||
if err = cd.ValidateCallData(); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -814,3 +814,11 @@ func TestRGRateCloneNil(t *testing.T) {
|
||||
t.Errorf("\nExpecting: <nil>,\n Received: <%+v>", result)
|
||||
}
|
||||
}
|
||||
|
||||
func RITimingAsFieldInterface(t *testing.T) {
|
||||
ri := &RateInterval{}
|
||||
if _, err := ri.Timing.FieldAsInterface([]string{}); err == nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -901,9 +901,51 @@ func TestUnitCounterFieldAsString(t *testing.T) {
|
||||
Weight: utils.Float64Pointer(15),
|
||||
}}},
|
||||
}
|
||||
if _, err := uc.FieldAsString(fldPath); err == nil {
|
||||
if _, err := uc.FieldAsString(fldPath); err == nil || err != utils.ErrNotFound {
|
||||
t.Error(err)
|
||||
} else if _, err := uc.FieldAsString([]string{utils.Counters}); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestUnitCounterFilterFieldAsInterFace(t *testing.T) {
|
||||
cfs := &CounterFilter{
|
||||
Value: 2.3,
|
||||
Filter: &BalanceFilter{
|
||||
ID: utils.StringPointer("testID2"),
|
||||
Type: utils.StringPointer("kind"),
|
||||
Weight: utils.Float64Pointer(15),
|
||||
}}
|
||||
if _, err := cfs.FieldAsInterface([]string{}); err == nil {
|
||||
t.Error(err)
|
||||
} else if _, err = cfs.FieldAsInterface([]string{"test"}); err == nil {
|
||||
t.Error(err)
|
||||
} else if _, err = cfs.FieldAsInterface([]string{utils.Value}); err != nil {
|
||||
t.Error(err)
|
||||
} else if _, err = cfs.FieldAsInterface([]string{utils.Value, "test"}); err == nil {
|
||||
t.Error(err)
|
||||
} else if val, err := cfs.FieldAsInterface([]string{utils.Filter}); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(val, cfs.Filter) {
|
||||
t.Errorf("expected %v ,received %v", utils.ToJSON(cfs.Filter), utils.ToJSON(val))
|
||||
} else if _, err = cfs.FieldAsInterface([]string{utils.Filter, "test"}); err == nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestUnitCounterFilterFieldAsString(t *testing.T) {
|
||||
cfs := &CounterFilter{
|
||||
Value: 2.3,
|
||||
Filter: &BalanceFilter{
|
||||
ID: utils.StringPointer("testID2"),
|
||||
Type: utils.StringPointer("kind"),
|
||||
Weight: utils.Float64Pointer(15),
|
||||
},
|
||||
}
|
||||
if _, err := cfs.FieldAsString([]string{}); err == nil {
|
||||
t.Error(err)
|
||||
} else if _, err = cfs.FieldAsString([]string{utils.Value}); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -678,9 +678,6 @@ func Difference(tm string, items ...interface{}) (diff interface{}, err error) {
|
||||
}
|
||||
items[i] = diff
|
||||
return Difference(tm, items[i:]...)
|
||||
} else {
|
||||
|
||||
fmt.Println(err)
|
||||
}
|
||||
|
||||
if itmVal, err := IfaceAsDuration(item); err != nil {
|
||||
|
||||
Reference in New Issue
Block a user