Added tests package with helpers. Started on middleware tests.
This commit is contained in:
parent
0e2625bf51
commit
58ba9f6dcc
9 changed files with 197 additions and 66 deletions
|
|
@ -4,28 +4,30 @@ import (
|
|||
"fmt"
|
||||
"testing"
|
||||
|
||||
"goweb/tests"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestNewPager(t *testing.T) {
|
||||
ctx, _ := newContext("/")
|
||||
ctx, _ := tests.NewContext(c.Web, "/")
|
||||
pgr := NewPager(ctx, 10)
|
||||
assert.Equal(t, 10, pgr.ItemsPerPage)
|
||||
assert.Equal(t, 1, pgr.Page)
|
||||
assert.Equal(t, 0, pgr.Items)
|
||||
assert.Equal(t, 0, pgr.Pages)
|
||||
|
||||
ctx, _ = newContext(fmt.Sprintf("/abc?%s=%d", PageQueryKey, 2))
|
||||
ctx, _ = tests.NewContext(c.Web, fmt.Sprintf("/abc?%s=%d", PageQueryKey, 2))
|
||||
pgr = NewPager(ctx, 10)
|
||||
assert.Equal(t, 2, pgr.Page)
|
||||
|
||||
ctx, _ = newContext(fmt.Sprintf("/abc?%s=%d", PageQueryKey, -2))
|
||||
ctx, _ = tests.NewContext(c.Web, fmt.Sprintf("/abc?%s=%d", PageQueryKey, -2))
|
||||
pgr = NewPager(ctx, 10)
|
||||
assert.Equal(t, 1, pgr.Page)
|
||||
}
|
||||
|
||||
func TestPager_SetItems(t *testing.T) {
|
||||
ctx, _ := newContext("/")
|
||||
ctx, _ := tests.NewContext(c.Web, "/")
|
||||
pgr := NewPager(ctx, 20)
|
||||
pgr.SetItems(100)
|
||||
assert.Equal(t, 100, pgr.Items)
|
||||
|
|
@ -33,7 +35,7 @@ func TestPager_SetItems(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestPager_IsBeginning(t *testing.T) {
|
||||
ctx, _ := newContext("/")
|
||||
ctx, _ := tests.NewContext(c.Web, "/")
|
||||
pgr := NewPager(ctx, 20)
|
||||
pgr.Pages = 10
|
||||
assert.True(t, pgr.IsBeginning())
|
||||
|
|
@ -44,7 +46,7 @@ func TestPager_IsBeginning(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestPager_IsEnd(t *testing.T) {
|
||||
ctx, _ := newContext("/")
|
||||
ctx, _ := tests.NewContext(c.Web, "/")
|
||||
pgr := NewPager(ctx, 20)
|
||||
pgr.Pages = 10
|
||||
assert.False(t, pgr.IsEnd())
|
||||
|
|
@ -55,7 +57,7 @@ func TestPager_IsEnd(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestPager_GetOffset(t *testing.T) {
|
||||
ctx, _ := newContext("/")
|
||||
ctx, _ := tests.NewContext(c.Web, "/")
|
||||
pgr := NewPager(ctx, 20)
|
||||
assert.Equal(t, 0, pgr.GetOffset())
|
||||
pgr.Page = 2
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue