mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-17 06:09:53 +05:00
Add coverage tests for engine
This commit is contained in:
committed by
Dan Christian Bogos
parent
d54e3959de
commit
f0a2695350
@@ -5979,3 +5979,117 @@ func TestAPItoTPStatsMetricNewDynamicBlockersFromStringErr(t *testing.T) {
|
||||
t.Errorf("expecting: \n%+v\n, received: \n%+v", expErr, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCsvDumpForThresholdModels(t *testing.T) {
|
||||
tpThPrf := &utils.TPThresholdProfile{
|
||||
TPid: "TP1",
|
||||
Tenant: "cgrates.org",
|
||||
ID: "TH_1",
|
||||
FilterIDs: []string{"FilterID1", "*ai:~*req.AnswerTime:2014-07-14T14:35:00Z"},
|
||||
MaxHits: 12,
|
||||
MinHits: 10,
|
||||
MinSleep: "1s",
|
||||
Blocker: false,
|
||||
Weights: ";20",
|
||||
ActionProfileIDs: []string{"WARN3"},
|
||||
}
|
||||
expected := ThresholdMdls{
|
||||
{
|
||||
Tpid: "TP1",
|
||||
Tenant: "cgrates.org",
|
||||
ID: "TH_1",
|
||||
FilterIDs: "FilterID1",
|
||||
MaxHits: 12,
|
||||
MinHits: 10,
|
||||
MinSleep: "1s",
|
||||
Blocker: false,
|
||||
Weights: ";20",
|
||||
ActionProfileIDs: "WARN3",
|
||||
},
|
||||
{
|
||||
Tpid: "TP1",
|
||||
ID: "TH_1",
|
||||
Tenant: "cgrates.org",
|
||||
FilterIDs: "*ai:~*req.AnswerTime:2014-07-14T14:35:00Z",
|
||||
},
|
||||
}
|
||||
rcv := APItoModelTPThreshold(tpThPrf)
|
||||
if !reflect.DeepEqual(expected, rcv) {
|
||||
t.Errorf("Expecting : %+v,\n received: %+v", utils.ToJSON(expected), utils.ToJSON(rcv))
|
||||
}
|
||||
expRecord := []string{"cgrates.org", "TH_1", "FilterID1", ";20", "12", "10", "1s", "false", "WARN3", "false"}
|
||||
for i, model := range rcv {
|
||||
if i == 1 {
|
||||
expRecord = []string{"cgrates.org", "TH_1", "*ai:~*req.AnswerTime:2014-07-14T14:35:00Z", "", "0", "0", "", "false", "", "false"}
|
||||
}
|
||||
if csvRecordRcv, _ := CsvDump(model); !reflect.DeepEqual(expRecord, csvRecordRcv) {
|
||||
t.Errorf("Expecting : %+v, received: %+v", utils.ToJSON(expRecord), utils.ToJSON(csvRecordRcv))
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestCsvDumpForDispatcherModels(t *testing.T) {
|
||||
tpDispPrf := &utils.TPDispatcherProfile{
|
||||
TPid: "TP1",
|
||||
Tenant: "cgrates.org",
|
||||
ID: "Dsp",
|
||||
FilterIDs: []string{"*ai:~*req.AnswerTime:2014-07-14T14:35:00Z", "FLTR_ACNT_dan", "FLTR_DST_DE"},
|
||||
Strategy: utils.MetaFirst,
|
||||
StrategyParams: []interface{}{},
|
||||
Weight: 20,
|
||||
Hosts: []*utils.TPDispatcherHostProfile{
|
||||
{
|
||||
ID: "C1",
|
||||
FilterIDs: []string{},
|
||||
Weight: 10,
|
||||
Params: []interface{}{"192.168.54.203"},
|
||||
Blocker: false,
|
||||
},
|
||||
{
|
||||
ID: "C2",
|
||||
FilterIDs: []string{},
|
||||
Weight: 10,
|
||||
Params: []interface{}{"192.168.54.204"},
|
||||
Blocker: false,
|
||||
},
|
||||
},
|
||||
}
|
||||
expected := DispatcherProfileMdls{
|
||||
&DispatcherProfileMdl{
|
||||
Tpid: "TP1",
|
||||
Tenant: "cgrates.org",
|
||||
ID: "Dsp",
|
||||
FilterIDs: "*ai:~*req.AnswerTime:2014-07-14T14:35:00Z;FLTR_ACNT_dan;FLTR_DST_DE",
|
||||
Strategy: utils.MetaFirst,
|
||||
Weight: 20,
|
||||
ConnID: "C1",
|
||||
ConnWeight: 10,
|
||||
ConnBlocker: false,
|
||||
ConnParameters: "192.168.54.203",
|
||||
},
|
||||
&DispatcherProfileMdl{
|
||||
Tpid: "TP1",
|
||||
Tenant: "cgrates.org",
|
||||
ID: "Dsp",
|
||||
ConnID: "C2",
|
||||
ConnWeight: 10,
|
||||
ConnBlocker: false,
|
||||
ConnParameters: "192.168.54.204",
|
||||
},
|
||||
}
|
||||
rcv := APItoModelTPDispatcherProfile(tpDispPrf)
|
||||
if !reflect.DeepEqual(expected, rcv) {
|
||||
t.Errorf("Expecting : %+v,\n received: %+v", utils.ToJSON(expected), utils.ToJSON(rcv))
|
||||
}
|
||||
expRecord := []string{"cgrates.org", "Dsp", "*ai:~*req.AnswerTime:2014-07-14T14:35:00Z;FLTR_ACNT_dan;FLTR_DST_DE", "20", "*first", "", "C1", "", "10", "false", "192.168.54.203"}
|
||||
for i, model := range rcv {
|
||||
if i == 1 {
|
||||
expRecord = []string{"cgrates.org", "Dsp", "", "0", "", "", "C2", "", "10", "false", "192.168.54.204"}
|
||||
}
|
||||
if csvRecordRcv, _ := CsvDump(model); !reflect.DeepEqual(expRecord, csvRecordRcv) {
|
||||
t.Errorf("Expecting : %+v, received: %+v", utils.ToJSON(expRecord), utils.ToJSON(csvRecordRcv))
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -3710,3 +3710,131 @@ func TestExportToPrometheusOK(t *testing.T) {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestStatASRClone(t *testing.T) {
|
||||
|
||||
asr := &StatASR{Metric: NewMetric(2, nil)}
|
||||
|
||||
if rcv := asr.Clone(); !reflect.DeepEqual(rcv, asr) {
|
||||
t.Errorf("Expecting <%+v>,\n Recevied <%+v>", asr, rcv)
|
||||
}
|
||||
}
|
||||
|
||||
func TestStatACDClone(t *testing.T) {
|
||||
|
||||
acd := &StatACD{Metric: NewMetric(2, nil)}
|
||||
|
||||
if rcv := acd.Clone(); !reflect.DeepEqual(rcv, acd) {
|
||||
t.Errorf("Expecting <%+v>,\n Recevied <%+v>", acd, rcv)
|
||||
}
|
||||
}
|
||||
|
||||
func TestStatACCClone(t *testing.T) {
|
||||
|
||||
acc := &StatACC{Metric: NewMetric(2, nil)}
|
||||
|
||||
if rcv := acc.Clone(); !reflect.DeepEqual(rcv, acc) {
|
||||
t.Errorf("Expecting <%+v>,\n Recevied <%+v>", acc, rcv)
|
||||
}
|
||||
}
|
||||
|
||||
func TestStatTCCClone(t *testing.T) {
|
||||
|
||||
tcc := &StatTCC{Metric: NewMetric(2, nil)}
|
||||
|
||||
if rcv := tcc.Clone(); !reflect.DeepEqual(rcv, tcc) {
|
||||
t.Errorf("Expecting <%+v>,\n Recevied <%+v>", tcc, rcv)
|
||||
}
|
||||
}
|
||||
|
||||
func TestStatPDDClone(t *testing.T) {
|
||||
|
||||
pdd := &StatPDD{Metric: NewMetric(2, nil)}
|
||||
|
||||
if rcv := pdd.Clone(); !reflect.DeepEqual(rcv, pdd) {
|
||||
t.Errorf("Expecting <%+v>,\n Recevied <%+v>", pdd, rcv)
|
||||
}
|
||||
}
|
||||
|
||||
func TestStatSumClone(t *testing.T) {
|
||||
|
||||
sum := &StatSum{Metric: NewMetric(2, nil), FieldName: "~*opts.*cost"}
|
||||
|
||||
if rcv := sum.Clone(); !reflect.DeepEqual(rcv, sum) {
|
||||
t.Errorf("Expecting <%+v>,\n Recevied <%+v>", sum, rcv)
|
||||
}
|
||||
}
|
||||
|
||||
func TestStatAverageClone(t *testing.T) {
|
||||
|
||||
avg := &StatAverage{Metric: NewMetric(2, nil), FieldName: "~*opts.*cost"}
|
||||
|
||||
if rcv := avg.Clone(); !reflect.DeepEqual(rcv, avg) {
|
||||
t.Errorf("Expecting <%+v>,\n Recevied <%+v>", avg, rcv)
|
||||
}
|
||||
}
|
||||
|
||||
func TestStatTCDClone(t *testing.T) {
|
||||
|
||||
sum := &StatTCD{Metric: NewMetric(2, nil)}
|
||||
|
||||
if rcv := sum.Clone(); !reflect.DeepEqual(rcv, sum) {
|
||||
t.Errorf("Expecting <%+v>,\n Recevied <%+v>", sum, rcv)
|
||||
}
|
||||
}
|
||||
|
||||
func TestStatDDCClone(t *testing.T) {
|
||||
|
||||
ddc := &StatDDC{
|
||||
Events: map[string]map[string]uint64{
|
||||
"EVENT_1": {
|
||||
"1001": 2,
|
||||
},
|
||||
"EVENT_3": {
|
||||
"1002": 1,
|
||||
},
|
||||
},
|
||||
FieldValues: map[string]utils.StringSet{
|
||||
"1001": {
|
||||
"EVENT_1": {},
|
||||
},
|
||||
"1002": {
|
||||
"EVENT_3": {},
|
||||
},
|
||||
},
|
||||
MinItems: 2,
|
||||
Count: 3,
|
||||
}
|
||||
|
||||
if rcv := ddc.Clone(); !reflect.DeepEqual(rcv, ddc) {
|
||||
t.Errorf("Expecting <%+v>,\n Recevied <%+v>", ddc, rcv)
|
||||
}
|
||||
}
|
||||
|
||||
func TestStatDistinctClone(t *testing.T) {
|
||||
|
||||
dst := &StatDistinct{
|
||||
Events: map[string]map[string]uint64{
|
||||
"EVENT_1": {
|
||||
"1001": 2,
|
||||
},
|
||||
"EVENT_3": {
|
||||
"1002": 1,
|
||||
},
|
||||
},
|
||||
FieldValues: map[string]utils.StringSet{
|
||||
"1001": {
|
||||
"EVENT_1": {},
|
||||
},
|
||||
"1002": {
|
||||
"EVENT_3": {},
|
||||
},
|
||||
},
|
||||
MinItems: 2,
|
||||
Count: 3,
|
||||
}
|
||||
|
||||
if rcv := dst.Clone(); !reflect.DeepEqual(rcv, dst) {
|
||||
t.Errorf("Expecting <%+v>,\n Recevied <%+v>", dst, rcv)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user