mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 10:06:24 +05:00
Add coverage tests on engine
This commit is contained in:
committed by
Dan Christian Bogos
parent
cd2362ef57
commit
17248c5dde
@@ -2822,3 +2822,47 @@ func TestCallDescriptorgetgetRatingPlansForPrefix(t *testing.T) {
|
||||
}
|
||||
Cache.Clear(nil)
|
||||
}
|
||||
|
||||
func TestAddRatingInfos(t *testing.T) {
|
||||
tests := []struct {
|
||||
existingRating RatingInfos
|
||||
newRating RatingInfos
|
||||
expected RatingInfos
|
||||
}{
|
||||
{
|
||||
existingRating: RatingInfos{
|
||||
&RatingInfo{ActivationTime: time.Date(2025, 4, 3, 9, 0, 0, 0, time.UTC), RateIntervals: RateIntervalList{&RateInterval{}}},
|
||||
},
|
||||
newRating: RatingInfos{
|
||||
&RatingInfo{ActivationTime: time.Date(2025, 4, 3, 8, 30, 0, 0, time.UTC), RateIntervals: RateIntervalList{&RateInterval{}}},
|
||||
},
|
||||
expected: RatingInfos{
|
||||
&RatingInfo{ActivationTime: time.Date(2025, 4, 3, 8, 30, 0, 0, time.UTC), RateIntervals: RateIntervalList{&RateInterval{}}},
|
||||
&RatingInfo{ActivationTime: time.Date(2025, 4, 3, 9, 0, 0, 0, time.UTC), RateIntervals: RateIntervalList{&RateInterval{}}},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run("Add Rating Infos", func(t *testing.T) {
|
||||
cd := &CallDescriptor{
|
||||
RatingInfos: tt.existingRating,
|
||||
}
|
||||
|
||||
cd.addRatingInfos(tt.newRating)
|
||||
|
||||
if len(cd.RatingInfos) != len(tt.expected) {
|
||||
t.Errorf("Expected %d RatingInfos, got %d", len(tt.expected), len(cd.RatingInfos))
|
||||
}
|
||||
|
||||
for i, ri := range cd.RatingInfos {
|
||||
if !ri.ActivationTime.Equal(tt.expected[i].ActivationTime) {
|
||||
t.Errorf("Expected activation time %v, got %v", tt.expected[i].ActivationTime, ri.ActivationTime)
|
||||
}
|
||||
if !reflect.DeepEqual(ri.RateIntervals, tt.expected[i].RateIntervals) {
|
||||
t.Errorf("Expected RateIntervals %v, got %v", tt.expected[i].RateIntervals, ri.RateIntervals)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2604,3 +2604,80 @@ func TestNewMapEventFromReqForm_ParseForm(t *testing.T) {
|
||||
t.Fatalf("Expected no error, got %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestArgV1ProcessEventsClone(t *testing.T) {
|
||||
original := &ArgV1ProcessEvents{
|
||||
Flags: []string{"flag1", "flag2"},
|
||||
CGREvents: []*utils.CGREvent{
|
||||
{
|
||||
ID: "event1",
|
||||
Tenant: "cgrates.org",
|
||||
Time: utils.TimePointer(time.Now()),
|
||||
Event: map[string]any{"key": "value"},
|
||||
APIOpts: map[string]any{"opt1": "val1"},
|
||||
},
|
||||
{
|
||||
ID: "event2",
|
||||
Tenant: "cgrates.org2",
|
||||
Time: utils.TimePointer(time.Now().Add(1 * time.Hour)),
|
||||
Event: map[string]any{"key2": "value2"},
|
||||
APIOpts: map[string]any{"opt2": "val2"},
|
||||
},
|
||||
},
|
||||
APIOpts: map[string]any{"apiOpt1": "optValue"},
|
||||
}
|
||||
|
||||
cloned := original.Clone()
|
||||
|
||||
if cloned == original {
|
||||
t.Errorf("Expected a new cloned object, but the cloned object is the same as the original.")
|
||||
}
|
||||
|
||||
if len(cloned.Flags) != len(original.Flags) {
|
||||
t.Errorf("Expected Flags length to be %d, got %d", len(original.Flags), len(cloned.Flags))
|
||||
} else {
|
||||
for i := range original.Flags {
|
||||
if original.Flags[i] != cloned.Flags[i] {
|
||||
t.Errorf("Expected Flags[%d] to be '%s', got '%s'", i, original.Flags[i], cloned.Flags[i])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if len(cloned.CGREvents) != len(original.CGREvents) {
|
||||
t.Errorf("Expected CGEvents length to be %d, got %d", len(original.CGREvents), len(cloned.CGREvents))
|
||||
} else {
|
||||
for i, originalEvent := range original.CGREvents {
|
||||
clonedEvent := cloned.CGREvents[i]
|
||||
if originalEvent == clonedEvent {
|
||||
t.Errorf("Expected CGEvent[%d] to be a clone, but they are the same instance.", i)
|
||||
}
|
||||
if originalEvent.ID != clonedEvent.ID || originalEvent.Tenant != clonedEvent.Tenant {
|
||||
t.Errorf("Expected CGEvent[%d] to have the same values, but got ID: %s and Tenant: %s in the clone", i, clonedEvent.ID, clonedEvent.Tenant)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if len(cloned.APIOpts) != len(original.APIOpts) {
|
||||
t.Errorf("Expected APIOpts length to be %d, got %d", len(original.APIOpts), len(cloned.APIOpts))
|
||||
} else {
|
||||
for key, value := range original.APIOpts {
|
||||
if cloned.APIOpts[key] != value {
|
||||
t.Errorf("Expected APIOpts[%s] to be '%v', got '%v'", key, value, cloned.APIOpts[key])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
original.Flags[0] = "modifiedFlag"
|
||||
original.CGREvents[0].ID = "modifiedEvent"
|
||||
original.APIOpts["apiOpt1"] = "modifiedValue"
|
||||
|
||||
if cloned.Flags[0] == "modifiedFlag" {
|
||||
t.Errorf("Expected cloned Flags to be unaffected, but it was modified.")
|
||||
}
|
||||
if cloned.CGREvents[0].ID == "modifiedEvent" {
|
||||
t.Errorf("Expected cloned CGEvents to be unaffected, but it was modified.")
|
||||
}
|
||||
if cloned.APIOpts["apiOpt1"] == "modifiedValue" {
|
||||
t.Errorf("Expected cloned APIOpts to be unaffected, but it was modified.")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1462,3 +1462,60 @@ func TestSortWeight(t *testing.T) {
|
||||
t.Errorf("Expected sorted routes to be route2, route3, route1, but got %v", sortedRoutes.Routes)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSortQOS(t *testing.T) {
|
||||
routes := []*SortedRoute{
|
||||
{
|
||||
RouteID: "route1",
|
||||
RouteParameters: "param1",
|
||||
sortingDataF64: map[string]float64{
|
||||
utils.MetaPDD: 10,
|
||||
utils.Weight: 5,
|
||||
},
|
||||
},
|
||||
{
|
||||
RouteID: "route2",
|
||||
RouteParameters: "param2",
|
||||
sortingDataF64: map[string]float64{
|
||||
utils.MetaPDD: 20,
|
||||
utils.Weight: 5,
|
||||
},
|
||||
},
|
||||
{
|
||||
RouteID: "route3",
|
||||
RouteParameters: "param3",
|
||||
sortingDataF64: map[string]float64{
|
||||
utils.MetaPDD: 15,
|
||||
utils.Weight: 3,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
sortedRoutes := &SortedRoutes{
|
||||
ProfileID: "testProfile",
|
||||
Sorting: "QOS",
|
||||
Routes: routes,
|
||||
}
|
||||
|
||||
sortedRoutes.SortQOS([]string{utils.MetaPDD})
|
||||
if sortedRoutes.Routes[0].RouteID != "route1" {
|
||||
t.Errorf("Expected route1 at position 0, got %s", sortedRoutes.Routes[0].RouteID)
|
||||
}
|
||||
if sortedRoutes.Routes[1].RouteID != "route3" {
|
||||
t.Errorf("Expected route3 at position 1, got %s", sortedRoutes.Routes[1].RouteID)
|
||||
}
|
||||
if sortedRoutes.Routes[2].RouteID != "route2" {
|
||||
t.Errorf("Expected route2 at position 2, got %s", sortedRoutes.Routes[2].RouteID)
|
||||
}
|
||||
|
||||
sortedRoutes.SortQOS([]string{utils.MetaPDD, utils.Weight})
|
||||
if sortedRoutes.Routes[0].RouteID != "route1" {
|
||||
t.Errorf("Expected route1 at position 0, got %s", sortedRoutes.Routes[0].RouteID)
|
||||
}
|
||||
if sortedRoutes.Routes[1].RouteID != "route3" {
|
||||
t.Errorf("Expected route3 at position 1, got %s", sortedRoutes.Routes[1].RouteID)
|
||||
}
|
||||
if sortedRoutes.Routes[2].RouteID != "route2" {
|
||||
t.Errorf("Expected route2 at position 2, got %s", sortedRoutes.Routes[2].RouteID)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user