feat(api): add NumPackages to mirrors/repos/snapshots list responses

add API response wrappers with NumPackages derived from RefList length; keep show endpoint payloads unchanged for backward compatibility; add API tests for list endpoint NumPackages; update swagger response schemas for list endpoints
This commit is contained in:
Pierig Le Saux
2026-04-11 00:09:08 -04:00
committed by André Roth
parent f8620d10b2
commit e908531bef
7 changed files with 196 additions and 13 deletions
+45
View File
@@ -0,0 +1,45 @@
package api
import (
"bytes"
"encoding/json"
"github.com/gin-gonic/gin"
. "gopkg.in/check.v1"
)
type SnapshotsSuite struct {
APISuite
}
var _ = Suite(&SnapshotsSuite{})
func (s *SnapshotsSuite) TestGetSnapshotsIncludesNumPackages(c *C) {
body, err := json.Marshal(gin.H{"Name": "count-snapshot-list"})
c.Assert(err, IsNil)
response, err := s.HTTPRequest("POST", "/api/snapshots", bytes.NewReader(body))
c.Assert(err, IsNil)
c.Assert(response.Code, Equals, 201)
response, err = s.HTTPRequest("GET", "/api/snapshots", nil)
c.Assert(err, IsNil)
c.Assert(response.Code, Equals, 200)
var snapshots []map[string]interface{}
err = json.Unmarshal(response.Body.Bytes(), &snapshots)
c.Assert(err, IsNil)
found := false
for _, snapshot := range snapshots {
if snapshot["Name"] == "count-snapshot-list" {
found = true
value, ok := snapshot["NumPackages"]
c.Assert(ok, Equals, true)
c.Assert(value, Equals, float64(0))
break
}
}
c.Assert(found, Equals, true)
}