@@ -2,6 +2,7 @@ package main
22
33import (
44 "encoding/json"
5+ "fmt"
56 "strings"
67 "testing"
78 "time"
@@ -200,9 +201,10 @@ func TestSoftwareEndpoints(t *testing.T) {
200201
201202 expectedCode : 200 ,
202203 expectedContentType : "application/json" ,
204+ setupFunc : addSoftwareForPaginationCapTest ,
203205 validateFunc : func (t * testing.T , response map [string ]interface {}) {
204206 items := assertListResponse (t , response )
205- assert .LessOrEqual (t , len (items ), 100 )
207+ assert .Equal (t , 100 , len (items ))
206208 },
207209 },
208210 {
@@ -1669,3 +1671,47 @@ func TestSoftwareDeleteDBChecks(t *testing.T) {
16691671 assert .Equal (t , 0 , dbCount (t , "software_urls" , "software_id" , softwareID ))
16701672 })
16711673}
1674+
1675+ func addSoftwareForPaginationCapTest (t * testing.T ) {
1676+ t .Helper ()
1677+
1678+ const (
1679+ insertCount = 110
1680+ urlPrefix = "https://cap-test.example.org/repo-"
1681+ )
1682+
1683+ swQuery := fmt .Sprintf (
1684+ "INSERT INTO software (id, software_url_id, publiccode_yml, active, created_at, updated_at) VALUES (%s, %s, %s, %s, %s, %s)" ,
1685+ placeholder (1 ),
1686+ placeholder (2 ),
1687+ placeholder (3 ),
1688+ placeholder (4 ),
1689+ placeholder (5 ),
1690+ placeholder (6 ),
1691+ )
1692+ urlQuery := fmt .Sprintf (
1693+ "INSERT INTO software_urls (id, url, software_id, created_at, updated_at) VALUES (%s, %s, %s, %s, %s)" ,
1694+ placeholder (1 ),
1695+ placeholder (2 ),
1696+ placeholder (3 ),
1697+ placeholder (4 ),
1698+ placeholder (5 ),
1699+ )
1700+
1701+ for i := range insertCount {
1702+ swID := fmt .Sprintf ("11111111-1111-1111-1111-%012d" , i )
1703+ urlID := fmt .Sprintf ("22222222-2222-2222-2222-%012d" , i )
1704+ createdAt := time .Date (2020 , 1 , 1 , 0 , 0 , 0 , 0 , time .UTC ).Add (time .Duration (i ) * time .Second )
1705+
1706+ _ , err := db .Exec (swQuery , swID , urlID , "-" , true , createdAt , createdAt )
1707+ require .NoError (t , err )
1708+
1709+ _ , err = db .Exec (urlQuery , urlID , fmt .Sprintf ("%s%d" , urlPrefix , i ), swID , createdAt , createdAt )
1710+ require .NoError (t , err )
1711+ }
1712+
1713+ t .Cleanup (func () {
1714+ _ , _ = db .Exec ("DELETE FROM software_urls WHERE url LIKE " + placeholder (1 ), urlPrefix + "%" )
1715+ _ , _ = db .Exec ("DELETE FROM software WHERE id LIKE " + placeholder (1 ), "11111111-1111-1111-1111-%" )
1716+ })
1717+ }
0 commit comments