mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-16 05:39:54 +05:00
Improving coverage tests at engine
This commit is contained in:
committed by
Dan Christian Bogos
parent
f45d33a70b
commit
00961123ff
@@ -340,3 +340,41 @@ func TestATExecute(t *testing.T) {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetNextStartTimeOld(t *testing.T) {
|
||||
at := &ActionTiming{
|
||||
Uuid: utils.GenUUID(),
|
||||
Timing: &RateInterval{
|
||||
Timing: &RITiming{
|
||||
Years: utils.Years{2023},
|
||||
Months: utils.Months{},
|
||||
MonthDays: utils.MonthDays{},
|
||||
WeekDays: utils.WeekDays{},
|
||||
StartTime: utils.ASAP,
|
||||
},
|
||||
},
|
||||
Weight: 10,
|
||||
ActionsID: "MINI",
|
||||
}
|
||||
|
||||
loc, _ := time.LoadLocation("America/New_York")
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
expected time.Time
|
||||
}{
|
||||
{
|
||||
name: "Test Case 1",
|
||||
expected: time.Date(2023, 1, 1, 0, 0, 0, 0, loc),
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
got := at.GetNextStartTimeOld(now)
|
||||
if !got.Equal(tt.expected) {
|
||||
t.Errorf("GetNextStartTimeOld() = %v, want %v", got, tt.expected)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1355,3 +1355,50 @@ func TestUsageAsCDR(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestMetaHandler(t *testing.T) {
|
||||
cfg, _ := config.NewDefaultCGRConfig()
|
||||
storedCdr1 := &CDR{
|
||||
CGRID: utils.Sha1("dsafdsaf", time.Unix(1383813745, 0).UTC().String()),
|
||||
ToR: utils.VOICE, OriginID: "dsafdsaf", OriginHost: "192.168.1.1",
|
||||
RequestType: utils.META_RATED, Tenant: "cgrates.org", Category: "call",
|
||||
Account: "1001", Subject: "1001", Destination: "1002",
|
||||
SetupTime: time.Unix(1383813745, 0).UTC(),
|
||||
AnswerTime: time.Unix(1383813746, 0).UTC(),
|
||||
Usage: time.Duration(10) * time.Second,
|
||||
RunID: utils.MetaDefault, Cost: 1.01,
|
||||
ExtraFields: map[string]string{"extra1": "val_extra1",
|
||||
"extra2": "val_extra2", "extra3": "val_extra3"},
|
||||
}
|
||||
cdre, err := NewCDRExporter([]*CDR{storedCdr1},
|
||||
cfg.CdreProfiles[utils.MetaDefault], utils.MetaFileCSV, "", "", "firstexport",
|
||||
true, 1, utils.CSV_SEP, cfg.GeneralCfg().HttpSkipTlsVerify, nil, nil)
|
||||
if err != nil {
|
||||
t.Error("Unexpected error received: ", err)
|
||||
}
|
||||
|
||||
tests := []struct {
|
||||
tag string
|
||||
expected string
|
||||
}{
|
||||
{metaExportID, cdre.exportID},
|
||||
{metaTimeNow, time.Now().Format("")},
|
||||
{metaSMSUsage, "~Usage"},
|
||||
{metaMMSUsage, "~Usage"},
|
||||
{metaGenericUsage, "~Usage"},
|
||||
{metaDataUsage, "~Usage"},
|
||||
{metaCostCDRs, "0"},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.tag, func(t *testing.T) {
|
||||
got, err := cdre.metaHandler(tt.tag, "")
|
||||
if err != nil {
|
||||
t.Errorf("metaHandler() returned error: %v", err)
|
||||
}
|
||||
if got != tt.expected {
|
||||
t.Errorf("metaHandler() = %v, want %v", got, tt.expected)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -973,3 +973,33 @@ func TestSupplierServicePopulateSortingData(t *testing.T) {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestArgsSuppAsOptsGetSupplier(t *testing.T) {
|
||||
cfg, _ := config.NewDefaultCGRConfig()
|
||||
tmpDm := dm
|
||||
defer func() {
|
||||
dm = tmpDm
|
||||
}()
|
||||
db := NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items)
|
||||
dm := NewDataManager(db, cfg.CacheCfg(), nil)
|
||||
ev := &ArgsGetSuppliers{
|
||||
MaxCost: utils.MetaEventCost,
|
||||
CGREvent: &utils.CGREvent{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "CostSuppliers",
|
||||
Event: map[string]interface{}{
|
||||
utils.Account: "1003",
|
||||
utils.Subject: "1001",
|
||||
utils.Destination: "1002",
|
||||
utils.Category: "call",
|
||||
utils.SetupTime: time.Date(2017, 12, 1, 14, 25, 0, 0, time.UTC),
|
||||
utils.Usage: "1m20s",
|
||||
},
|
||||
},
|
||||
}
|
||||
SetDataStorage(dm)
|
||||
if _, err := ev.asOptsGetSuppliers(); err == nil {
|
||||
t.Error(err)
|
||||
}
|
||||
//unifinished
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user