Add new unit tests on engine

This commit is contained in:
armirveliaj
2024-07-22 09:50:49 -04:00
committed by Dan Christian Bogos
parent 124ac6fbb6
commit 564bb136fe
5 changed files with 197 additions and 0 deletions

View File

@@ -2217,3 +2217,11 @@ func TestAttrSGetAttributeForEventErrs(t *testing.T) {
})
}
}
func TestLibEngineShutdown(t *testing.T) {
service := &AttributeService{}
err := service.Shutdown()
if err != nil {
t.Errorf("Expected no error, but got %v", err)
}
}

View File

@@ -327,3 +327,15 @@ func TestCallCostUpdateRatedUsage(t *testing.T) {
t.Error(rcv)
}
}
func TestCallCostSetRpSubjectPrefixMatching(t *testing.T) {
SetRpSubjectPrefixMatching(true)
if rpSubjectPrefixMatching != true {
t.Errorf("Expected rpSubjectPrefixMatching to be true, but got %v", rpSubjectPrefixMatching)
SetRpSubjectPrefixMatching(false)
if rpSubjectPrefixMatching != false {
t.Errorf("Expected rpSubjectPrefixMatching to be false, but got %v", rpSubjectPrefixMatching)
}
}
}

View File

@@ -1637,3 +1637,55 @@ func TestCDRCloneNil(t *testing.T) {
t.Error(rcv)
}
}
func TestTotalExportedCdrs(t *testing.T) {
cdre := &CDRExporter{
numberOfRecords: 42,
}
result := cdre.TotalExportedCdrs()
if result != 42 {
t.Errorf("TotalExportedCdrs() = %d; want 42", result)
}
}
func TestPositiveExports(t *testing.T) {
cdre := &CDRExporter{
positiveExports: []string{"export1", "export2", "export3"},
}
result := cdre.PositiveExports()
expected := []string{"export1", "export2", "export3"}
if len(result) != len(expected) {
t.Errorf("PositiveExports() has different length; got %d, want %d", len(result), len(expected))
}
for i, v := range expected {
if result[i] != v {
t.Errorf("PositiveExports() = %v; want %v", result, expected)
break
}
}
}
func TestNegativeExports(t *testing.T) {
cdre := &CDRExporter{
negativeExports: map[string]string{
"cgrid1": "error 1",
"cgrid2": "error 2",
"cgrid3": "error 3",
},
}
result := cdre.NegativeExports()
expected := map[string]string{
"cgrid1": "error 1",
"cgrid2": "error 2",
"cgrid3": "error 3",
}
if len(result) != len(expected) {
t.Errorf("NegativeExports() has different length; got %d, want %d", len(result), len(expected))
}
for key, value := range expected {
if resultValue, exists := result[key]; !exists || resultValue != value {
t.Errorf("NegativeExports() = %v; want %v", result, expected)
break
}
}
}

49
engine/libengine_test.go Normal file
View File

@@ -0,0 +1,49 @@
/*
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 TestNewRPCClientSet(t *testing.T) {
tests := []struct {
name string
clientSet *RPCClientSet
}{
{
name: "default case",
clientSet: NewRPCClientSet(),
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if tt.clientSet == nil {
t.Errorf("Expected RPCClientSet to be non-nil")
}
if tt.clientSet.set == nil {
t.Errorf("Expected 'set' map to be initialized, got nil")
}
if len(tt.clientSet.set) != 0 {
t.Errorf("Expected 'set' map to be empty, got %d items", len(tt.clientSet.set))
}
})
}
}

76
engine/libtest_test.go Normal file
View File

@@ -0,0 +1,76 @@
/*
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 (
"reflect"
"testing"
"github.com/cgrates/cgrates/utils"
"github.com/cgrates/ltcache"
)
func TestGetDefaultEmptyCacheStats(t *testing.T) {
expected := map[string]*ltcache.CacheStats{
utils.MetaDefault: {Items: 0, Groups: 0},
utils.CacheAccountActionPlans: {Items: 0, Groups: 0},
utils.CacheActionPlans: {Items: 0, Groups: 0},
utils.CacheActionTriggers: {Items: 0, Groups: 0},
utils.CacheActions: {Items: 0, Groups: 0},
utils.CacheAttributeFilterIndexes: {Items: 0, Groups: 0},
utils.CacheAttributeProfiles: {Items: 0, Groups: 0},
utils.CacheChargerFilterIndexes: {Items: 0, Groups: 0},
utils.CacheChargerProfiles: {Items: 0, Groups: 0},
utils.CacheDispatcherFilterIndexes: {Items: 0, Groups: 0},
utils.CacheReverseFilterIndexes: {Items: 0, Groups: 0},
utils.CacheDispatcherProfiles: {Items: 0, Groups: 0},
utils.CacheDispatcherHosts: {Items: 0, Groups: 0},
utils.CacheDispatcherRoutes: {Items: 0, Groups: 0},
utils.CacheDestinations: {Items: 0, Groups: 0},
utils.CacheEventResources: {Items: 0, Groups: 0},
utils.CacheFilters: {Items: 0, Groups: 0},
utils.CacheRatingPlans: {Items: 0, Groups: 0},
utils.CacheRatingProfiles: {Items: 0, Groups: 0},
utils.CacheResourceFilterIndexes: {Items: 0, Groups: 0},
utils.CacheResourceProfiles: {Items: 0, Groups: 0},
utils.CacheResources: {Items: 0, Groups: 0},
utils.CacheReverseDestinations: {Items: 0, Groups: 0},
utils.CacheRPCResponses: {Items: 0, Groups: 0},
utils.CacheSharedGroups: {Items: 0, Groups: 0},
utils.CacheStatFilterIndexes: {Items: 0, Groups: 0},
utils.CacheStatQueueProfiles: {Items: 0, Groups: 0},
utils.CacheStatQueues: {Items: 0, Groups: 0},
utils.CacheSupplierFilterIndexes: {Items: 0, Groups: 0},
utils.CacheSupplierProfiles: {Items: 0, Groups: 0},
utils.CacheThresholdFilterIndexes: {Items: 0, Groups: 0},
utils.CacheThresholdProfiles: {Items: 0, Groups: 0},
utils.CacheThresholds: {Items: 0, Groups: 0},
utils.CacheTimings: {Items: 0, Groups: 0},
utils.CacheDiameterMessages: {Items: 0, Groups: 0},
utils.CacheClosedSessions: {Items: 0, Groups: 0},
utils.CacheLoadIDs: {Items: 0, Groups: 0},
utils.CacheRPCConnections: {Items: 0, Groups: 0},
utils.CacheCDRIDs: {Items: 0, Groups: 0},
utils.CacheRatingProfilesTmp: {Items: 0, Groups: 0},
}
result := GetDefaultEmptyCacheStats()
if !reflect.DeepEqual(result, expected) {
t.Errorf("expected %v, got %v", expected, result)
}
}