aboutsummaryrefslogtreecommitdiffhomepage
path: root/cmd/mbf/internal/pkgserver/api_test.go
diff options
context:
space:
mode:
authorOphestra <cat@gensokyo.uk>2026-05-17 13:07:12 +0900
committerOphestra <cat@gensokyo.uk>2026-05-17 15:56:53 +0900
commit30eb0d6a613ad268f6805ccbcdcabf158e7f526f (patch)
tree07e55baa52748fd139e183017eeb43f5f64cee59 /cmd/mbf/internal/pkgserver/api_test.go
parentc2ff9c9fa55ea569a5e70ee90d2eb0b2ee2a0540 (diff)
internal/rosa: key metadata by string
For upcoming azalea integration. The API is quite ugly right now to ease migration. Signed-off-by: Ophestra <cat@gensokyo.uk>
Diffstat (limited to 'cmd/mbf/internal/pkgserver/api_test.go')
-rw-r--r--cmd/mbf/internal/pkgserver/api_test.go77
1 files changed, 3 insertions, 74 deletions
diff --git a/cmd/mbf/internal/pkgserver/api_test.go b/cmd/mbf/internal/pkgserver/api_test.go
index 8449c234..4c178fb9 100644
--- a/cmd/mbf/internal/pkgserver/api_test.go
+++ b/cmd/mbf/internal/pkgserver/api_test.go
@@ -3,7 +3,6 @@ package pkgserver
import (
"net/http"
"net/http/httptest"
- "slices"
"strconv"
"testing"
@@ -32,7 +31,7 @@ func TestAPIInfo(t *testing.T) {
checkPayload(t, resp, struct {
Count int `json:"count"`
HakureiVersion string `json:"hakurei_version"`
- }{int(rosa.PresetUnexportedStart), info.Version()})
+ }{rosa.Native().Count(), info.Version()})
}
func TestAPIGet(t *testing.T) {
@@ -96,8 +95,8 @@ func TestAPIGet(t *testing.T) {
t.Run("index", func(t *testing.T) {
t.Parallel()
checkValidate(
- t, "limit=1&sort=0&index", 0, int(rosa.PresetUnexportedStart-1),
- "index must be an integer between 0 and "+strconv.Itoa(int(rosa.PresetUnexportedStart-1)),
+ t, "limit=1&sort=0&index", 0, rosa.Native().Count()-1,
+ "index must be an integer between 0 and "+strconv.Itoa(rosa.Native().Count()-1),
)
})
@@ -108,74 +107,4 @@ func TestAPIGet(t *testing.T) {
"sort must be an integer between 0 and "+strconv.Itoa(int(sortOrderEnd)),
)
})
-
- checkWithSuffix := func(name, suffix string, want []*metadata) {
- t.Run(name, func(t *testing.T) {
- t.Parallel()
-
- w := newRequest(suffix)
- resp := w.Result()
- checkStatus(t, resp, http.StatusOK)
- checkAPIHeader(t, w.Header())
- checkPayloadFunc(t, resp, func(got *struct {
- Values []*metadata `json:"values"`
- }) bool {
- return slices.EqualFunc(got.Values, want, func(a, b *metadata) bool {
- return (a.Version == b.Version ||
- a.Version == rosa.Unversioned ||
- b.Version == rosa.Unversioned) &&
- a.HasReport == b.HasReport &&
- a.Name == b.Name &&
- a.Description == b.Description &&
- a.Website == b.Website
- })
- })
-
- })
- }
-
- checkWithSuffix("declarationAscending", "?limit=2&index=1&sort=0", []*metadata{
- {
- Metadata: rosa.GetMetadata(1),
- Version: rosa.Std.Version(1),
- },
- {
- Metadata: rosa.GetMetadata(2),
- Version: rosa.Std.Version(2),
- },
- })
- checkWithSuffix("declarationAscending offset", "?limit=3&index=5&sort=0", []*metadata{
- {
- Metadata: rosa.GetMetadata(5),
- Version: rosa.Std.Version(5),
- },
- {
- Metadata: rosa.GetMetadata(6),
- Version: rosa.Std.Version(6),
- },
- {
- Metadata: rosa.GetMetadata(7),
- Version: rosa.Std.Version(7),
- },
- })
- checkWithSuffix("declarationDescending", "?limit=3&index=0&sort=1", []*metadata{
- {
- Metadata: rosa.GetMetadata(rosa.PresetUnexportedStart - 1),
- Version: rosa.Std.Version(rosa.PresetUnexportedStart - 1),
- },
- {
- Metadata: rosa.GetMetadata(rosa.PresetUnexportedStart - 2),
- Version: rosa.Std.Version(rosa.PresetUnexportedStart - 2),
- },
- {
- Metadata: rosa.GetMetadata(rosa.PresetUnexportedStart - 3),
- Version: rosa.Std.Version(rosa.PresetUnexportedStart - 3),
- },
- })
- checkWithSuffix("declarationDescending offset", "?limit=1&index=37&sort=1", []*metadata{
- {
- Metadata: rosa.GetMetadata(rosa.PresetUnexportedStart - 38),
- Version: rosa.Std.Version(rosa.PresetUnexportedStart - 38),
- },
- })
}