mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Add unit tests on agents
This commit is contained in:
committed by
Dan Christian Bogos
parent
23d6820253
commit
ae7c27da0a
@@ -1260,7 +1260,7 @@ func TestFSEventGetDisconnectCause(t *testing.T) {
|
||||
|
||||
func TestFSEventGetRoute(t *testing.T) {
|
||||
event := FSEvent{
|
||||
"VAR_CGR_ROUTE": "Sales Team",
|
||||
"FSEvent1": "FSEvent12",
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
@@ -1268,7 +1268,7 @@ func TestFSEventGetRoute(t *testing.T) {
|
||||
want string
|
||||
}{
|
||||
{"Static Value Prefix", utils.StaticValuePrefix + "MyRoute", "MyRoute"},
|
||||
{"VAR_CGR_ROUTE Present", "VAR_CGR_ROUTE", "Sales Team"},
|
||||
{"VAR_CGR_ROUTE Present", "FSEvent1", "FSEvent12"},
|
||||
}
|
||||
noMatchCase := struct {
|
||||
name string
|
||||
@@ -1290,7 +1290,51 @@ func TestFSEventGetRoute(t *testing.T) {
|
||||
t.Run(noMatchCase.name, func(t *testing.T) {
|
||||
got := event.GetRoute(noMatchCase.fieldName)
|
||||
if got != noMatchCase.want {
|
||||
t.Errorf("Test: %s - Got: %s, Want: %s", noMatchCase.want, got, noMatchCase.want)
|
||||
t.Errorf("For test: %s - Got: %s, Want: %s", noMatchCase.want, got, noMatchCase.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func TestFSEventGetOptions(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
fsev FSEvent
|
||||
expect map[string]any
|
||||
}{
|
||||
{
|
||||
name: "No_options",
|
||||
fsev: FSEvent{},
|
||||
expect: map[string]any{},
|
||||
},
|
||||
{
|
||||
name: "Valid_options",
|
||||
fsev: FSEvent{
|
||||
VarCGROpts: "key1=value1,key2=value2",
|
||||
},
|
||||
expect: map[string]any{},
|
||||
},
|
||||
{
|
||||
name: "Invalid_options_-_Missing_separator",
|
||||
fsev: FSEvent{
|
||||
VarCGROpts: "key1=value1,key2value2",
|
||||
},
|
||||
expect: map[string]any{},
|
||||
},
|
||||
{
|
||||
name: "Invalid_options_-_Multiple_separators",
|
||||
fsev: FSEvent{
|
||||
VarCGROpts: "key1=value1,value2=value3=value4",
|
||||
},
|
||||
expect: map[string]any{},
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
result := test.fsev.GetOptions()
|
||||
if !reflect.DeepEqual(result, test.expect) {
|
||||
t.Errorf("expected %v, got %v", test.expect, result)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -209,3 +209,36 @@ func TestUpdateDNSMsgFromNM(t *testing.T) {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestLibdnsNewDnsReply(t *testing.T) {
|
||||
req := new(dns.Msg)
|
||||
req.SetQuestion("cgrates.org", dns.TypeA)
|
||||
rply := newDnsReply(req)
|
||||
if len(rply.Question) != len(req.Question) {
|
||||
t.Errorf("Expected %d questions, got %d", len(req.Question), len(rply.Question))
|
||||
}
|
||||
for i, q := range rply.Question {
|
||||
if q.Name != req.Question[i].Name {
|
||||
t.Errorf("Expected question name %s, got %s", req.Question[i].Name, q.Name)
|
||||
}
|
||||
if q.Qtype != req.Question[i].Qtype {
|
||||
t.Errorf("Expected question type %d, got %d", req.Question[i].Qtype, q.Qtype)
|
||||
}
|
||||
if q.Qclass != req.Question[i].Qclass {
|
||||
t.Errorf("Expected question class %d, got %d", req.Question[i].Qclass, q.Qclass)
|
||||
}
|
||||
}
|
||||
rplyOpts := rply.IsEdns0()
|
||||
if rplyOpts == nil {
|
||||
rply.Extra = append(rply.Extra, &dns.OPT{
|
||||
Hdr: dns.RR_Header{Name: ".", Rrtype: dns.TypeOPT},
|
||||
Option: []dns.EDNS0{
|
||||
&dns.EDNS0_NSID{Code: dns.EDNS0NSID, Nsid: "test"},
|
||||
},
|
||||
})
|
||||
} else {
|
||||
if rplyOpts.UDPSize() != 4096 {
|
||||
t.Errorf("Expected EDNS0 UDP size 4096, got %d", rplyOpts.UDPSize())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,6 +22,8 @@ import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"net/http/httputil"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
@@ -190,3 +192,17 @@ func TestHttpXmlDPFieldAsInterface2(t *testing.T) {
|
||||
t.Errorf("expecting: 0.0225, received: <%s>", data)
|
||||
}
|
||||
}
|
||||
|
||||
func TestStringReq(t *testing.T) {
|
||||
req := httptest.NewRequest("GET", "http://102.304.01", nil)
|
||||
req.Header.Add("Content-Type", "application/json")
|
||||
dp := &httpUrlDP{req: req}
|
||||
expected, err := httputil.DumpRequest(req, true)
|
||||
if err != nil {
|
||||
t.Fatalf("Error dumping request: %v", err)
|
||||
}
|
||||
result := dp.String()
|
||||
if result != string(expected) {
|
||||
t.Errorf("String method returned unexpected result:\nExpected: %s\nGot: %s", string(expected), result)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user