diff --git a/agents/fsevent_test.go b/agents/fsevent_test.go index d5dc53af0..a2a0fb639 100644 --- a/agents/fsevent_test.go +++ b/agents/fsevent_test.go @@ -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) + } + }) + } +} diff --git a/agents/libdns_test.go b/agents/libdns_test.go index 34244b512..9c8ba8e29 100644 --- a/agents/libdns_test.go +++ b/agents/libdns_test.go @@ -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()) + } + } +} diff --git a/agents/libhttpagent_test.go b/agents/libhttpagent_test.go index dad06fd57..834372771 100644 --- a/agents/libhttpagent_test.go +++ b/agents/libhttpagent_test.go @@ -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) + } +}