coverage tests at engine

This commit is contained in:
gezimbll
2022-11-03 11:13:51 -04:00
committed by Dan Christian Bogos
parent c2a5259f75
commit 93292fac71
5 changed files with 199 additions and 4 deletions

View File

@@ -2728,3 +2728,20 @@ func TestGetSharedGroups(t *testing.T) {
t.Errorf("expected %v ,received %v", utils.ToJSON(val), utils.ToJSON(exp))
}
}
func TestAccountAsOldStructure(t *testing.T) {
acc := &Account{}
expAcc := &Account{
ID: "*out:",
BalanceMap: map[string]Balances{},
UnitCounters: UnitCounters{},
ActionTriggers: ActionTriggers{},
AllowNegative: false,
Disabled: false,
}
if val := acc.AsOldStructure(); reflect.DeepEqual(val, expAcc) {
t.Errorf("expected %v ,received %v ", utils.ToJSON(expAcc), utils.ToJSON(val))
}
}

View File

@@ -2521,7 +2521,12 @@ func TestValueFormulaDebit(t *testing.T) {
}
func TestClonedAction(t *testing.T) {
a := &Action{
var a *Action
if clone := a.Clone(); clone != nil {
t.Errorf("Expected nil but got %v", clone)
}
a = &Action{
Id: "test1",
ActionType: utils.MetaTopUp,
Balance: &BalanceFilter{

View File

@@ -85,10 +85,15 @@ func TestNewBalanceFilter(t *testing.T) {
if _, err := NewBalanceFilter(attrs, ""); err == nil {
t.Error("Expecxted error received nil")
}
attrs[utils.ExpiryTime] = "NotTime"
if _, err := NewBalanceFilter(attrs, ""); err == nil {
t.Error("Expecxted error received nil")
}
attrs[utils.Value] = "NotFloat"
if _, err := NewBalanceFilter(attrs, ""); err == nil {
t.Error("Expecxted error received nil")
}
}
func TestBalanceFilterClone(t *testing.T) {
@@ -477,3 +482,57 @@ func TestBalanceFilterFieldAsString(t *testing.T) {
t.Error(err)
}
}
func TestBalanceFilterModifyBalance(t *testing.T) {
bf := &BalanceFilter{
ID: utils.StringPointer("id"),
ExpirationDate: utils.TimePointer(time.Date(2022, 12, 24, 10, 0, 0, 0, time.UTC)),
RatingSubject: utils.StringPointer("rating"),
Categories: &utils.StringMap{
"exp": true,
},
SharedGroups: &utils.StringMap{
"shared": false,
},
TimingIDs: &utils.StringMap{
"one": true,
},
Blocker: utils.BoolPointer(true),
Timings: []*RITiming{
{
ID: "tId",
Years: utils.Years{2, 1},
},
},
Disabled: utils.BoolPointer(true),
}
b := &Balance{}
exp := &Balance{
ID: "id",
ExpirationDate: time.Date(2022, 12, 24, 10, 0, 0, 0, time.UTC),
Weight: 0,
RatingSubject: "rating",
Categories: utils.StringMap{"exp": true},
SharedGroups: utils.StringMap{
"shared": false},
Timings: []*RITiming{
{
ID: "tId",
Years: utils.Years{2, 1},
},
},
TimingIDs: utils.StringMap{
"one": true},
Disabled: true,
Blocker: true}
bf.ModifyBalance(b)
if reflect.DeepEqual(b, exp) {
t.Errorf("expected %v ,received %v", utils.ToJSON(exp), utils.ToJSON(b))
}
}

View File

@@ -225,6 +225,7 @@ func TestBalanceMatchActionTriggerWeight(t *testing.T) {
}
func TestBalanceMatchActionTriggerRatingSubject(t *testing.T) {
at := &ActionTrigger{Balance: &BalanceFilter{RatingSubject: utils.StringPointer("test")}}
b := &Balance{RatingSubject: "test"}
if !b.MatchActionTrigger(at) {
@@ -302,3 +303,78 @@ func TestBalanceIsExpiredAt(t *testing.T) {
}
}
func TestBalanceAsInterface(t *testing.T) {
b := &Balance{
Uuid: "uuid",
ID: "id",
Value: 2.21,
ExpirationDate: time.Date(2022, 11, 22, 9, 0, 0, 0, time.UTC),
Weight: 2.88,
DestinationIDs: utils.StringMap{
"destId1": true,
"destId2": true,
},
RatingSubject: "rating",
Categories: utils.StringMap{
"ctg1": true,
"ctg2": false,
},
SharedGroups: utils.StringMap{
"shgp1": false,
"shgp2": true,
},
Timings: []*RITiming{
{
ID: "id",
Years: utils.Years{2, 3},
},
},
TimingIDs: utils.StringMap{
"timingid1": true,
"timingid2": false,
},
Factor: ValueFactor{
"factor1": 2.21,
"factor2": 1.34,
},
}
if _, err := b.FieldAsInterface([]string{}); err == nil || err != utils.ErrNotFound {
t.Error(err)
} else if _, err = b.FieldAsInterface([]string{"value"}); err == nil {
t.Error(err)
} else if _, err = b.FieldAsInterface([]string{"DestinationIDs[destId1]", "secondVal"}); err == nil || err != utils.ErrNotFound {
t.Error(err)
} else if _, err = b.FieldAsInterface([]string{"Categories[ctg1]", "secondVal"}); err == nil || err != utils.ErrNotFound {
t.Error(err)
} else if _, err = b.FieldAsInterface([]string{"SharedGroups[shgp1]", "secondVal"}); err == nil || err != utils.ErrNotFound {
t.Error(err)
} else if _, err = b.FieldAsInterface([]string{"TimingIDs[timingid1]", "secondVal"}); err == nil || err != utils.ErrNotFound {
t.Error(err)
} else if _, err = b.FieldAsInterface([]string{"Timings[zero]"}); err == nil {
t.Error(err)
} else if _, err = b.FieldAsInterface([]string{"Timings[2]"}); err == nil || err != utils.ErrNotFound {
t.Error(err)
} else if _, err = b.FieldAsInterface([]string{"Timings[2]", "val"}); err == nil {
t.Error(err)
} else if _, err = b.FieldAsInterface([]string{"Factor[factor1]", "secondVal"}); err == nil || err != utils.ErrNotFound {
t.Error(err)
}
if _, err = b.FieldAsInterface([]string{"DestinationIDs[destId1]"}); err != nil {
t.Error(err)
} else if _, err = b.FieldAsInterface([]string{"Categories[ctg1]"}); err != nil {
t.Error(err)
} else if _, err = b.FieldAsInterface([]string{"SharedGroups[shgp1]"}); err != nil {
t.Error(err)
} else if _, err = b.FieldAsInterface([]string{"TimingIDs[timingid1]"}); err != nil {
t.Error(err)
} else if _, err = b.FieldAsInterface([]string{"Timings[0]"}); err != nil {
t.Error(err)
} else if _, err = b.FieldAsInterface([]string{"Factor[factor1]"}); err != nil {
t.Error(err)
}
}

View File

@@ -470,6 +470,11 @@ func TestCDRAsExternalCDR(t *testing.T) {
if cdrOut := storCdr.AsExternalCDR(); !reflect.DeepEqual(expectOutCdr, cdrOut) {
t.Errorf("Expected: %+v, received: %+v", expectOutCdr, cdrOut)
}
expectOutCdr.ToR, storCdr.ToR, expectOutCdr.Usage = "other", "other", "10000000000"
if cdrOut := storCdr.AsExternalCDR(); !reflect.DeepEqual(expectOutCdr, cdrOut) {
t.Errorf("Expected: %+v, received: %+v", expectOutCdr, cdrOut)
}
}
func TestUsageReqAsCD(t *testing.T) {
@@ -491,10 +496,39 @@ func TestUsageReqAsCD(t *testing.T) {
} else if !reflect.DeepEqual(eCD, cd) {
t.Errorf("Expected: %+v, received: %+v", eCD, cd)
}
}
func TestUsageReqAsCDNil(t *testing.T) {
req := &UsageRecord{
ToR: utils.MetaVoice, RequestType: utils.MetaRated,
Tenant: "cgrates.org", Category: "call",
Account: "1001", Subject: "1001", Destination: "1002",
Usage: "test",
SetupTime: "2013-11-07T08:42:26Z",
ExtraFields: map[string]string{
"ExtraField1": "extraVal",
},
}
if _, err := req.AsCallDescriptor("/time.zone", true); err == nil {
t.Error(err)
} else if _, err = req.AsCallDescriptor("", true); err == nil {
t.Error(err)
}
req.Usage = "10"
if _, err := req.AsCallDescriptor("", true); err != nil {
t.Error(err)
}
}
func TestCdrClone(t *testing.T) {
cdr := &CDR{}
var cdr *CDR
if val := cdr.Clone(); val != nil {
t.Errorf("expected nil , received %v ", val)
}
cdr = &CDR{}
eOut := &CDR{}
if rcv := cdr.Clone(); !reflect.DeepEqual(rcv, eOut) {
t.Errorf("Expecting: %+v, received: %+v", eOut, rcv)
@@ -749,8 +783,12 @@ func TestCDRNewCDRFromSQL(t *testing.T) {
} else if !reflect.DeepEqual(cdr, eCDR) {
t.Errorf("Expecting: %+v, received: %+v", cdr, eCDR)
}
cdrSQL.ExtraFields = "extrafield"
if _, err := NewCDRFromSQL(cdrSQL); err == nil {
cdrSQL.CostDetails = "val"
if _, err = NewCDRFromSQL(cdrSQL); err == nil {
t.Error(err)
}
cdrSQL.ExtraFields = "test"
if _, err = NewCDRFromSQL(cdrSQL); err == nil {
t.Error(err)
}
}