mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Added coverage tests for cachecfg.go, datadbcfg.go, erscfg.go, fctemplate.go and rsrparser.go
This commit is contained in:
committed by
Dan Christian Bogos
parent
4c2e81c3a6
commit
023cf8f5f2
@@ -115,6 +115,72 @@ func TestCacheParamCfgloadFromJsonCfg(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestCacheCFGAsMapInterface(t *testing.T) {
|
||||
c := CacheParamCfg{
|
||||
Limit: 1,
|
||||
TTL: 1 * time.Second,
|
||||
StaticTTL: true,
|
||||
Precache: false,
|
||||
}
|
||||
|
||||
rcv := c.AsMapInterface()
|
||||
exp := map[string]any{
|
||||
utils.LimitCfg: 1,
|
||||
utils.TTLCfg: "1s",
|
||||
utils.StaticTTLCfg: true,
|
||||
utils.PrecacheCfg: false,
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(rcv, exp) {
|
||||
t.Errorf("recived %v, expected %v", rcv, exp)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
func TestCacheCFGAddTmpCaches(t *testing.T) {
|
||||
c := CacheParamCfg{
|
||||
Limit: 1,
|
||||
TTL: 1 * time.Second,
|
||||
StaticTTL: true,
|
||||
Precache: false,
|
||||
}
|
||||
|
||||
cc := CacheCfg{"test": &c}
|
||||
|
||||
cc.AddTmpCaches()
|
||||
|
||||
rcv := cc[utils.CacheRatingProfilesTmp]
|
||||
exp := &CacheParamCfg{
|
||||
Limit: -1,
|
||||
TTL: time.Minute,
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(rcv, exp) {
|
||||
t.Errorf("recived %v, expected %v", rcv, exp)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCacheCFGAsMappInterface(t *testing.T) {
|
||||
c := CacheParamCfg{
|
||||
Limit: 1,
|
||||
TTL: 1 * time.Second,
|
||||
StaticTTL: true,
|
||||
Precache: false,
|
||||
}
|
||||
|
||||
cc := CacheCfg{"test": &c}
|
||||
|
||||
exp := c.AsMapInterface()
|
||||
rcv := cc.AsMapInterface()["test"]
|
||||
|
||||
if !reflect.DeepEqual(rcv, exp) {
|
||||
t.Errorf("recived %v, expected %v", rcv, exp)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
func TestCacheCfgAsMapInterface(t *testing.T) {
|
||||
var cachecfg *CacheCfg
|
||||
|
||||
@@ -20,6 +20,7 @@ package config
|
||||
import (
|
||||
"reflect"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
)
|
||||
@@ -444,3 +445,23 @@ func TestDataDbCfgAsMapInterface(t *testing.T) {
|
||||
t.Errorf("Expected: %+v ,\n received: %+v", utils.ToJSON(eMap), utils.ToJSON(rcv))
|
||||
}
|
||||
}
|
||||
|
||||
func TestDataDBCFGClone(t *testing.T) {
|
||||
d := &DataDbCfg{
|
||||
DataDbType: "*redis",
|
||||
DataDbHost: "127.0.0.1",
|
||||
DataDbPort: "6379",
|
||||
DataDbName: "10",
|
||||
DataDbUser: "cgrates",
|
||||
DataDbPass: "",
|
||||
DataDbSentinelName: "",
|
||||
QueryTimeout: 10 * time.Second,
|
||||
RplFiltered: false,
|
||||
}
|
||||
|
||||
rcv := d.Clone()
|
||||
|
||||
if !reflect.DeepEqual(rcv, d) {
|
||||
t.Errorf("recived %v, expected %v", rcv, d)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -329,3 +329,22 @@ func TestERsCfgAsMapInterface(t *testing.T) {
|
||||
t.Errorf("\nExpected: %+v\nReceived: %+v", utils.ToJSON(eMap), utils.ToJSON(rcv))
|
||||
}
|
||||
}
|
||||
|
||||
func TestERSCFGClone(t *testing.T) {
|
||||
ev := EventReaderCfg{}
|
||||
ev2 := EventReaderCfg{}
|
||||
|
||||
e := ERsCfg{
|
||||
Enabled: true,
|
||||
SessionSConns: []string{"val1", "val2"},
|
||||
Readers: []*EventReaderCfg{&ev, &ev2},
|
||||
}
|
||||
|
||||
rcv := e.Clone()
|
||||
exp := &e
|
||||
|
||||
if rcv.Enabled != exp.Enabled && !reflect.DeepEqual(rcv.SessionSConns, exp.SessionSConns) && !reflect.DeepEqual(rcv.Readers, exp.Readers) {
|
||||
t.Errorf("recived %v, expected %v", rcv, exp)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -329,3 +329,43 @@ func TestFCTemplateClone(t *testing.T) {
|
||||
t.Errorf("expected: %s ,received: %s", utils.ToJSON(initialSmpl), utils.ToJSON(cloned))
|
||||
}
|
||||
}
|
||||
|
||||
func TestFCTemplateGetPathSlice(t *testing.T) {
|
||||
fc := FCTemplate{
|
||||
Tag: "Elem1",
|
||||
Type: "*composed",
|
||||
Path: "Elem1",
|
||||
Filters: []string{"Filter1", "Filter2"},
|
||||
Value: NewRSRParsersMustCompile("Elem1", true, utils.INFIELD_SEP),
|
||||
pathItems: utils.PathItems{utils.PathItem{Field: "test"}},
|
||||
pathSlice: []string{"val1", "val2"},
|
||||
}
|
||||
|
||||
rcv := fc.GetPathSlice()
|
||||
exp := []string{"val1", "val2"}
|
||||
|
||||
if !reflect.DeepEqual(rcv, exp) {
|
||||
t.Errorf("recived %v, expected %v", rcv, exp)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestFCTemplateGetPathItems(t *testing.T) {
|
||||
fc := FCTemplate{
|
||||
Tag: "Elem1",
|
||||
Type: "*composed",
|
||||
Path: "Elem1",
|
||||
Filters: []string{"Filter1", "Filter2"},
|
||||
Value: NewRSRParsersMustCompile("Elem1", true, utils.INFIELD_SEP),
|
||||
pathItems: utils.PathItems{utils.PathItem{Field: "test"}},
|
||||
pathSlice: []string{"val1", "val2"},
|
||||
}
|
||||
|
||||
rcv := fc.GetPathItems()
|
||||
exp := utils.PathItems{utils.PathItem{Field: "test"}}
|
||||
|
||||
if !reflect.DeepEqual(rcv, exp) {
|
||||
t.Errorf("recived %v, expected %v", rcv, exp)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
package config
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"reflect"
|
||||
"regexp"
|
||||
"testing"
|
||||
@@ -181,3 +182,132 @@ func TestRSRParserCompileConstant(t *testing.T) {
|
||||
t.Errorf("expecting: %+v, received: %+v", ePrsr, prsr)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRSRParserGetRule(t *testing.T) {
|
||||
p := RSRParser{
|
||||
Rules: "Test",
|
||||
}
|
||||
p2 := RSRParser{
|
||||
Rules: "Test2",
|
||||
}
|
||||
|
||||
pp := RSRParsers{&p, &p2}
|
||||
|
||||
rcv := pp.GetRule()
|
||||
exp := "Test.Test2"
|
||||
|
||||
if rcv != exp {
|
||||
t.Errorf("expecting: %+v, received: %+v", exp, rcv)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestRSRParsersCompile(t *testing.T) {
|
||||
|
||||
p := RSRParser{
|
||||
Rules: "Test",
|
||||
}
|
||||
p2 := RSRParser{
|
||||
Rules: "Test2",
|
||||
}
|
||||
|
||||
pp := RSRParsers{&p, &p2}
|
||||
|
||||
rcv := pp.Compile()
|
||||
|
||||
if rcv != nil {
|
||||
t.Errorf("expecting: %+v, received: %+v", nil, rcv)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRSRParserParseDataProviderWithInterface(t *testing.T) {
|
||||
|
||||
p := RSRParser{
|
||||
Rules: "Test",
|
||||
}
|
||||
p2 := RSRParser{
|
||||
Rules: "Test2",
|
||||
}
|
||||
|
||||
pp := RSRParsers{&p, &p2}
|
||||
|
||||
rcv, err := pp.ParseDataProviderWithInterfaces(utils.MapStorage{}, ".")
|
||||
exp := "TestTest2"
|
||||
var expErr error = nil
|
||||
|
||||
if err != expErr {
|
||||
t.Fatalf("recived %v, expected %v", err, expErr)
|
||||
}
|
||||
|
||||
if rcv != exp {
|
||||
t.Errorf("recived %s, expected %s", rcv, exp)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestRSRParserNewParserMustCompile(t *testing.T) {
|
||||
|
||||
rcv := NewRSRParserMustCompile("test", false)
|
||||
exp, _ := NewRSRParser("test", false)
|
||||
|
||||
if !reflect.DeepEqual(rcv, exp) {
|
||||
t.Errorf("recived %v, expected %v", rcv, exp)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRSRParserregexpMatched(t *testing.T) {
|
||||
|
||||
p := RSRParser{
|
||||
Rules: "Test",
|
||||
}
|
||||
|
||||
rcv := p.RegexpMatched()
|
||||
|
||||
if rcv {
|
||||
t.Error("was expecting false")
|
||||
}
|
||||
}
|
||||
|
||||
func TestRSRParserParseDataProviderAsFloat64(t *testing.T) {
|
||||
|
||||
type args struct {
|
||||
dP utils.DataProvider
|
||||
separator string
|
||||
}
|
||||
|
||||
type exp struct {
|
||||
val float64
|
||||
err error
|
||||
}
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
exp exp
|
||||
}{
|
||||
{
|
||||
name: "",
|
||||
args: args{dP: utils.MapStorage{}, separator: "."},
|
||||
exp: exp{val: 0, err: errors.New("empty path in parser")},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
|
||||
p := RSRParser{
|
||||
Rules: "Test",
|
||||
}
|
||||
|
||||
rcv, err := p.ParseDataProviderAsFloat64(tt.args.dP, tt.args.separator)
|
||||
|
||||
if err.Error() != tt.exp.err.Error() {
|
||||
t.Fatalf("recived %s, expected %s", err, tt.exp.err)
|
||||
}
|
||||
|
||||
if rcv != tt.exp.val {
|
||||
t.Errorf("recived %v, expected %v", rcv, tt.exp.val)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -452,54 +452,3 @@ func TestPathItemListMoveAfter(t *testing.T) {
|
||||
t.Error("moved after")
|
||||
}
|
||||
}
|
||||
|
||||
func TestPathItemList(t *testing.T) {
|
||||
|
||||
p1 := PathItemElement{}
|
||||
|
||||
pl := PathItemList{
|
||||
root: p1,
|
||||
len: 3,
|
||||
}
|
||||
|
||||
p1.list = &pl
|
||||
|
||||
p2 := PathItemElement{
|
||||
next: &p1,
|
||||
list: &pl,
|
||||
}
|
||||
|
||||
p1.prev = &p2
|
||||
|
||||
p3 := PathItemElement{
|
||||
next: &p2,
|
||||
list: &pl,
|
||||
}
|
||||
|
||||
p2.prev = &p3
|
||||
|
||||
pr4 := PathItemElement{}
|
||||
|
||||
pl2 := PathItemList{
|
||||
root: pr4,
|
||||
len: 3,
|
||||
}
|
||||
|
||||
pr4.list = &pl2
|
||||
|
||||
p5 := PathItemElement{
|
||||
next: &pr4,
|
||||
list: &pl2,
|
||||
}
|
||||
|
||||
p6 := PathItemElement{
|
||||
next: &p5,
|
||||
list: &pl2,
|
||||
}
|
||||
|
||||
p5.prev = &p6
|
||||
|
||||
//uncompleted
|
||||
//pl.PushBackList(&pl2)
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user