@@ -1392,69 +1392,139 @@ class RepoResourceSpec extends TufReposerverSpec with RepoResourceSpecUtil
1392
1392
withRandomNamepace { implicit ns =>
1393
1393
createRepo()
1394
1394
// create packages
1395
- Put (apiUri(s " user_repo/targets/cheerios-0.0.5?name=cheerios&version=0.0.5 " ), form).namespaced ~> routes ~> check {
1396
- status shouldBe StatusCodes .OK
1397
- responseAs[SignedPayload [TargetsRole ]]
1398
- }
1399
- Put (apiUri(s " user_repo/targets/cheerios-0.0.6?name=cheerios&version=0.0.6 " ), form).namespaced ~> routes ~> check {
1400
- status shouldBe StatusCodes .OK
1401
- responseAs[SignedPayload [TargetsRole ]]
1395
+ (1 to 100 by 1 ).foreach { idx =>
1396
+ Put (apiUri(s " user_repo/targets/riceKrispies-0.0. " + idx+ " ?name=riceKrispies&version=0.0." + idx), form).namespaced ~> routes ~> check {
1397
+ status shouldBe StatusCodes .OK
1398
+ responseAs[SignedPayload [TargetsRole ]]
1399
+ }
1402
1400
}
1403
- Put (apiUri(s " user_repo/targets/riceKrispies-0.0.1?name=riceKrispies&version=0.0.1 " ), form ).namespaced ~> routes ~> check {
1401
+ Get (apiUri(s " user_repo/target_items " ) ).namespaced ~> routes ~> check {
1404
1402
status shouldBe StatusCodes .OK
1405
- responseAs[SignedPayload [TargetsRole ]]
1403
+ val paged = responseAs[PaginationResult [ClientTargetItem ]]
1404
+ println(paged)
1405
+ paged.total shouldBe 100
1406
+ paged.offset shouldBe 0 // default
1407
+ paged.limit shouldBe 50 // default
1408
+ paged.values.length shouldEqual (paged.limit)
1409
+ val targetCustoms = paged.map { clientTargetItem =>
1410
+ clientTargetItem.custom.asJson.as[TargetCustom ] match {
1411
+ case Right (custom) => custom
1412
+ case Left (err) => println(s " Failed to parse json. Error: ${err.toString}" ); throw err
1413
+ }
1414
+ }
1415
+ val nameVersionTuple = targetCustoms.values.map(custom => (custom.name.value, custom.version.value))
1416
+ (1 to 50 by 1 ).foreach { idx =>
1417
+ nameVersionTuple should contain(" riceKrispies" , " 0.0." + idx)
1418
+ }
1419
+ (51 to 100 by 1 ).foreach { idx =>
1420
+ nameVersionTuple should not contain(" riceKrispies" , " 0.0." + idx)
1421
+ }
1406
1422
}
1407
1423
Get (apiUri(s " user_repo/target_items?offset=1 " )).namespaced ~> routes ~> check {
1408
1424
status shouldBe StatusCodes .OK
1409
1425
val paged = responseAs[PaginationResult [ClientTargetItem ]]
1410
1426
println(paged)
1411
- paged.total shouldBe 3
1427
+ paged.total shouldBe 100
1412
1428
paged.offset shouldBe 1
1413
- paged.limit shouldBe 50
1429
+ paged.limit shouldBe 50 // default
1430
+ paged.values.length shouldEqual(paged.limit)
1414
1431
val targetCustoms = paged.map { clientTargetItem =>
1415
1432
clientTargetItem.custom.asJson.as[TargetCustom ] match {
1416
1433
case Right (custom) => custom
1417
1434
case Left (err) => println(s " Failed to parse json. Error: ${err.toString}" ); throw err
1418
1435
}
1419
1436
}
1420
1437
val nameVersionTuple = targetCustoms.values.map(custom => (custom.name.value, custom.version.value))
1421
- nameVersionTuple should not contain(" cheerios" , " 0.0.5" )
1422
- nameVersionTuple should contain(" cheerios" , " 0.0.6" )
1423
- nameVersionTuple should contain(" riceKrispies" , " 0.0.1" )
1438
+ nameVersionTuple should not contain(" riceKrispies" , " 0.0.1" )
1439
+ (2 to 51 by 1 ).foreach { idx =>
1440
+ nameVersionTuple should contain(" riceKrispies" , " 0.0." + idx)
1441
+ }
1442
+ (52 to 100 by 1 ).foreach { idx =>
1443
+ nameVersionTuple should not contain(" riceKrispies" , " 0.0." + idx)
1444
+ }
1424
1445
}
1425
1446
Get (apiUri(s " user_repo/target_items?limit=2 " )).namespaced ~> routes ~> check {
1426
1447
status shouldBe StatusCodes .OK
1427
1448
val paged = responseAs[PaginationResult [ClientTargetItem ]]
1428
- paged.total shouldBe 3
1449
+ paged.total shouldBe 100
1429
1450
paged.offset shouldBe 0
1430
1451
paged.limit shouldBe 2
1452
+ paged.values.length shouldEqual(paged.limit)
1431
1453
val targetCustoms = paged.map { clientTargetItem =>
1432
1454
clientTargetItem.custom.asJson.as[TargetCustom ] match {
1433
1455
case Right (custom) => custom
1434
1456
case Left (err) => println(s " Failed to parse json. Error: ${err.toString}" ); throw err
1435
1457
}
1436
1458
}
1437
1459
val nameVersionTuple = targetCustoms.values.map(custom => (custom.name.value, custom.version.value))
1438
- nameVersionTuple should contain(" cheerios" , " 0.0.5" )
1439
- nameVersionTuple should contain(" cheerios" , " 0.0.6" )
1440
- nameVersionTuple should not contain(" riceKrispies" , " 0.0.1" )
1460
+ nameVersionTuple should contain(" riceKrispies" , " 0.0.1" )
1461
+ nameVersionTuple should contain(" riceKrispies" , " 0.0.2" )
1462
+ (3 to 100 by 1 ).foreach { idx =>
1463
+ nameVersionTuple should not contain(" riceKrispies" , " 0.0." + idx)
1464
+ }
1441
1465
}
1442
- Get (apiUri(s " user_repo/target_items?offset=1 &limit=1 " )).namespaced ~> routes ~> check {
1466
+ Get (apiUri(s " user_repo/target_items?offset=30 &limit=30 " )).namespaced ~> routes ~> check {
1443
1467
status shouldBe StatusCodes .OK
1444
1468
val paged = responseAs[PaginationResult [ClientTargetItem ]]
1445
- paged.total shouldBe 3
1446
- paged.offset shouldBe 1
1447
- paged.limit shouldBe 1
1469
+ paged.total shouldBe 100
1470
+ paged.offset shouldBe 30
1471
+ paged.limit shouldBe 30
1472
+ paged.values.length shouldEqual(paged.limit)
1448
1473
val targetCustoms = paged.map { clientTargetItem =>
1449
1474
clientTargetItem.custom.asJson.as[TargetCustom ] match {
1450
1475
case Right (custom) => custom
1451
1476
case Left (err) => println(s " Failed to parse json. Error: ${err.toString}" ); throw err
1452
1477
}
1453
1478
}
1454
1479
val nameVersionTuple = targetCustoms.values.map(custom => (custom.name.value, custom.version.value))
1455
- nameVersionTuple should not contain(" cheerios" , " 0.0.5" )
1456
- nameVersionTuple should contain(" cheerios" , " 0.0.6" )
1457
- nameVersionTuple should not contain(" riceKrispies" , " 0.0.1" )
1480
+ (1 to 30 by 1 ).foreach { idx =>
1481
+ nameVersionTuple should not contain(" riceKrispies" , " 0.0." + idx)
1482
+ }
1483
+ (31 to 60 by 1 ).foreach { idx =>
1484
+ nameVersionTuple should contain(" riceKrispies" , " 0.0." + idx)
1485
+ }
1486
+ }
1487
+ Get (apiUri(s " user_repo/target_items?offset=30&limit=60 " )).namespaced ~> routes ~> check {
1488
+ status shouldBe StatusCodes .OK
1489
+ val paged = responseAs[PaginationResult [ClientTargetItem ]]
1490
+ paged.total shouldBe 100
1491
+ paged.offset shouldBe 30
1492
+ paged.limit shouldBe 60
1493
+ paged.values.length shouldEqual (paged.limit)
1494
+ val targetCustoms = paged.map { clientTargetItem =>
1495
+ clientTargetItem.custom.asJson.as[TargetCustom ] match {
1496
+ case Right (custom) => custom
1497
+ case Left (err) => println(s " Failed to parse json. Error: ${err.toString}" ); throw err
1498
+ }
1499
+ }
1500
+ val nameVersionTuple = targetCustoms.values.map(custom => (custom.name.value, custom.version.value))
1501
+ (1 to 30 by 1 ).foreach { idx =>
1502
+ nameVersionTuple should not contain(" riceKrispies" , " 0.0." + idx)
1503
+ }
1504
+ (31 to 90 by 1 ).foreach { idx =>
1505
+ nameVersionTuple should contain(" riceKrispies" , " 0.0." + idx)
1506
+ }
1507
+ }
1508
+ Get (apiUri(s " user_repo/target_items?offset=30&limit=90 " )).namespaced ~> routes ~> check {
1509
+ status shouldBe StatusCodes .OK
1510
+ val paged = responseAs[PaginationResult [ClientTargetItem ]]
1511
+ paged.total shouldBe 100
1512
+ paged.offset shouldBe 30
1513
+ paged.limit shouldBe 90
1514
+ paged.values.length shouldEqual(70 ) // 100 (total) - 30 (offset)
1515
+ val targetCustoms = paged.map { clientTargetItem =>
1516
+ clientTargetItem.custom.asJson.as[TargetCustom ] match {
1517
+ case Right (custom) => custom
1518
+ case Left (err) => println(s " Failed to parse json. Error: ${err.toString}" ); throw err
1519
+ }
1520
+ }
1521
+ val nameVersionTuple = targetCustoms.values.map(custom => (custom.name.value, custom.version.value))
1522
+ (1 to 30 by 1 ).foreach { idx =>
1523
+ nameVersionTuple should not contain(" riceKrispies" , " 0.0." + idx)
1524
+ }
1525
+ (31 to 100 by 1 ).foreach { idx =>
1526
+ nameVersionTuple should contain(" riceKrispies" , " 0.0." + idx)
1527
+ }
1458
1528
}
1459
1529
}
1460
1530
}
0 commit comments