-
Notifications
You must be signed in to change notification settings - Fork 185
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Qiang Xue
committed
Aug 16, 2016
1 parent
5aadec6
commit fc1b2fb
Showing
11 changed files
with
66 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package apis | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
"testing" | ||
|
||
"github.com/go-ozzo/ozzo-routing" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func Test_getPaginatedListFromRequest(t *testing.T) { | ||
tests := []struct { | ||
Tag string | ||
Page, PerPage int | ||
ExpPage, ExpPerPage int | ||
}{ | ||
{"t1", 1, 10, 1, 10}, | ||
{"t2", -1, -1, 1, DEFAULT_PAGE_SIZE}, | ||
{"t2", 0, 0, 1, DEFAULT_PAGE_SIZE}, | ||
{"t3", 2, MAX_PAGE_SIZE + 1, 2, MAX_PAGE_SIZE}, | ||
} | ||
for _, test := range tests { | ||
url := "http://www.example.com/search?foo=1" | ||
if test.Page >= 0 { | ||
url = fmt.Sprintf("%s&page=%v", url, test.Page) | ||
} | ||
if test.PerPage >= 0 { | ||
url = fmt.Sprintf("%s&per_page=%v", url, test.PerPage) | ||
} | ||
req, _ := http.NewRequest("GET", url, nil) | ||
c := routing.NewContext(nil, req) | ||
pl := getPaginatedListFromRequest(c, 100000) | ||
assert.Equal(t, test.ExpPage, pl.Page) | ||
assert.Equal(t, test.ExpPerPage, pl.PerPage) | ||
} | ||
} | ||
|
||
func Test_parseInt(t *testing.T) { | ||
assert.Equal(t, 123, parseInt("123", 1)) | ||
assert.Equal(t, 1, parseInt("a123", 1)) | ||
assert.Equal(t, 1, parseInt("", 1)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
package app | ||
|
||
var Version = "v1.0" | ||
// Version specifies the current version of the application. | ||
// The value of this variable is replaced with the latest git tag | ||
// by "make" while building or running the application. | ||
var Version = "1.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,4 +51,3 @@ func (rs *requestScope) SetRollback(v bool) { | |
func (rs *requestScope) Now() time.Time { | ||
return time.Now() | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ package errors | |
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters