mirror of
https://github.com/hanzoai/status.git
synced 2026-10-30 18:21:48 +00:00
zip's registration is a verb method on the group, so a route that is not a typed operation says which method it answers with. The security package's own two-method router goes with it: it existed so both the app and a sub-router could satisfy one name, and restating a routing surface is what let the two disagree — the methods it named no longer exist. The app spells itself as a group, which registers at exactly the paths it did. The toolchain and the pin move together, because below zip v1.36.50 the JSON encoder was selected on a build tag: a repo whose go directive rises first writes a wire that is neither the old release's nor the new one's until the pin catches up. metrics_test.go still does not compile, before and after: it compares a metric registry against a gatherer from a different metrics library, so the two Gather signatures disagree. That is its own change. Co-authored-by: Hanzo Dev <[email protected]>
80 lines
2.3 KiB
Go
80 lines
2.3 KiB
Go
package api
|
|
|
|
import (
|
|
"fmt"
|
|
"testing"
|
|
|
|
"github.com/zap-proto/zip"
|
|
"hanzo.ai/status/storage"
|
|
)
|
|
|
|
func TestExtractPageAndPageSizeFromRequest(t *testing.T) {
|
|
type Scenario struct {
|
|
Name string
|
|
Page string
|
|
PageSize string
|
|
ExpectedPage int
|
|
ExpectedPageSize int
|
|
MaximumNumberOfResults int
|
|
}
|
|
scenarios := []Scenario{
|
|
{
|
|
Page: "1",
|
|
PageSize: "20",
|
|
ExpectedPage: 1,
|
|
ExpectedPageSize: 20,
|
|
MaximumNumberOfResults: 20,
|
|
},
|
|
{
|
|
Page: "2",
|
|
PageSize: "10",
|
|
ExpectedPage: 2,
|
|
ExpectedPageSize: 10,
|
|
MaximumNumberOfResults: 40,
|
|
},
|
|
{
|
|
Page: "2",
|
|
PageSize: "10",
|
|
ExpectedPage: 2,
|
|
ExpectedPageSize: 10,
|
|
MaximumNumberOfResults: 200,
|
|
},
|
|
{
|
|
Page: "1",
|
|
PageSize: "999999",
|
|
ExpectedPage: 1,
|
|
ExpectedPageSize: storage.DefaultMaximumNumberOfResults,
|
|
MaximumNumberOfResults: 100,
|
|
},
|
|
{
|
|
Page: "-1",
|
|
PageSize: "-1",
|
|
ExpectedPage: DefaultPage,
|
|
ExpectedPageSize: DefaultPageSize,
|
|
MaximumNumberOfResults: 20,
|
|
},
|
|
{
|
|
Page: "invalid",
|
|
PageSize: "invalid",
|
|
ExpectedPage: DefaultPage,
|
|
ExpectedPageSize: DefaultPageSize,
|
|
MaximumNumberOfResults: 100,
|
|
},
|
|
}
|
|
for _, scenario := range scenarios {
|
|
t.Run("page-"+scenario.Page+"-pageSize-"+scenario.PageSize, func(t *testing.T) {
|
|
//request := httptest.NewRequest("GET", fmt.Sprintf("/v1/status/statuses?page=%s&pageSize=%s", scenario.Page, scenario.PageSize), http.NoBody)
|
|
app := zip.New(zip.Config{})
|
|
c := app.TestCtx("GET", "/v1/status/statuses")
|
|
c.Fiber().Request().SetRequestURI(fmt.Sprintf("/v1/status/statuses?page=%s&pageSize=%s", scenario.Page, scenario.PageSize))
|
|
actualPage, actualPageSize := extractPageAndPageSizeFromRequest(c, scenario.MaximumNumberOfResults)
|
|
if actualPage != scenario.ExpectedPage {
|
|
t.Errorf("expected %d, got %d", scenario.ExpectedPage, actualPage)
|
|
}
|
|
if actualPageSize != scenario.ExpectedPageSize {
|
|
t.Errorf("expected %d, got %d", scenario.ExpectedPageSize, actualPageSize)
|
|
}
|
|
})
|
|
}
|
|
}
|