Skip to content

Commit c4d77a0

Browse files
committed
Add test cases for negative resource version in TestList
1 parent 58d9b5c commit c4d77a0

File tree

1 file changed

+67
-0
lines changed

1 file changed

+67
-0
lines changed

staging/src/k8s.io/apiserver/pkg/storage/testing/store_tests.go

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1491,6 +1491,73 @@ func RunTestList(ctx context.Context, t *testing.T, store storage.Interface, inc
14911491
expectContinueExact: encodeContinueOrDie(createdPods[1].Namespace+"/"+createdPods[1].Name+"\x00", int64(continueRV+1)),
14921492
expectedRemainingItemCount: utilpointer.Int64(3),
14931493
},
1494+
{
1495+
name: "test List with continue from second pod, negative resource version gives consistent read",
1496+
prefix: "/pods/",
1497+
pred: storage.SelectionPredicate{
1498+
Label: labels.Everything(),
1499+
Field: fields.Everything(),
1500+
Continue: encodeContinueOrDie(createdPods[0].Namespace+"/"+createdPods[0].Name+"\x00", -1),
1501+
},
1502+
expectedOut: []example.Pod{*createdPods[1], *createdPods[2], *createdPods[3], *createdPods[4]},
1503+
expectRV: currentRV,
1504+
},
1505+
{
1506+
name: "test List with continue from second pod and limit, negative resource version gives consistent read",
1507+
prefix: "/pods/",
1508+
pred: storage.SelectionPredicate{
1509+
Label: labels.Everything(),
1510+
Field: fields.Everything(),
1511+
Limit: 2,
1512+
Continue: encodeContinueOrDie(createdPods[0].Namespace+"/"+createdPods[0].Name+"\x00", -1),
1513+
},
1514+
expectedOut: []example.Pod{*createdPods[1], *createdPods[2]},
1515+
expectContinue: true,
1516+
expectContinueExact: encodeContinueOrDie(createdPods[2].Namespace+"/"+createdPods[2].Name+"\x00", int64(continueRV+1)),
1517+
expectRV: currentRV,
1518+
expectedRemainingItemCount: utilpointer.Int64(2),
1519+
},
1520+
{
1521+
name: "test List with continue from third pod, negative resource version gives consistent read",
1522+
prefix: "/pods/",
1523+
pred: storage.SelectionPredicate{
1524+
Label: labels.Everything(),
1525+
Field: fields.Everything(),
1526+
Continue: encodeContinueOrDie(createdPods[2].Namespace+"/"+createdPods[2].Name+"\x00", -1),
1527+
},
1528+
expectedOut: []example.Pod{*createdPods[3], *createdPods[4]},
1529+
expectRV: currentRV,
1530+
},
1531+
{
1532+
name: "test List with continue from empty fails",
1533+
prefix: "/pods/",
1534+
pred: storage.SelectionPredicate{
1535+
Label: labels.Everything(),
1536+
Field: fields.Everything(),
1537+
Continue: encodeContinueOrDie("", int64(continueRV)),
1538+
},
1539+
expectError: true,
1540+
},
1541+
{
1542+
name: "test List with continue from first pod, empty resource version fails",
1543+
prefix: "/pods/",
1544+
pred: storage.SelectionPredicate{
1545+
Label: labels.Everything(),
1546+
Field: fields.Everything(),
1547+
Continue: encodeContinueOrDie(createdPods[0].Namespace+"/"+createdPods[0].Name+"\x00", 0),
1548+
},
1549+
expectError: true,
1550+
},
1551+
{
1552+
name: "test List with negative rv fails",
1553+
prefix: "/pods/",
1554+
rv: "-1",
1555+
pred: storage.SelectionPredicate{
1556+
Label: labels.Everything(),
1557+
Field: fields.Everything(),
1558+
},
1559+
expectError: true,
1560+
},
14941561
}
14951562

14961563
for _, tt := range tests {

0 commit comments

Comments
 (0)