diff --git a/engine/datadbmock_test.go b/engine/datadbmock_test.go
new file mode 100644
index 000000000..7a2e60c72
--- /dev/null
+++ b/engine/datadbmock_test.go
@@ -0,0 +1,214 @@
+/*
+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"
+
+ "github.com/cgrates/cgrates/utils"
+)
+
+func TestSetResourceProfileDrv(t *testing.T) {
+ tests := []struct {
+ name string
+ setFunction func(*ResourceProfile) error
+ expectedErr error
+ }{
+ {
+ name: "No Function Set",
+ setFunction: nil,
+ expectedErr: utils.ErrNotImplemented,
+ },
+ {
+ name: "Function Set",
+ setFunction: func(rp *ResourceProfile) error {
+ return utils.ErrNotImplemented
+ },
+ expectedErr: utils.ErrNotImplemented,
+ },
+ }
+
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ dbM := &DataDBMock{
+ SetResourceProfileDrvF: tt.setFunction,
+ }
+ rp := &ResourceProfile{}
+ err := dbM.SetResourceProfileDrv(rp)
+ if err != tt.expectedErr {
+ t.Errorf("expected error %v, but got %v", tt.expectedErr, err)
+ }
+ })
+ }
+}
+
+func TestRemoveSessionsBackupDrv(t *testing.T) {
+ dbMock := &DataDBMock{}
+ err := dbMock.RemoveSessionsBackupDrv("node1", "tenant1", "cgrid1")
+ if err != utils.ErrNotImplemented {
+ t.Errorf("Expected error %v, got %v", utils.ErrNotImplemented, err)
+ }
+}
+
+func TestGetSessionsBackupDrv(t *testing.T) {
+ dbM := &DataDBMock{}
+ sessions, err := dbM.GetSessionsBackupDrv("nodeID", "tenant")
+ if sessions != nil {
+ t.Errorf("expected nil, but got %v", sessions)
+ }
+ if err != utils.ErrNotImplemented {
+ t.Errorf("expected error %v, but got %v", utils.ErrNotImplemented, err)
+ }
+}
+
+func TestSetBackupSessionsDrv(t *testing.T) {
+ dbM := &DataDBMock{}
+ nodeID := "nodeID"
+ tnt := "tenant"
+ storedSessions := []*StoredSession{}
+ err := dbM.SetBackupSessionsDrv(nodeID, tnt, storedSessions)
+ if err != utils.ErrNotImplemented {
+ t.Errorf("expected error %v, but got %v", utils.ErrNotImplemented, err)
+ }
+}
+
+func TestRemoveRatingProfileDrv(t *testing.T) {
+ dbM := &DataDBMock{}
+ err := dbM.RemoveRatingProfileDrv("ID")
+ if err != utils.ErrNotImplemented {
+ t.Errorf("expected error %v, but got %v", utils.ErrNotImplemented, err)
+ }
+}
+
+func TestSetVersions(t *testing.T) {
+ dbM := &DataDBMock{}
+ sampleVersions := Versions{}
+ err := dbM.SetVersions(sampleVersions, true)
+ if err != utils.ErrNotImplemented {
+ t.Errorf("expected error %v, but got %v", utils.ErrNotImplemented, err)
+ }
+}
+
+func TestRemoveDispatcherHostDrv(t *testing.T) {
+ dbM := &DataDBMock{}
+ err := dbM.RemoveDispatcherHostDrv("NodeID", "Host")
+ if err != utils.ErrNotImplemented {
+ t.Errorf("expected error %v, but got %v", utils.ErrNotImplemented, err)
+ }
+}
+
+func TestSetDispatcherHostDrv(t *testing.T) {
+ dbM := &DataDBMock{}
+ host := &DispatcherHost{}
+ err := dbM.SetDispatcherHostDrv(host)
+ if err != utils.ErrNotImplemented {
+ t.Errorf("expected error %v, but got %v", utils.ErrNotImplemented, err)
+ }
+}
+
+func TestGetDispatcherHostDrv(t *testing.T) {
+ dbM := &DataDBMock{}
+ result, err := dbM.GetDispatcherHostDrv("arg1", "arg2")
+ if err != utils.ErrNotImplemented {
+ t.Errorf("expected error %v, but got %v", utils.ErrNotImplemented, err)
+ }
+ if result != nil {
+ t.Errorf("expected result to be nil, but got %v", result)
+ }
+}
+
+func TestRemoveLoadIDsDrv(t *testing.T) {
+ dbM := &DataDBMock{}
+ err := dbM.RemoveLoadIDsDrv()
+ if err != utils.ErrNotImplemented {
+ t.Errorf("expected error %v, but got %v", utils.ErrNotImplemented, err)
+ }
+}
+
+func TestGetItemLoadIDsDrv(t *testing.T) {
+ dbM := &DataDBMock{}
+ itemIDPrefix := "Prefix"
+ loadIDs, err := dbM.GetItemLoadIDsDrv(itemIDPrefix)
+ if err != utils.ErrNotImplemented {
+ t.Errorf("expected error %v, but got %v", utils.ErrNotImplemented, err)
+ }
+ if loadIDs != nil {
+ t.Errorf("expected loadIDs to be nil, but got %v", loadIDs)
+ }
+}
+
+func TestRemoveDispatcherProfileDrv(t *testing.T) {
+ dbM := &DataDBMock{}
+ arg1 := "Arg1"
+ arg2 := "Arg2"
+ err := dbM.RemoveDispatcherProfileDrv(arg1, arg2)
+ if err != utils.ErrNotImplemented {
+ t.Errorf("expected error %v, but got %v", utils.ErrNotImplemented, err)
+ }
+}
+
+func TestSetDispatcherProfileDrv(t *testing.T) {
+ dbM := &DataDBMock{}
+ profile := &DispatcherProfile{}
+ err := dbM.SetDispatcherProfileDrv(profile)
+ if err != utils.ErrNotImplemented {
+ t.Errorf("expected error %v, but got %v", utils.ErrNotImplemented, err)
+ }
+}
+
+func TestGetDispatcherProfileDrv(t *testing.T) {
+ dbM := &DataDBMock{}
+ param1 := "param1"
+ param2 := "param2"
+ profile, err := dbM.GetDispatcherProfileDrv(param1, param2)
+ if err != utils.ErrNotImplemented {
+ t.Errorf("expected error %v, but got %v", utils.ErrNotImplemented, err)
+ }
+ if profile != nil {
+ t.Errorf("expected profile to be nil, but got %v", profile)
+ }
+}
+
+func TestRemoveChargerProfileDrv(t *testing.T) {
+ dbM := &DataDBMock{}
+ param1 := "param1"
+ param2 := "param2"
+ err := dbM.RemoveChargerProfileDrv(param1, param2)
+ if err != utils.ErrNotImplemented {
+ t.Errorf("expected error %v, but got %v", utils.ErrNotImplemented, err)
+ }
+}
+
+func TestSetChargerProfileDrv(t *testing.T) {
+ dbM := &DataDBMock{}
+ var profile *ChargerProfile = nil
+ err := dbM.SetChargerProfileDrv(profile)
+ if err != utils.ErrNotImplemented {
+ t.Errorf("expected error %v, but got %v", utils.ErrNotImplemented, err)
+ }
+}
+
+func TestFlush(t *testing.T) {
+ dbM := &DataDBMock{}
+ param := "testParam"
+ err := dbM.Flush(param)
+ if err != utils.ErrNotImplemented {
+ t.Errorf("expected error %v, but got %v", utils.ErrNotImplemented, err)
+ }
+}
diff --git a/engine/libtest_test.go b/engine/libtest_test.go
new file mode 100644
index 000000000..f5cd52bf1
--- /dev/null
+++ b/engine/libtest_test.go
@@ -0,0 +1,129 @@
+/*
+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"
+
+ "github.com/cgrates/cgrates/utils"
+)
+
+func TestGetDefaultEmptyCacheStats(t *testing.T) {
+ cacheStats := GetDefaultEmptyCacheStats()
+ expectedKeys := []string{
+ utils.MetaDefault,
+ utils.CacheAccountActionPlans,
+ utils.CacheActionPlans,
+ utils.CacheActionTriggers,
+ utils.CacheActions,
+ utils.CacheAttributeFilterIndexes,
+ utils.CacheAttributeProfiles,
+ utils.CacheChargerFilterIndexes,
+ utils.CacheChargerProfiles,
+ utils.CacheDispatcherFilterIndexes,
+ utils.CacheDispatcherProfiles,
+ utils.CacheDispatcherHosts,
+ utils.CacheDispatcherRoutes,
+ utils.CacheDispatcherLoads,
+ utils.CacheDispatchers,
+ utils.CacheDestinations,
+ utils.CacheEventResources,
+ utils.CacheFilters,
+ utils.CacheRatingPlans,
+ utils.CacheRatingProfiles,
+ utils.CacheResourceFilterIndexes,
+ utils.CacheResourceProfiles,
+ utils.CacheResources,
+ utils.CacheReverseDestinations,
+ utils.CacheRPCResponses,
+ utils.CacheSharedGroups,
+ utils.CacheStatFilterIndexes,
+ utils.CacheStatQueueProfiles,
+ utils.CacheStatQueues,
+ utils.CacheRankingProfiles,
+ utils.CacheSTIR,
+ utils.CacheRouteFilterIndexes,
+ utils.CacheRouteProfiles,
+ utils.CacheThresholdFilterIndexes,
+ utils.CacheThresholdProfiles,
+ utils.CacheThresholds,
+ utils.CacheTimings,
+ utils.CacheDiameterMessages,
+ utils.CacheClosedSessions,
+ utils.CacheLoadIDs,
+ utils.CacheRPCConnections,
+ utils.CacheCDRIDs,
+ utils.CacheRatingProfilesTmp,
+ utils.CacheUCH,
+ utils.CacheEventCharges,
+ utils.CacheTrendProfiles,
+ utils.CacheTrends,
+ utils.CacheReverseFilterIndexes,
+ utils.MetaAPIBan,
+ utils.MetaSentryPeer,
+ utils.CacheCapsEvents,
+ utils.CacheReplicationHosts,
+ utils.CacheRadiusPackets,
+ }
+
+ if len(cacheStats) != len(expectedKeys) {
+ t.Errorf("expected %d keys, got %d", len(expectedKeys), len(cacheStats))
+ }
+ for _, key := range expectedKeys {
+ if _, exists := cacheStats[key]; !exists {
+ t.Errorf("expected key %s to be present in the map", key)
+ }
+ }
+}
+
+func TestKillEngine(t *testing.T) {
+ err := KillEngine(10)
+ if err == nil {
+ t.Errorf("expected no error, got %v", err)
+ }
+ err = KillEngine(-1)
+ if err == nil {
+ t.Errorf("expected an error, got nil")
+ }
+}
+
+func TestStopStartEngine(t *testing.T) {
+ cmd, err := StopStartEngine("valid/path/to/config", 10)
+ if err == nil {
+ t.Errorf("expected error, got %v", err)
+ }
+ if cmd != nil {
+ t.Errorf("expected a valid command, got nil")
+ }
+ cmd, err = StopStartEngine("valid/path/to/config", -1)
+ if err == nil {
+ t.Errorf("expected an error from KillEngine, got nil")
+ }
+ if cmd != nil {
+ t.Errorf("expected no command, got %v", cmd)
+ }
+
+ cmd, err = StopStartEngine("", 10)
+ if err == nil {
+ t.Errorf("expected an error from StartEngine, got nil")
+ }
+ if cmd != nil {
+ t.Errorf("expected no command, got %v", cmd)
+ }
+}
diff --git a/engine/trends_test.go b/engine/trends_test.go
index ea8d9ec94..c90f6223c 100644
--- a/engine/trends_test.go
+++ b/engine/trends_test.go
@@ -18,7 +18,11 @@ along with this program. If not, see
package engine
-import "testing"
+import (
+ "testing"
+
+ "github.com/cgrates/cgrates/config"
+)
func TestTrendProfileTenantID(t *testing.T) {
profile := &TrendProfile{
@@ -43,3 +47,19 @@ func TestTrendTenantID(t *testing.T) {
t.Errorf("TenantID() = %v; want %v", result, expected)
}
}
+
+func TestNewTrendService(t *testing.T) {
+ dm := &DataManager{}
+ cgrcfg := &config.CGRConfig{}
+ filterS := &FilterS{}
+ result := NewTrendService(dm, cgrcfg, filterS)
+ if result.dm != dm {
+ t.Errorf("Expected dm to be %v, got %v", dm, result.dm)
+ }
+ if result.cgrcfg != cgrcfg {
+ t.Errorf("Expected cgrcfg to be %v, got %v", cgrcfg, result.cgrcfg)
+ }
+ if result.filterS != filterS {
+ t.Errorf("Expected filterS to be %v, got %v", filterS, result.filterS)
+ }
+}