diff --git a/config/fwvdp_test.go b/config/fwvdp_test.go index 97d15d1ff..fdc46dfdd 100644 --- a/config/fwvdp_test.go +++ b/config/fwvdp_test.go @@ -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, }, } diff --git a/config/objdp_test.go b/config/objdp_test.go index 8e9aa3085..85bb0af9a 100644 --- a/config/objdp_test.go +++ b/config/objdp_test.go @@ -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{}, diff --git a/utils/dataconverter_test.go b/utils/dataconverter_test.go index 66f15865d..39e269087 100644 --- a/utils/dataconverter_test.go +++ b/utils/dataconverter_test.go @@ -178,7 +178,7 @@ func shouldPanic(t *testing.T, f func(string) DataConverter) { _ = recover() }() - NewDataConverterMustCompile("!£$%&/()=?123") + f("!£$%&/()=?123") t.Error("should have panicked") } diff --git a/utils/orderednavigablemap_test.go b/utils/orderednavigablemap_test.go index eed2ac861..358ee7938 100644 --- a/utils/orderednavigablemap_test.go +++ b/utils/orderednavigablemap_test.go @@ -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() diff --git a/utils/pathitemlist_test.go b/utils/pathitemlist_test.go index fd8c821b0..cab9fe60a 100644 --- a/utils/pathitemlist_test.go +++ b/utils/pathitemlist_test.go @@ -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) + +} diff --git a/utils/rsrfield_test.go b/utils/rsrfield_test.go index 5d7453c36..2959239e4 100644 --- a/utils/rsrfield_test.go +++ b/utils/rsrfield_test.go @@ -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) + } +}