mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-14 20:59:53 +05:00
Add new unit tests on engine and config
This commit is contained in:
committed by
Dan Christian Bogos
parent
b523024ca2
commit
4b35d74a29
@@ -2586,3 +2586,33 @@ func TestSentryPeerJson(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestRankingsJsonCfgKeyNotPresent(t *testing.T) {
|
||||
jsnCfg := CgrJsonCfg{}
|
||||
rankingsCfg, err := jsnCfg.RankingsJsonCfg()
|
||||
if rankingsCfg != nil {
|
||||
t.Errorf("Expected rankingsCfg to be nil, got %v", rankingsCfg)
|
||||
}
|
||||
if err != nil {
|
||||
t.Errorf("Expected no error, but got %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRankingsJsonCfgValidJson(t *testing.T) {
|
||||
rankingsJson := RankingsJsonCfg{}
|
||||
rawJson, err := json.Marshal(rankingsJson)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to marshal valid JSON: %v", err)
|
||||
}
|
||||
jsnCfg := CgrJsonCfg{
|
||||
RANKINGS_JSON: (*json.RawMessage)(&rawJson),
|
||||
}
|
||||
rankingsCfg, err := jsnCfg.RankingsJsonCfg()
|
||||
if rankingsCfg == nil {
|
||||
t.Errorf("Expected rankingsCfg not to be nil")
|
||||
}
|
||||
if err != nil {
|
||||
t.Errorf("Expected no error, but got %v", err)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -262,3 +262,28 @@ func TestGeneralCfgClone(t *testing.T) {
|
||||
t.Errorf("Expected clone to not modify the cloned")
|
||||
}
|
||||
}
|
||||
|
||||
func TestCachingDelay(t *testing.T) {
|
||||
|
||||
gencfg := &GeneralCfg{
|
||||
CachingDelay: 5 * time.Second,
|
||||
}
|
||||
|
||||
expectedMap := map[string]any{
|
||||
utils.CachingDlayCfg: "5s",
|
||||
}
|
||||
resultMap := gencfg.AsMapInterface()
|
||||
if resultMap[utils.CachingDlayCfg] != expectedMap[utils.CachingDlayCfg] {
|
||||
t.Errorf("Non-zero CachingDelay test failed. Expected %v, but got %v", expectedMap[utils.CachingDlayCfg], resultMap[utils.CachingDlayCfg])
|
||||
}
|
||||
gencfg = &GeneralCfg{
|
||||
CachingDelay: 0,
|
||||
}
|
||||
expectedMap = map[string]any{
|
||||
utils.CachingDlayCfg: "0",
|
||||
}
|
||||
resultMap = gencfg.AsMapInterface()
|
||||
if resultMap[utils.CachingDlayCfg] != expectedMap[utils.CachingDlayCfg] {
|
||||
t.Errorf("Zero CachingDelay test failed. Expected %v, but got %v", expectedMap[utils.CachingDlayCfg], resultMap[utils.CachingDlayCfg])
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
package config
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path"
|
||||
"reflect"
|
||||
"testing"
|
||||
@@ -553,3 +554,33 @@ func TestLoadersCfgGetLockFilePath(t *testing.T) {
|
||||
t.Error(rcv)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetLockFilePath(t *testing.T) {
|
||||
loader := LoaderSCfg{
|
||||
LockFilePath: "/cgrates/cgrates/lockfile.lck",
|
||||
}
|
||||
if loader.GetLockFilePath() != "/cgrates/cgrates/lockfile.lck" {
|
||||
t.Error("Expected /cgrates/cgrates/lockfile.lck")
|
||||
}
|
||||
|
||||
loader = LoaderSCfg{
|
||||
LockFilePath: "relative.lck",
|
||||
TpInDir: "/base/dir",
|
||||
}
|
||||
if loader.GetLockFilePath() != "/base/dir/relative.lck" {
|
||||
t.Error("Expected /base/dir/relative.lck")
|
||||
}
|
||||
|
||||
tmpDir := "/tmp/cgrates_cgrates"
|
||||
_ = os.Mkdir(tmpDir, 0755)
|
||||
defer os.Remove(tmpDir)
|
||||
|
||||
loader = LoaderSCfg{
|
||||
LockFilePath: tmpDir,
|
||||
ID: "loader123",
|
||||
}
|
||||
expected := "/tmp/cgrates_cgrates/loader123.lck"
|
||||
if loader.GetLockFilePath() != expected {
|
||||
t.Errorf("Expected %v, but got %v", expected, loader.GetLockFilePath())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,6 +20,8 @@ package engine
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/cgrates/cgrates/config"
|
||||
)
|
||||
|
||||
func TestTrendProfileTenantID(t *testing.T) {
|
||||
@@ -45,3 +47,44 @@ func TestTrendTenantID(t *testing.T) {
|
||||
t.Errorf("TenantID() = %v; want %v", result, expected)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNewTrendS(t *testing.T) {
|
||||
dm := &DataManager{}
|
||||
connMgr := &ConnManager{}
|
||||
filterS := &FilterS{}
|
||||
cgrcfg := &config.CGRConfig{}
|
||||
|
||||
trendS := NewTrendS(dm, connMgr, filterS, cgrcfg)
|
||||
|
||||
if trendS == nil {
|
||||
t.Errorf("Expected NewTrendS to return a non-nil instance")
|
||||
}
|
||||
if trendS.dm != dm {
|
||||
t.Errorf("Expected DataManager to be set correctly, got %v, want %v", trendS.dm, dm)
|
||||
}
|
||||
if trendS.connMgr != connMgr {
|
||||
t.Errorf("Expected ConnManager to be set correctly, got %v, want %v", trendS.connMgr, connMgr)
|
||||
}
|
||||
if trendS.filterS != filterS {
|
||||
t.Errorf("Expected FilterS to be set correctly, got %v, want %v", trendS.filterS, filterS)
|
||||
}
|
||||
if trendS.cgrcfg != cgrcfg {
|
||||
t.Errorf("Expected CGRConfig to be set correctly, got %v, want %v", trendS.cgrcfg, cgrcfg)
|
||||
}
|
||||
|
||||
if trendS.loopStopped == nil {
|
||||
t.Errorf("Expected loopStopped to be initialized, but got nil")
|
||||
}
|
||||
if trendS.crnTQsMux == nil {
|
||||
t.Errorf("Expected crnTQsMux to be initialized, but got nil")
|
||||
}
|
||||
if trendS.crnTQs == nil {
|
||||
t.Errorf("Expected crnTQs to be initialized, but got nil")
|
||||
} else if len(trendS.crnTQs) != 0 {
|
||||
t.Errorf("Expected crnTQs to be empty, but got length %d", len(trendS.crnTQs))
|
||||
}
|
||||
|
||||
if trendS.crn != nil {
|
||||
t.Errorf("Expected crn to be nil, but got %v", trendS.crn)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user