snapshot of https://github.com/go-gitea/gitea.git (main, 2026-09-15; blobs > 131072B omitted)
Some checks failed
cache-seeder / prune (push) Has been skipped
cache-seeder / frontend (push) Failing after 3s
cache-seeder / python (push) Failing after 3s
cache-seeder / gobuild (push) Failing after 4s
cache-seeder / lint (bindata, lint-backend) (push) Failing after 3s
giteabot backport / giteabot (push) Has been skipped
giteabot / giteabot (push) Has been skipped
cache-prune / prune (push) Has been skipped
release-nightly-snapcraft / build-and-publish (ubuntu-24.04) (push) Has been cancelled
release-nightly-snapcraft / build-and-publish (ubuntu-24.04-arm) (push) Has been cancelled
release-nightly / nightly-binary (push) Has been cancelled
release-nightly / nightly-container (push) Has been cancelled
cron-renovate / cron-renovate (push) Has been skipped
Some checks failed
cache-seeder / prune (push) Has been skipped
cache-seeder / frontend (push) Failing after 3s
cache-seeder / python (push) Failing after 3s
cache-seeder / gobuild (push) Failing after 4s
cache-seeder / lint (bindata, lint-backend) (push) Failing after 3s
giteabot backport / giteabot (push) Has been skipped
giteabot / giteabot (push) Has been skipped
cache-prune / prune (push) Has been skipped
release-nightly-snapcraft / build-and-publish (ubuntu-24.04) (push) Has been cancelled
release-nightly-snapcraft / build-and-publish (ubuntu-24.04-arm) (push) Has been cancelled
release-nightly / nightly-binary (push) Has been cancelled
release-nightly / nightly-container (push) Has been cancelled
cron-renovate / cron-renovate (push) Has been skipped
This commit is contained in:
44
routers/api/v1/utils/sort_test.go
Normal file
44
routers/api/v1/utils/sort_test.go
Normal file
@@ -0,0 +1,44 @@
|
||||
// Copyright 2026 The Gitea Authors. All rights reserved.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package utils
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"testing"
|
||||
|
||||
"gitea.dev/models/db"
|
||||
"gitea.dev/services/contexttest"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestResolveSortOrder(t *testing.T) {
|
||||
m := map[string]map[string]db.SearchOrderBy{
|
||||
"asc": {"id": "id ASC"},
|
||||
"desc": {"id": "id DESC"},
|
||||
}
|
||||
defaultOrder := db.SearchOrderBy("default")
|
||||
|
||||
cases := []struct {
|
||||
path string
|
||||
wantOK bool
|
||||
wantOrder db.SearchOrderBy
|
||||
wantStatus int
|
||||
}{
|
||||
{"GET /", true, defaultOrder, 0},
|
||||
{"GET /?sort=id", true, "id ASC", 0},
|
||||
{"GET /?sort=id&order=desc", true, "id DESC", 0},
|
||||
{"GET /?sort=bogus", false, "", http.StatusUnprocessableEntity},
|
||||
{"GET /?sort=id&order=bogus", false, "", http.StatusUnprocessableEntity},
|
||||
}
|
||||
for _, tc := range cases {
|
||||
t.Run(tc.path, func(t *testing.T) {
|
||||
ctx, _ := contexttest.MockAPIContext(t, tc.path)
|
||||
got, ok := ResolveSortOrder(ctx, m, defaultOrder)
|
||||
assert.Equal(t, tc.wantOK, ok)
|
||||
assert.Equal(t, tc.wantOrder, got)
|
||||
assert.Equal(t, tc.wantStatus, ctx.Resp.WrittenStatus())
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user