mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Add coverage tests on agents
This commit is contained in:
committed by
Dan Christian Bogos
parent
13f3f4dc11
commit
f84e7c29a3
@@ -535,3 +535,16 @@ func TestProcessRequest(t *testing.T) {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestV1GetActiveSessionIDs(t *testing.T) {
|
||||
da := &DiameterAgent{}
|
||||
ignParam := "ignore"
|
||||
var sessionIDs []*sessions.SessionID
|
||||
err := da.V1GetActiveSessionIDs(ignParam, &sessionIDs)
|
||||
if err != utils.ErrNotImplemented {
|
||||
t.Errorf("Expected ErrNotImplemented, but got: %v", err)
|
||||
}
|
||||
if len(sessionIDs) != 0 {
|
||||
t.Errorf("Expected sessionIDs slice to be empty, but got %d items", len(sessionIDs))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -826,3 +826,89 @@ func TestKamEventKamReplyString(t *testing.T) {
|
||||
t.Errorf("Unexpected TransactionLabel in parsed KamReply: expected %s, got %v", "label", parsedReply["TransactionLabel"])
|
||||
}
|
||||
}
|
||||
|
||||
func TestKamDlgReplyString(t *testing.T) {
|
||||
kdr := &KamDlgReply{}
|
||||
expectedJSON := `{"Event":"","Jsonrpl_body":null}`
|
||||
result := kdr.String()
|
||||
if result != expectedJSON {
|
||||
t.Errorf("Expected %s, but got %s", expectedJSON, result)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNewKamDlgReply(t *testing.T) {
|
||||
validJSON := []byte(`{"Field1":"test","Field2":123}`)
|
||||
expectedReply := KamDlgReply{}
|
||||
rpl, err := NewKamDlgReply(validJSON)
|
||||
if err != nil {
|
||||
t.Errorf("Expected no error, but got %v", err)
|
||||
}
|
||||
if rpl != expectedReply {
|
||||
t.Errorf("Expected %+v, but got %+v", expectedReply, rpl)
|
||||
}
|
||||
invalidJSON := []byte(`{"Field1":"test","Field2":}`)
|
||||
_, err = NewKamDlgReply(invalidJSON)
|
||||
if err == nil {
|
||||
t.Errorf("Expected an error, but got nil")
|
||||
}
|
||||
emptyJSON := []byte(`{}`)
|
||||
expectedEmptyReply := KamDlgReply{}
|
||||
rpl, err = NewKamDlgReply(emptyJSON)
|
||||
if err != nil {
|
||||
t.Errorf("Expected no error, but got %v", err)
|
||||
}
|
||||
|
||||
if rpl != expectedEmptyReply {
|
||||
t.Errorf("Expected %+v, but got %+v", expectedEmptyReply, rpl)
|
||||
}
|
||||
}
|
||||
|
||||
func TestAsKamAuthReplyProcessStats(t *testing.T) {
|
||||
kamEvData := KamEvent{}
|
||||
authArgs := &sessions.V1AuthorizeArgs{
|
||||
ProcessStats: true,
|
||||
}
|
||||
statQueueIDs := []string{"queue1", "queue2", "queue3"}
|
||||
authReply := &sessions.V1AuthorizeReply{
|
||||
StatQueueIDs: &statQueueIDs,
|
||||
}
|
||||
kar, err := kamEvData.AsKamAuthReply(authArgs, authReply, nil)
|
||||
if err != nil {
|
||||
t.Errorf("Expected no error, but got %v", err)
|
||||
}
|
||||
expectedStatQueues := "queue1,queue2,queue3"
|
||||
if kar.StatQueues != expectedStatQueues {
|
||||
t.Errorf("Expected StatQueues to be %s, but got %s", expectedStatQueues, kar.StatQueues)
|
||||
}
|
||||
}
|
||||
|
||||
func TestAsKamAuthReplyProcessThresholds(t *testing.T) {
|
||||
kamEvData := KamEvent{
|
||||
KamTRIndex: "index123",
|
||||
KamTRLabel: "label123",
|
||||
}
|
||||
authArgs := &sessions.V1AuthorizeArgs{
|
||||
ProcessThresholds: true,
|
||||
}
|
||||
thresholdIDs := []string{"threshold1", "threshold2", "threshold3"}
|
||||
authReply := &sessions.V1AuthorizeReply{
|
||||
ThresholdIDs: &thresholdIDs,
|
||||
}
|
||||
kar, err := kamEvData.AsKamAuthReply(authArgs, authReply, nil)
|
||||
if err != nil {
|
||||
t.Errorf("Expected no error, but got %v", err)
|
||||
}
|
||||
expectedThresholds := "threshold1,threshold2,threshold3"
|
||||
if kar.Thresholds != expectedThresholds {
|
||||
t.Errorf("Expected Thresholds to be %s, but got %s", expectedThresholds, kar.Thresholds)
|
||||
}
|
||||
}
|
||||
|
||||
func TestV1AuthorizeArgsParseFlags(t *testing.T) {
|
||||
kev := make(KamEvent)
|
||||
args := kev.V1AuthorizeArgs()
|
||||
if !args.GetMaxUsage {
|
||||
t.Error("Expected GetMaxUsage to be true when CGRFlags is not present")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1189,3 +1189,19 @@ func TestLibDiamBareErr(t *testing.T) {
|
||||
t.Errorf("Expected CommandFlags to be set to ErrorFlag, got %v", result.Header.CommandFlags)
|
||||
}
|
||||
}
|
||||
|
||||
func TestHeaderLenDiam(t *testing.T) {
|
||||
a := &diam.AVP{
|
||||
Flags: avp.Vbit,
|
||||
}
|
||||
result := headerLen(a)
|
||||
if result != 12 {
|
||||
t.Errorf("Expected headerLen to return 12 for Vbit set, got: %d", result)
|
||||
}
|
||||
a.Flags = 0
|
||||
result = headerLen(a)
|
||||
if result != 8 {
|
||||
t.Errorf("Expected headerLen to return 8 for Vbit not set, got: %d", result)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -22,8 +22,11 @@ import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
//"github.com/cgrates/cgrates/utils"
|
||||
)
|
||||
|
||||
@@ -191,3 +194,39 @@ func TestHttpXmlDPFieldAsInterface2(t *testing.T) {
|
||||
t.Errorf("expecting: 0.0225, received: <%s>", data)
|
||||
}
|
||||
}
|
||||
|
||||
func TestStringMethod(t *testing.T) {
|
||||
req, err := http.NewRequest("GET", "http://cgrates.com", nil)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to create request: %v", err)
|
||||
}
|
||||
hU := &httpUrlDP{
|
||||
req: req,
|
||||
}
|
||||
str := hU.String()
|
||||
expectedPrefix := "GET / HTTP/1.1\r\nHost: cgrates.com\r\n"
|
||||
if str[:len(expectedPrefix)] != expectedPrefix {
|
||||
t.Errorf("Expected request string to start with '%s', got '%s'", expectedPrefix, str)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNewHATextPlainEncoder(t *testing.T) {
|
||||
w := httptest.NewRecorder()
|
||||
_, err := newHATextPlainEncoder(w)
|
||||
if err != nil {
|
||||
t.Fatalf("Unexpected error creating encoder: %v", err)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestRemoteHost(t *testing.T) {
|
||||
addr := "192.168.1.1:2012"
|
||||
hU := &httpXmlDP{
|
||||
addr: addr,
|
||||
}
|
||||
remoteAddr := hU.RemoteHost()
|
||||
expectedAddr := utils.NewNetAddr("TCP", addr)
|
||||
if remoteAddr.String() != expectedAddr.String() {
|
||||
t.Errorf("Expected RemoteHost to return %v, but got %v", expectedAddr, remoteAddr)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user