Add new unit tests on engine

This commit is contained in:
armirveliaj
2024-07-03 10:00:11 -04:00
committed by Dan Christian Bogos
parent 49657db953
commit fb04c28dab
3 changed files with 125 additions and 0 deletions

View File

@@ -4868,3 +4868,35 @@ func TestActionsAlterAndDisconnectSessions(t *testing.T) {
})
}
}
func TestActionsStringMethod(t *testing.T) {
cdrProvider := &cdrLogProvider{}
expectedJSON := "{}"
jsonStr := cdrProvider.String()
if jsonStr != expectedJSON {
t.Errorf("String() method result does not match expected JSON. Got: %s, Expected: %s", jsonStr, expectedJSON)
}
}
func TestActionsClone(t *testing.T) {
actions := Actions{}
cloned, err := actions.Clone()
if err != nil {
t.Errorf("Expected no error, got %v", err)
}
if len(cloned.(Actions)) != len(actions) {
t.Errorf("Expected cloned Actions length %d, got %d", len(actions), len(cloned.(Actions)))
}
for i := range actions {
if !reflect.DeepEqual(actions[i], cloned.(Actions)[i]) {
t.Errorf("Expected cloned Action[%d] to match original, got %+v", i, cloned.(Actions)[i])
}
}
cloned, err = (Actions)(nil).Clone()
if err != nil {
t.Errorf("Expected no error when apl is nil, got %v", err)
}
if cloned != nil {
t.Errorf("Expected cloned result to be nil when apl is nil, got %+v", cloned)
}
}

View File

@@ -20,6 +20,7 @@ package engine
import (
"bytes"
"encoding/json"
"fmt"
"log"
"os"
"strings"
@@ -884,3 +885,81 @@ func TestBalancesFieldAsInterfaceIndexPath(t *testing.T) {
})
}
func TestBalanceSummaryFieldAsInterfaceUnsupportedField(t *testing.T) {
balanceSummary := &BalanceSummary{}
fldPath := []string{"unsupportedField"}
expectedError := fmt.Sprintf("unsupported field prefix: <%s>", fldPath[0])
_, err := balanceSummary.FieldAsInterface(fldPath)
if err == nil {
t.Fatalf("Expected an error but got nil")
}
if err.Error() != expectedError {
t.Errorf("Expected error: %s, but got: %s", expectedError, err.Error())
}
}
func TestBalancesSummaryFieldAsInterface(t *testing.T) {
var balanceSummary *BalanceSummary
fldPath := []string{"Filed"}
_, err := balanceSummary.FieldAsInterface(fldPath)
if err != utils.ErrNotFound {
t.Fatalf("Expected utils.ErrNotFound but got: %v", err)
}
balanceSummary = &BalanceSummary{}
fldPath = []string{}
_, err = balanceSummary.FieldAsInterface(fldPath)
if err != utils.ErrNotFound {
t.Fatalf("Expected utils.ErrNotFound but got: %v", err)
}
fldPath = []string{"unsupportedField"}
expectedError := fmt.Sprintf("unsupported field prefix: <%s>", fldPath[0])
_, err = balanceSummary.FieldAsInterface(fldPath)
if err == nil {
t.Fatalf("Expected an error but got nil")
}
if err.Error() != expectedError {
t.Errorf("Expected error: %s, but got: %s", expectedError, err.Error())
}
}
func TestBalancesHardMatchFilterNilFilter(t *testing.T) {
balance := &Balance{}
var balanceFilter *BalanceFilter = nil
result := balance.HardMatchFilter(balanceFilter, false)
if result != true {
t.Errorf("Expected true when balanceFilter is nil, but got %v", result)
}
}
func TestBalancesHardMatchFilter(t *testing.T) {
t.Run("NilFilter", func(t *testing.T) {
balance := &Balance{}
var balanceFilter *BalanceFilter = nil
result := balance.HardMatchFilter(balanceFilter, false)
if result != true {
t.Errorf("Expected true when balanceFilter is nil, but got %v", result)
}
})
t.Run("UuidMatch", func(t *testing.T) {
expectedUuid := "1"
balance := &Balance{Uuid: expectedUuid}
balanceFilter := &BalanceFilter{Uuid: &expectedUuid}
result := balance.HardMatchFilter(balanceFilter, false)
if result != true {
t.Errorf("Expected true when Uuid matches, but got %v", result)
}
})
t.Run("UuidNoMatch", func(t *testing.T) {
balance := &Balance{Uuid: "1"}
nonMatchingUuid := "2"
balanceFilter := &BalanceFilter{Uuid: &nonMatchingUuid}
result := balance.HardMatchFilter(balanceFilter, false)
if result != false {
t.Errorf("Expected false when Uuid doesn't match, but got %v", result)
}
})
}

View File

@@ -1430,3 +1430,17 @@ func TestResponderGetCostOnRatingPlans(t *testing.T) {
t.Errorf("expected %v, got %v", exp, reply)
}
}
func TestResponderPingResponder(t *testing.T) {
responder := &Responder{}
ctx := context.Background()
var event *utils.CGREvent = nil
var reply string
err := responder.Ping(ctx, event, &reply)
if reply != utils.Pong {
t.Errorf("Expected reply to be '%s', got '%s'", utils.Pong, reply)
}
if err != nil {
t.Errorf("Expected error to be nil, got %v", err)
}
}