mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Revise and Add new unit tests on engine
This commit is contained in:
committed by
Dan Christian Bogos
parent
e20200c30a
commit
f1d0be170d
@@ -31,6 +31,7 @@ import (
|
||||
|
||||
"github.com/cgrates/cgrates/config"
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
"github.com/google/go-cmp/cmp"
|
||||
)
|
||||
|
||||
func TestActionTriggerClone(t *testing.T) {
|
||||
@@ -459,3 +460,77 @@ func TestStringToJson(t *testing.T) {
|
||||
t.Errorf("String method returned unexpected result, got: %s, want: %s", result, string(expected))
|
||||
}
|
||||
}
|
||||
|
||||
func TestUpdateInitialValue(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
as *AccountSummary
|
||||
old *AccountSummary
|
||||
expected *AccountSummary
|
||||
}{
|
||||
{
|
||||
name: "old is nil",
|
||||
as: &AccountSummary{
|
||||
BalanceSummaries: BalanceSummaries{
|
||||
{UUID: "1", Initial: 10, Value: 20},
|
||||
},
|
||||
},
|
||||
old: nil,
|
||||
expected: &AccountSummary{
|
||||
BalanceSummaries: BalanceSummaries{
|
||||
{UUID: "1", Initial: 10, Value: 20},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "update initial values",
|
||||
as: &AccountSummary{
|
||||
BalanceSummaries: BalanceSummaries{
|
||||
{UUID: "1", Initial: 10, Value: 20},
|
||||
{UUID: "2", Initial: 15, Value: 25},
|
||||
},
|
||||
},
|
||||
old: &AccountSummary{
|
||||
BalanceSummaries: BalanceSummaries{
|
||||
{UUID: "1", Initial: 5, Value: 10},
|
||||
{UUID: "3", Initial: 20, Value: 30},
|
||||
},
|
||||
},
|
||||
expected: &AccountSummary{
|
||||
BalanceSummaries: BalanceSummaries{
|
||||
{UUID: "1", Initial: 5, Value: 20},
|
||||
{UUID: "2", Initial: 15, Value: 25},
|
||||
{UUID: "3", Initial: 0, Value: 0},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "no matching UUIDs",
|
||||
as: &AccountSummary{
|
||||
BalanceSummaries: BalanceSummaries{
|
||||
{UUID: "4", Initial: 10, Value: 20},
|
||||
},
|
||||
},
|
||||
old: &AccountSummary{
|
||||
BalanceSummaries: BalanceSummaries{
|
||||
{UUID: "5", Initial: 5, Value: 10},
|
||||
},
|
||||
},
|
||||
expected: &AccountSummary{
|
||||
BalanceSummaries: BalanceSummaries{
|
||||
{UUID: "4", Initial: 10, Value: 20},
|
||||
{UUID: "5", Initial: 0, Value: 0},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
tt.as.UpdateInitialValue(tt.old)
|
||||
if diff := cmp.Diff(tt.as, tt.expected); diff != "" {
|
||||
t.Errorf("UpdateInitialValue() mismatch (-want +got):\n%s", diff)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2811,13 +2811,10 @@ func TestCallDescriptorgetgetRatingPlansForPrefix(t *testing.T) {
|
||||
}
|
||||
// Default FallbackDepth is 3
|
||||
got, err := cd.getRatingPlansForPrefix("testkey", 4)
|
||||
|
||||
if err != utils.ErrMaxRecursionDepth {
|
||||
t.Errorf("getRatingPlansForPrefix() expected %v, got %v, ", utils.ErrMaxRecursionDepth, err)
|
||||
|
||||
} else if got != 4 {
|
||||
t.Errorf("getRatingPlansForPrefix() expected %v, got %v, ", 4, got)
|
||||
}
|
||||
|
||||
Cache.Clear(nil)
|
||||
}
|
||||
|
||||
40
engine/libindex_test.go
Normal file
40
engine/libindex_test.go
Normal file
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
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 TestLibIndexIsDynamicDPPath(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
path string
|
||||
want bool
|
||||
}{
|
||||
{"Dynamic Path (stats)", "~*stats/", true},
|
||||
{"Static Path", "/static/", false},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
got := IsDynamicDPPath(tt.path)
|
||||
if got != tt.want {
|
||||
t.Errorf("IsDynamicDPPath(%q) = %v, want %v", tt.path, got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user