mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Add new unit tests on engine
This commit is contained in:
committed by
Dan Christian Bogos
parent
eba876eec8
commit
36c623599e
@@ -20,6 +20,7 @@ package engine
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
@@ -434,3 +435,27 @@ func TestEngineActionTriggerEquals(t *testing.T) {
|
||||
t.Errorf("Expected %v not to equal %v, but it did.", at1, at3)
|
||||
}
|
||||
}
|
||||
|
||||
func TestStringToJson(t *testing.T) {
|
||||
at := &ActionTrigger{
|
||||
ID: "321",
|
||||
UniqueID: "122",
|
||||
ThresholdType: "*min_event_counter",
|
||||
ThresholdValue: 10.0,
|
||||
Recurrent: true,
|
||||
MinSleep: 5 * time.Second,
|
||||
ExpirationDate: time.Now().AddDate(0, 0, 7),
|
||||
ActivationDate: time.Now(),
|
||||
Balance: nil,
|
||||
Weight: 0.5,
|
||||
ActionsID: "123",
|
||||
MinQueuedItems: 100,
|
||||
Executed: false,
|
||||
LastExecutionTime: time.Now().Add(-time.Hour),
|
||||
}
|
||||
result := at.String()
|
||||
expected, _ := json.Marshal(at)
|
||||
if result != string(expected) {
|
||||
t.Errorf("String method returned unexpected result, got: %s, want: %s", result, string(expected))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2768,3 +2768,56 @@ func TestEngineCallDescriptorString(t *testing.T) {
|
||||
t.Errorf("Expected CallDescriptor.String() to return %s, got %s", want, got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCallDescriptorClone(t *testing.T) {
|
||||
originalCD := &CallDescriptor{
|
||||
Category: "call",
|
||||
Tenant: "cgrates.org",
|
||||
Subject: "user",
|
||||
Account: "testAccount",
|
||||
Destination: "local",
|
||||
TimeStart: time.Date(2022, time.January, 7, 16, 60, 0, 0, time.UTC),
|
||||
TimeEnd: time.Date(2022, time.January, 7, 16, 60, 0, 0, time.UTC),
|
||||
LoopIndex: 1,
|
||||
DurationIndex: time.Minute * 3,
|
||||
FallbackSubject: "testfallbacksubject",
|
||||
ToR: utils.MetaVoice,
|
||||
ExtraFields: map[string]string{"key1": "value1"},
|
||||
MaxRate: 10.0,
|
||||
MaxRateUnit: time.Minute,
|
||||
MaxCostSoFar: 0.5,
|
||||
CgrID: "grid1",
|
||||
RunID: "runID123",
|
||||
ForceDuration: false,
|
||||
PerformRounding: true,
|
||||
DenyNegativeAccount: true,
|
||||
DryRun: false,
|
||||
}
|
||||
clonedCD := originalCD.Clone()
|
||||
if originalCD == clonedCD {
|
||||
t.Errorf("Expected cloned CallDescriptor to be a new instance, got pointer to original")
|
||||
}
|
||||
}
|
||||
|
||||
func TestCallDescriptorgetgetRatingPlansForPrefix(t *testing.T) {
|
||||
Cache.Clear(nil)
|
||||
cd := CallDescriptor{
|
||||
Category: "sms",
|
||||
Tenant: "cgrates.org",
|
||||
Subject: "testAccITAddBalanceWithDestinations",
|
||||
Account: "testAccITAddBalanceWithDestinations",
|
||||
Destination: "1003",
|
||||
DurationIndex: 0,
|
||||
}
|
||||
// Default FallbackDepth is 3
|
||||
got, err := cd.getRatingPlansForPrefix("testkey", 4)
|
||||
|
||||
if err != utils.ErrMaxRecursionDepth {
|
||||
t.Errorf("getRatingPlansForPrefix() expected %v, got %v, ", utils.ErrMaxRecursionDepth, err)
|
||||
|
||||
} else if got != 4 {
|
||||
t.Errorf("getRatingPlansForPrefix() expected %v, got %v, ", 4, got)
|
||||
}
|
||||
|
||||
Cache.Clear(nil)
|
||||
}
|
||||
|
||||
@@ -2361,3 +2361,25 @@ func TestV1RateCDRsSuccesful(t *testing.T) {
|
||||
t.Error("Expected reply to be ok")
|
||||
}
|
||||
}
|
||||
|
||||
func TestCdrsSetCloneable(t *testing.T) {
|
||||
tests := []struct {
|
||||
input bool
|
||||
expected bool
|
||||
}{
|
||||
{input: true, expected: true},
|
||||
{input: false, expected: false},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
attr := &ArgV1ProcessEvents{
|
||||
Flags: []string{},
|
||||
CGREvents: []*utils.CGREvent{},
|
||||
APIOpts: make(map[string]any),
|
||||
clnb: !tt.input,
|
||||
}
|
||||
attr.SetCloneable(tt.input)
|
||||
if attr.clnb != tt.expected {
|
||||
t.Errorf("SetCloneable(%v) = %v; expected %v", tt.input, attr.clnb, tt.expected)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user