mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Add new unit tests on engine
This commit is contained in:
committed by
Dan Christian Bogos
parent
54fb100268
commit
124ac6fbb6
53
engine/core_test.go
Normal file
53
engine/core_test.go
Normal file
@@ -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 <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
|
||||
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)
|
||||
}
|
||||
}
|
||||
46
engine/libcdre_test.go
Normal file
46
engine/libcdre_test.go
Normal file
@@ -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 <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
|
||||
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])
|
||||
}
|
||||
}
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user