diff --git a/engine/core_test.go b/engine/core_test.go new file mode 100644 index 000000000..07d9fed73 --- /dev/null +++ b/engine/core_test.go @@ -0,0 +1,53 @@ +/* +Real-time Online/Offline Charging System (OCS) for Telecom & ISP environments +Copyright (C) ITsysCOM GmbH + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see +*/ + +package engine + +import ( + "testing" +) + +func TestNewCoreService(t *testing.T) { + coreService := NewCoreService() + if coreService == nil { + t.Fatal("Expected non-nil *CoreService, got nil") + } + if _, ok := interface{}(coreService).(*CoreService); !ok { + t.Fatalf("Expected type *CoreService, got %T", coreService) + } +} + +func TestListenAndServe(t *testing.T) { + coreService := &CoreService{} + exitChan := make(chan bool, 1) + go func() { + err := coreService.ListenAndServe(exitChan) + if err != nil { + t.Errorf("ListenAndServe returned an error: %v", err) + } + }() + exitChan <- true +} + +func TestShutdown(t *testing.T) { + coreService := &CoreService{} + err := coreService.Shutdown() + if err != nil { + t.Errorf("Shutdown returned an error: %v", err) + } +} diff --git a/engine/libcdre_test.go b/engine/libcdre_test.go new file mode 100644 index 000000000..75fee5069 --- /dev/null +++ b/engine/libcdre_test.go @@ -0,0 +1,46 @@ +/* +Real-time Online/Offline Charging System (OCS) for Telecom & ISP environments +Copyright (C) ITsysCOM GmbH + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see +*/ + +package engine + +import ( + "testing" +) + +func TestSetModule(t *testing.T) { + expEv := &ExportEvents{} + testModule := "newModuleValue" + expEv.SetModule(testModule) + if expEv.module != testModule { + t.Errorf("Expected module %s, got %s", testModule, expEv.module) + } +} + +func TestAddEvent(t *testing.T) { + expEv := &ExportEvents{ + Events: []any{}, + } + event := "testEvent" + expEv.AddEvent(event) + if len(expEv.Events) != 1 { + t.Errorf("Expected 1 event, got %d", len(expEv.Events)) + } + if expEv.Events[0] != event { + t.Errorf("Expected event %v, got %v", event, expEv.Events[0]) + } +} diff --git a/engine/poster_test.go b/engine/poster_test.go index d8fc7b8c4..0074fd47a 100644 --- a/engine/poster_test.go +++ b/engine/poster_test.go @@ -66,3 +66,52 @@ func TestKafkaParseURL(t *testing.T) { t.Errorf("Expected: %s ,received: %s", utils.ToJSON(exp), utils.ToJSON(kfk)) } } + +func TestParseURL(t *testing.T) { + tests := []struct { + input string + expectedURL string + expectedQID string + expectError bool + }{ + { + input: "http://cgrates.com/path?queue_id=myQueue", + expectedURL: "http://cgrates.com/path", + expectedQID: "myQueue", + expectError: false, + }, + { + input: "http://cgrates.com/path", + expectedURL: "http://cgrates.com/path", + expectedQID: defaultQueueID, + expectError: false, + }, + { + input: ":/invalid-url", + expectedURL: "", + expectedQID: "", + expectError: true, + }, + } + + for _, test := range tests { + t.Run(test.input, func(t *testing.T) { + url, qid, err := parseURL(test.input) + if test.expectError { + if err == nil { + t.Fatalf("Expected error, got nil") + } + } else { + if err != nil { + t.Fatalf("Expected no error, got %v", err) + } + if url != test.expectedURL { + t.Fatalf("Expected URL to be %v, got %v", test.expectedURL, url) + } + if qid != test.expectedQID { + t.Fatalf("Expected qID to be %v, got %v", test.expectedQID, qid) + } + } + }) + } +} diff --git a/engine/responder_test.go b/engine/responder_test.go index d7dab513b..87f775286 100644 --- a/engine/responder_test.go +++ b/engine/responder_test.go @@ -1282,3 +1282,31 @@ func TestResponderGetMaxSessionTimeOnAccounts(t *testing.T) { } // } + +func TestResponderPing(t *testing.T) { + var r Responder + var reply string + err := r.Ping(nil, &reply) + if err != nil { + t.Fatalf("Expected no error, got %v", err) + } + if reply != utils.Pong { + t.Fatalf("Expected reply to be %s, got %s", utils.Pong, reply) + } +} + +func TestResponderSetMaxComputedUsage(t *testing.T) { + r := &Responder{ + MaxComputedUsage: make(map[string]time.Duration), + } + newMaxComputedUsage := map[string]time.Duration{ + "user1": 5 * time.Hour, + "user2": 3 * time.Hour, + } + r.SetMaxComputedUsage(newMaxComputedUsage) + r.maxComputedUsageMutex.RLock() + defer r.maxComputedUsageMutex.RUnlock() + if !reflect.DeepEqual(r.MaxComputedUsage, newMaxComputedUsage) { + t.Fatalf("Expected MaxComputedUsage to be %v, got %v", newMaxComputedUsage, r.MaxComputedUsage) + } +}