mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-20 06:38:45 +05:00
Added tests for orderednavigablemap.go, pathitemlist.go and rsrfield.go
This commit is contained in:
committed by
Dan Christian Bogos
parent
044106e81a
commit
4c2e81c3a6
@@ -49,41 +49,41 @@ func TestFWVDPFieldAsInterface(t *testing.T) {
|
||||
|
||||
dP := FWVProvider{req: "test", cache: utils.MapStorage{"test": "test"}}
|
||||
|
||||
tests := []struct{
|
||||
name string
|
||||
arg []string
|
||||
exp any
|
||||
err bool
|
||||
tests := []struct {
|
||||
name string
|
||||
arg []string
|
||||
exp any
|
||||
err bool
|
||||
}{
|
||||
{
|
||||
name: "empty field path",
|
||||
arg: []string{},
|
||||
exp: nil,
|
||||
err: false,
|
||||
arg: []string{},
|
||||
exp: nil,
|
||||
err: false,
|
||||
},
|
||||
{
|
||||
name: "empty field path",
|
||||
arg: []string{"a-b"},
|
||||
exp: nil,
|
||||
err: true,
|
||||
arg: []string{"a-b"},
|
||||
exp: nil,
|
||||
err: true,
|
||||
},
|
||||
{
|
||||
name: "empty field path",
|
||||
arg: []string{"5-6"},
|
||||
exp: "",
|
||||
err: true,
|
||||
arg: []string{"5-6"},
|
||||
exp: "",
|
||||
err: true,
|
||||
},
|
||||
{
|
||||
name: "empty field path",
|
||||
arg: []string{"0-a"},
|
||||
exp: nil,
|
||||
err: true,
|
||||
arg: []string{"0-a"},
|
||||
exp: nil,
|
||||
err: true,
|
||||
},
|
||||
{
|
||||
name: "empty field path",
|
||||
arg: []string{"0-6"},
|
||||
exp: "",
|
||||
err: true,
|
||||
arg: []string{"0-6"},
|
||||
exp: "",
|
||||
err: true,
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@@ -168,7 +168,7 @@ func TestObjDPFieldAsInterface(t *testing.T) {
|
||||
slcPrfx: []string{"!", "."},
|
||||
},
|
||||
{
|
||||
name: "has selector",
|
||||
name: "has selector with error",
|
||||
arg: []string{"test[0", "."},
|
||||
exp: exp{data: nil, err: true},
|
||||
slcPrfx: []string{},
|
||||
|
||||
@@ -178,7 +178,7 @@ func shouldPanic(t *testing.T, f func(string) DataConverter) {
|
||||
_ = recover()
|
||||
}()
|
||||
|
||||
NewDataConverterMustCompile("!£$%&/()=?123")
|
||||
f("!£$%&/()=?123")
|
||||
t.Error("should have panicked")
|
||||
}
|
||||
|
||||
|
||||
@@ -747,6 +747,24 @@ func TestOrderedNavigableRemote(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestONMRemoveAll(t *testing.T) {
|
||||
p := PathItemList{
|
||||
root: PathItemElement{},
|
||||
len: 0,
|
||||
}
|
||||
onm := OrderedNavigableMap{
|
||||
nm: &NMData{"test"},
|
||||
orderIdx: &p,
|
||||
orderRef: map[string][]*PathItemElement{},
|
||||
}
|
||||
|
||||
onm.RemoveAll()
|
||||
|
||||
if onm.nm.String() != "{}" {
|
||||
t.Error("didn't remove all", onm.nm.String())
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
func BenchmarkOrderdNavigableMapSet(b *testing.B) {
|
||||
nm := NewOrderedNavigableMap()
|
||||
|
||||
@@ -165,32 +165,31 @@ func TestPathItemListInsertBefore(t *testing.T) {
|
||||
list: nil,
|
||||
}
|
||||
|
||||
|
||||
type args struct {
|
||||
v PathItems
|
||||
v PathItems
|
||||
mark *PathItemElement
|
||||
}
|
||||
|
||||
tests := []struct{
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
exp *PathItemElement
|
||||
exp *PathItemElement
|
||||
}{
|
||||
{
|
||||
name: "different path item lists",
|
||||
args: args{ps, &pTest},
|
||||
exp: nil,
|
||||
exp: nil,
|
||||
},
|
||||
{
|
||||
name: "returns new path item element",
|
||||
args: args{ps, &p3},
|
||||
exp: nil,
|
||||
exp: nil,
|
||||
},
|
||||
}
|
||||
|
||||
for i, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
|
||||
|
||||
rcv := pl.InsertBefore(tt.args.v, tt.args.mark)
|
||||
|
||||
if i < 1 {
|
||||
@@ -237,13 +236,12 @@ func TestPathItemListInsertAfter(t *testing.T) {
|
||||
list: nil,
|
||||
}
|
||||
|
||||
|
||||
type args struct {
|
||||
v PathItems
|
||||
v PathItems
|
||||
mark *PathItemElement
|
||||
}
|
||||
|
||||
tests := []struct{
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
}{
|
||||
@@ -259,7 +257,7 @@ func TestPathItemListInsertAfter(t *testing.T) {
|
||||
|
||||
for i, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
|
||||
|
||||
rcv := pl.InsertAfter(tt.args.v, tt.args.mark)
|
||||
|
||||
if i < 1 {
|
||||
@@ -346,7 +344,7 @@ func TestPathItemListPushFront(t *testing.T) {
|
||||
func TestPathItemListLen(t *testing.T) {
|
||||
|
||||
pl := PathItemList{
|
||||
len: 3,
|
||||
len: 3,
|
||||
}
|
||||
|
||||
rcv := pl.Len()
|
||||
@@ -355,3 +353,153 @@ func TestPathItemListLen(t *testing.T) {
|
||||
t.Errorf("recived %d, expected 3", rcv)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPathItemListMoveToFront(t *testing.T) {
|
||||
|
||||
pr := PathItemElement{
|
||||
Value: PathItems{PathItem{Field: "test"}},
|
||||
}
|
||||
|
||||
pl := PathItemList{
|
||||
root: pr,
|
||||
len: 3,
|
||||
}
|
||||
|
||||
pr.list = &pl
|
||||
|
||||
p2 := PathItemElement{
|
||||
prev: &pr,
|
||||
list: &pl,
|
||||
}
|
||||
|
||||
p3 := PathItemElement{
|
||||
prev: &p2,
|
||||
list: &pl,
|
||||
}
|
||||
|
||||
p2.next = &p3
|
||||
|
||||
p := PathItemElement{
|
||||
Value: PathItems{PathItem{Field: "test"}},
|
||||
}
|
||||
|
||||
pl.MoveToFront(&p)
|
||||
}
|
||||
|
||||
func TestPathItemListMoveBefore(t *testing.T) {
|
||||
pr := PathItemElement{}
|
||||
|
||||
pl := PathItemList{
|
||||
root: pr,
|
||||
len: 3,
|
||||
}
|
||||
|
||||
pr.list = &pl
|
||||
|
||||
p2 := PathItemElement{
|
||||
prev: &pr,
|
||||
list: &pl,
|
||||
}
|
||||
|
||||
p3 := PathItemElement{
|
||||
prev: &p2,
|
||||
list: &pl,
|
||||
}
|
||||
|
||||
p2.next = &p3
|
||||
|
||||
p := PathItemElement{
|
||||
Value: PathItems{PathItem{Field: "test"}},
|
||||
}
|
||||
|
||||
pl.MoveBefore(&p, &p2)
|
||||
|
||||
if len(p2.prev.Value) != 0 {
|
||||
t.Error("moved before")
|
||||
}
|
||||
}
|
||||
|
||||
func TestPathItemListMoveAfter(t *testing.T) {
|
||||
|
||||
pr := PathItemElement{}
|
||||
|
||||
pl := PathItemList{
|
||||
root: pr,
|
||||
len: 3,
|
||||
}
|
||||
|
||||
pr.list = &pl
|
||||
|
||||
p2 := PathItemElement{
|
||||
prev: &pr,
|
||||
list: &pl,
|
||||
}
|
||||
|
||||
p3 := PathItemElement{
|
||||
prev: &p2,
|
||||
list: &pl,
|
||||
}
|
||||
|
||||
p2.next = &p3
|
||||
|
||||
p := PathItemElement{
|
||||
Value: PathItems{PathItem{Field: "test"}},
|
||||
}
|
||||
|
||||
pl.MoveAfter(&p, &p2)
|
||||
|
||||
if len(p2.prev.Value) != 0 {
|
||||
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)
|
||||
|
||||
}
|
||||
|
||||
@@ -739,3 +739,42 @@ func TestRSRFldParse(t *testing.T) {
|
||||
t.Errorf("expecting: %s, received: %s", eOut, out)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRsrFieldNewRSRFieldMustCompile(t *testing.T) {
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
arg string
|
||||
exp *RSRField
|
||||
}{
|
||||
{
|
||||
name: "nil return",
|
||||
arg: "",
|
||||
exp: nil,
|
||||
},
|
||||
{
|
||||
name: "nil return",
|
||||
arg: ")",
|
||||
exp: nil,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
rcv := NewRSRFieldMustCompile(tt.arg)
|
||||
|
||||
if !reflect.DeepEqual(rcv, tt.exp) {
|
||||
t.Errorf("recived %v, expected %v", rcv, tt.exp)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestRSRFieldNewRSRFilterdMustCompile(t *testing.T) {
|
||||
|
||||
rcv := NewRSRFilterMustCompile("test")
|
||||
|
||||
if rcv.filterRule != "test" {
|
||||
t.Error("didn't create RSRFilter", rcv)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user