mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-15 05:09:54 +05:00
Remove unused struct types, functions and tests related to paginator
This commit is contained in:
committed by
Dan Christian Bogos
parent
c9e2809701
commit
583cd71a42
@@ -37,32 +37,6 @@ type Paginator struct {
|
||||
Offset *int // Offset of the first item returned (eg: use Limit*Page in case of PerPage items)
|
||||
}
|
||||
|
||||
func (pgnt *Paginator) PaginateStringSlice(in []string) (out []string) {
|
||||
if len(in) == 0 {
|
||||
return
|
||||
}
|
||||
var limit, offset int
|
||||
if pgnt.Limit != nil && *pgnt.Limit > 0 {
|
||||
limit = *pgnt.Limit
|
||||
}
|
||||
if pgnt.Offset != nil && *pgnt.Offset > 0 {
|
||||
offset = *pgnt.Offset
|
||||
}
|
||||
if limit == 0 && offset == 0 {
|
||||
return in
|
||||
}
|
||||
if offset > len(in) {
|
||||
return
|
||||
}
|
||||
if offset != 0 && limit != 0 {
|
||||
limit = limit + offset
|
||||
}
|
||||
if limit == 0 || limit > len(in) {
|
||||
limit = len(in)
|
||||
}
|
||||
return CloneStringSlice(in[offset:limit])
|
||||
}
|
||||
|
||||
func GetPaginateOpts(opts map[string]interface{}) (limit, offset, maxItems int, err error) {
|
||||
if limitIface, has := opts[PageLimitOpt]; has {
|
||||
if limit, err = IfaceAsTInt(limitIface); err != nil {
|
||||
|
||||
@@ -23,59 +23,6 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestPaginatorPaginateStringSlice(t *testing.T) {
|
||||
//len(in)=0
|
||||
eOut := []string{}
|
||||
pgnt := new(Paginator)
|
||||
rcv := pgnt.PaginateStringSlice(eOut)
|
||||
if len(rcv) != 0 {
|
||||
t.Errorf("Expecting an empty slice, received: %+v", rcv)
|
||||
}
|
||||
//offset > len(in)
|
||||
eOut = []string{"1"}
|
||||
pgnt = &Paginator{Offset: IntPointer(2), Limit: IntPointer(0)}
|
||||
rcv = pgnt.PaginateStringSlice(eOut)
|
||||
|
||||
if len(rcv) != 0 {
|
||||
t.Errorf("Expecting an empty slice, received: %+v", rcv)
|
||||
}
|
||||
//offset != 0 && limit != 0
|
||||
eOut = []string{"3", "4"}
|
||||
pgnt = &Paginator{Offset: IntPointer(2), Limit: IntPointer(0)}
|
||||
rcv = pgnt.PaginateStringSlice([]string{"1", "2", "3", "4"})
|
||||
|
||||
if !reflect.DeepEqual(eOut, rcv) {
|
||||
t.Errorf("Expecting an empty slice, received: %+v", rcv)
|
||||
}
|
||||
|
||||
eOut = []string{"1", "2", "3", "4"}
|
||||
pgnt = new(Paginator)
|
||||
if rcv := pgnt.PaginateStringSlice([]string{"1", "2", "3", "4"}); !reflect.DeepEqual(eOut, rcv) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", eOut, rcv)
|
||||
}
|
||||
eOut = []string{"1", "2", "3"}
|
||||
pgnt.Limit = IntPointer(3)
|
||||
if rcv := pgnt.PaginateStringSlice([]string{"1", "2", "3", "4"}); !reflect.DeepEqual(eOut, rcv) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", eOut, rcv)
|
||||
}
|
||||
eOut = []string{"2", "3", "4"}
|
||||
pgnt.Offset = IntPointer(1)
|
||||
if rcv := pgnt.PaginateStringSlice([]string{"1", "2", "3", "4"}); !reflect.DeepEqual(eOut, rcv) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", eOut, rcv)
|
||||
}
|
||||
eOut = []string{}
|
||||
pgnt.Offset = IntPointer(4)
|
||||
if rcv := pgnt.PaginateStringSlice([]string{"1", "2", "3", "4"}); !reflect.DeepEqual(eOut, rcv) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", eOut, rcv)
|
||||
}
|
||||
eOut = []string{"3"}
|
||||
pgnt.Offset = IntPointer(2)
|
||||
pgnt.Limit = IntPointer(1)
|
||||
if rcv := pgnt.PaginateStringSlice([]string{"1", "2", "3", "4"}); !reflect.DeepEqual(eOut, rcv) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", eOut, rcv)
|
||||
}
|
||||
}
|
||||
|
||||
func TestClonePaginator(t *testing.T) {
|
||||
expectedPaginator := Paginator{
|
||||
Limit: IntPointer(2),
|
||||
|
||||
@@ -699,12 +699,6 @@ type ArgsItemIDs struct {
|
||||
ItemsPrefix string
|
||||
}
|
||||
|
||||
type PaginatorWithTenant struct {
|
||||
Tenant string
|
||||
Paginator
|
||||
APIOpts map[string]interface{}
|
||||
}
|
||||
|
||||
type TenantWithAPIOpts struct {
|
||||
Tenant string
|
||||
APIOpts map[string]interface{}
|
||||
|
||||
Reference in New Issue
Block a user