Skip to content

Commit 034285d

Browse files
committed
Test continuations and exact revision LISTs
1 parent fa03b93 commit 034285d

File tree

1 file changed

+304
-0
lines changed

1 file changed

+304
-0
lines changed

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

Lines changed: 304 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1189,6 +1189,310 @@ func RunTestList(ctx context.Context, t *testing.T, store storage.Interface, com
11891189
expectRVFunc: resourceVersionNotOlderThan(list.ResourceVersion),
11901190
expectedOut: []example.Pod{},
11911191
},
1192+
// match=Exact
1193+
{
1194+
name: "test List with resource version set before first write, match=Exact",
1195+
prefix: "/pods/",
1196+
pred: storage.Everything,
1197+
expectedOut: []example.Pod{},
1198+
rv: initialRV,
1199+
rvMatch: metav1.ResourceVersionMatchExact,
1200+
expectRV: initialRV,
1201+
},
1202+
{
1203+
name: "test List with resource version of first write, match=Exact",
1204+
prefix: "/pods/",
1205+
pred: storage.Everything,
1206+
expectedOut: []example.Pod{*createdPods[0]},
1207+
rv: createdPods[0].ResourceVersion,
1208+
rvMatch: metav1.ResourceVersionMatchExact,
1209+
expectRV: createdPods[0].ResourceVersion,
1210+
},
1211+
{
1212+
name: "test List with resource version of second write, match=Exact",
1213+
prefix: "/pods/",
1214+
pred: storage.Everything,
1215+
expectedOut: []example.Pod{*createdPods[0], *createdPods[1]},
1216+
rv: createdPods[1].ResourceVersion,
1217+
rvMatch: metav1.ResourceVersionMatchExact,
1218+
expectRV: createdPods[1].ResourceVersion,
1219+
},
1220+
{
1221+
name: "test List with resource version of third write, match=Exact",
1222+
prefix: "/pods/",
1223+
pred: storage.Everything,
1224+
expectedOut: []example.Pod{*createdPods[0], *createdPods[1], *createdPods[2]},
1225+
rv: createdPods[2].ResourceVersion,
1226+
rvMatch: metav1.ResourceVersionMatchExact,
1227+
expectRV: createdPods[2].ResourceVersion,
1228+
},
1229+
{
1230+
name: "test List with resource version of fourth write, match=Exact",
1231+
prefix: "/pods/",
1232+
pred: storage.Everything,
1233+
expectedOut: []example.Pod{*createdPods[0], *createdPods[1], *createdPods[2], *createdPods[3]},
1234+
rv: createdPods[3].ResourceVersion,
1235+
rvMatch: metav1.ResourceVersionMatchExact,
1236+
expectRV: createdPods[3].ResourceVersion,
1237+
},
1238+
{
1239+
name: "test List with resource version of fifth write, match=Exact",
1240+
prefix: "/pods/",
1241+
pred: storage.Everything,
1242+
expectedOut: []example.Pod{*createdPods[0], *createdPods[1], *createdPods[2], *createdPods[3], *createdPods[4]},
1243+
rv: createdPods[4].ResourceVersion,
1244+
rvMatch: metav1.ResourceVersionMatchExact,
1245+
expectRV: createdPods[4].ResourceVersion,
1246+
},
1247+
{
1248+
name: "test List with resource version of six write, match=Exact",
1249+
prefix: "/pods/",
1250+
pred: storage.Everything,
1251+
expectedOut: []example.Pod{*createdPods[0], *createdPods[1], *createdPods[2], *createdPods[3], *createdPods[4], *createdPods[5]},
1252+
rv: createdPods[5].ResourceVersion,
1253+
rvMatch: metav1.ResourceVersionMatchExact,
1254+
expectRV: createdPods[5].ResourceVersion,
1255+
},
1256+
{
1257+
name: "test List with resource version of seventh write, match=Exact",
1258+
prefix: "/pods/",
1259+
pred: storage.Everything,
1260+
expectedOut: []example.Pod{*updatedPod, *createdPods[1], *createdPods[2], *createdPods[3], *createdPods[4], *createdPods[5]},
1261+
rv: updatedPod.ResourceVersion,
1262+
rvMatch: metav1.ResourceVersionMatchExact,
1263+
expectRV: updatedPod.ResourceVersion,
1264+
},
1265+
{
1266+
name: "test List with resource version of eight write, match=Exact",
1267+
prefix: "/pods/",
1268+
pred: storage.Everything,
1269+
expectedOut: []example.Pod{*updatedPod, *createdPods[1], *createdPods[2], *createdPods[3], *createdPods[4]},
1270+
rv: fmt.Sprint(continueRV),
1271+
rvMatch: metav1.ResourceVersionMatchExact,
1272+
expectRV: fmt.Sprint(continueRV),
1273+
},
1274+
{
1275+
name: "test List with resource version after writes, match=Exact",
1276+
prefix: "/pods/",
1277+
pred: storage.Everything,
1278+
expectedOut: []example.Pod{*updatedPod, *createdPods[1], *createdPods[2], *createdPods[3], *createdPods[4]},
1279+
rv: fmt.Sprint(continueRV + 1),
1280+
rvMatch: metav1.ResourceVersionMatchExact,
1281+
expectRV: fmt.Sprint(continueRV + 1),
1282+
},
1283+
{
1284+
name: "test List with future resource version, match=Exact",
1285+
prefix: "/pods/",
1286+
pred: storage.Everything,
1287+
rv: fmt.Sprint(continueRV + 2),
1288+
rvMatch: metav1.ResourceVersionMatchExact,
1289+
expectRVTooLarge: true,
1290+
},
1291+
// limit, match=Exact
1292+
{
1293+
name: "test List with limit, resource version of second write, match=Exact",
1294+
prefix: "/pods/",
1295+
pred: storage.SelectionPredicate{
1296+
Label: labels.Everything(),
1297+
Field: fields.Everything(),
1298+
Limit: 1,
1299+
},
1300+
expectedOut: []example.Pod{*createdPods[0]},
1301+
rv: createdPods[1].ResourceVersion,
1302+
expectContinue: true,
1303+
expectContinueExact: encodeContinueOrDie(createdPods[0].Namespace+"/"+createdPods[0].Name+"\x00", int64(mustAtoi(createdPods[1].ResourceVersion))),
1304+
rvMatch: metav1.ResourceVersionMatchExact,
1305+
expectRV: createdPods[1].ResourceVersion,
1306+
expectedRemainingItemCount: utilpointer.Int64(1),
1307+
},
1308+
{
1309+
name: "test List with limit, resource version of third write, match=Exact",
1310+
prefix: "/pods/",
1311+
pred: storage.SelectionPredicate{
1312+
Label: labels.Everything(),
1313+
Field: fields.Everything(),
1314+
Limit: 2,
1315+
},
1316+
rv: createdPods[2].ResourceVersion,
1317+
rvMatch: metav1.ResourceVersionMatchExact,
1318+
expectedOut: []example.Pod{*createdPods[0], *createdPods[1]},
1319+
expectContinue: true,
1320+
expectContinueExact: encodeContinueOrDie(createdPods[1].Namespace+"/"+createdPods[1].Name+"\x00", int64(mustAtoi(createdPods[2].ResourceVersion))),
1321+
expectRV: createdPods[2].ResourceVersion,
1322+
expectedRemainingItemCount: utilpointer.Int64(1),
1323+
},
1324+
{
1325+
name: "test List with limit, resource version of fourth write, match=Exact",
1326+
prefix: "/pods/",
1327+
pred: storage.SelectionPredicate{
1328+
Label: labels.Everything(),
1329+
Field: fields.Everything(),
1330+
Limit: 4,
1331+
},
1332+
rv: createdPods[3].ResourceVersion,
1333+
rvMatch: metav1.ResourceVersionMatchExact,
1334+
expectedOut: []example.Pod{*createdPods[0], *createdPods[1], *createdPods[2], *createdPods[3]},
1335+
expectRV: createdPods[3].ResourceVersion,
1336+
},
1337+
{
1338+
name: "test List with limit, resource version of fifth write, match=Exact",
1339+
prefix: "/pods/",
1340+
pred: storage.SelectionPredicate{
1341+
Label: labels.Everything(),
1342+
Field: fields.Everything(),
1343+
Limit: 1,
1344+
},
1345+
rv: createdPods[4].ResourceVersion,
1346+
rvMatch: metav1.ResourceVersionMatchExact,
1347+
expectedOut: []example.Pod{*createdPods[0]},
1348+
expectRV: createdPods[4].ResourceVersion,
1349+
expectContinue: true,
1350+
expectContinueExact: encodeContinueOrDie(createdPods[0].Namespace+"/"+createdPods[0].Name+"\x00", int64(mustAtoi(createdPods[4].ResourceVersion))),
1351+
expectedRemainingItemCount: utilpointer.Int64(4),
1352+
},
1353+
{
1354+
name: "test List with limit, resource version of six write, match=Exact",
1355+
prefix: "/pods/",
1356+
pred: storage.SelectionPredicate{
1357+
Label: labels.Everything(),
1358+
Field: fields.Everything(),
1359+
Limit: 2,
1360+
},
1361+
rv: createdPods[5].ResourceVersion,
1362+
rvMatch: metav1.ResourceVersionMatchExact,
1363+
expectedOut: []example.Pod{*createdPods[0], *createdPods[1]},
1364+
expectRV: createdPods[5].ResourceVersion,
1365+
expectContinue: true,
1366+
expectContinueExact: encodeContinueOrDie(createdPods[1].Namespace+"/"+createdPods[1].Name+"\x00", int64(mustAtoi(createdPods[5].ResourceVersion))),
1367+
expectedRemainingItemCount: utilpointer.Int64(4),
1368+
},
1369+
{
1370+
name: "test List with limit, resource version of seventh write, match=Exact",
1371+
prefix: "/pods/",
1372+
pred: storage.SelectionPredicate{
1373+
Label: labels.Everything(),
1374+
Field: fields.Everything(),
1375+
Limit: 4,
1376+
},
1377+
rv: updatedPod.ResourceVersion,
1378+
rvMatch: metav1.ResourceVersionMatchExact,
1379+
expectedOut: []example.Pod{*updatedPod, *createdPods[1], *createdPods[5], *createdPods[2]},
1380+
expectRV: updatedPod.ResourceVersion,
1381+
expectContinue: true,
1382+
expectContinueExact: encodeContinueOrDie(createdPods[2].Namespace+"/"+createdPods[2].Name+"\x00", int64(mustAtoi(updatedPod.ResourceVersion))),
1383+
expectedRemainingItemCount: utilpointer.Int64(2),
1384+
},
1385+
{
1386+
name: "test List with limit, resource version of eight write, match=Exact",
1387+
prefix: "/pods/",
1388+
pred: storage.SelectionPredicate{
1389+
Label: labels.Everything(),
1390+
Field: fields.Everything(),
1391+
Limit: 8,
1392+
},
1393+
expectedOut: []example.Pod{*updatedPod, *createdPods[1], *createdPods[2], *createdPods[3], *createdPods[4]},
1394+
rv: fmt.Sprint(continueRV),
1395+
rvMatch: metav1.ResourceVersionMatchExact,
1396+
expectRV: fmt.Sprint(continueRV),
1397+
},
1398+
{
1399+
name: "test List with limit, resource version after writes, match=Exact",
1400+
prefix: "/pods/",
1401+
pred: storage.SelectionPredicate{
1402+
Label: labels.Everything(),
1403+
Field: fields.Everything(),
1404+
Limit: 1,
1405+
},
1406+
rv: fmt.Sprint(continueRV + 1),
1407+
rvMatch: metav1.ResourceVersionMatchExact,
1408+
expectedOut: []example.Pod{*updatedPod},
1409+
expectRV: fmt.Sprint(continueRV + 1),
1410+
expectContinue: true,
1411+
expectContinueExact: encodeContinueOrDie(updatedPod.Namespace+"/"+updatedPod.Name+"\x00", int64(continueRV+1)),
1412+
expectedRemainingItemCount: utilpointer.Int64(4),
1413+
},
1414+
// Continue
1415+
{
1416+
name: "test List with continue, resource version of second write",
1417+
prefix: "/pods/",
1418+
pred: storage.SelectionPredicate{
1419+
Label: labels.Everything(),
1420+
Field: fields.Everything(),
1421+
Limit: 1,
1422+
Continue: encodeContinueOrDie(createdPods[0].Namespace+"/"+createdPods[0].Name+"\x00", int64(mustAtoi(createdPods[1].ResourceVersion))),
1423+
},
1424+
expectedOut: []example.Pod{*createdPods[1]},
1425+
expectRV: createdPods[1].ResourceVersion,
1426+
},
1427+
{
1428+
name: "test List with continue, resource version of third write",
1429+
prefix: "/pods/",
1430+
pred: storage.SelectionPredicate{
1431+
Label: labels.Everything(),
1432+
Field: fields.Everything(),
1433+
Limit: 2,
1434+
Continue: encodeContinueOrDie(createdPods[1].Namespace+"/"+createdPods[1].Name+"\x00", int64(mustAtoi(createdPods[2].ResourceVersion))),
1435+
},
1436+
expectedOut: []example.Pod{*createdPods[2]},
1437+
expectRV: createdPods[2].ResourceVersion,
1438+
},
1439+
{
1440+
name: "test List with continue, resource version of fifth write",
1441+
prefix: "/pods/",
1442+
pred: storage.SelectionPredicate{
1443+
Label: labels.Everything(),
1444+
Field: fields.Everything(),
1445+
Limit: 1,
1446+
Continue: encodeContinueOrDie(createdPods[0].Namespace+"/"+createdPods[0].Name+"\x00", int64(mustAtoi(createdPods[4].ResourceVersion))),
1447+
},
1448+
expectedOut: []example.Pod{*createdPods[1]},
1449+
expectRV: createdPods[4].ResourceVersion,
1450+
expectContinue: true,
1451+
expectContinueExact: encodeContinueOrDie(createdPods[1].Namespace+"/"+createdPods[1].Name+"\x00", int64(mustAtoi(createdPods[4].ResourceVersion))),
1452+
expectedRemainingItemCount: utilpointer.Int64(3),
1453+
},
1454+
{
1455+
name: "test List with continue, resource version of six write",
1456+
prefix: "/pods/",
1457+
pred: storage.SelectionPredicate{
1458+
Label: labels.Everything(),
1459+
Field: fields.Everything(),
1460+
Limit: 2,
1461+
Continue: encodeContinueOrDie(createdPods[1].Namespace+"/"+createdPods[1].Name+"\x00", int64(mustAtoi(createdPods[5].ResourceVersion))),
1462+
},
1463+
expectedOut: []example.Pod{*createdPods[5], *createdPods[2]},
1464+
expectRV: createdPods[5].ResourceVersion,
1465+
expectContinue: true,
1466+
expectContinueExact: encodeContinueOrDie(createdPods[2].Namespace+"/"+createdPods[2].Name+"\x00", int64(mustAtoi(createdPods[5].ResourceVersion))),
1467+
expectedRemainingItemCount: utilpointer.Int64(2),
1468+
},
1469+
{
1470+
name: "test List with continue, resource version of seventh write",
1471+
prefix: "/pods/",
1472+
pred: storage.SelectionPredicate{
1473+
Label: labels.Everything(),
1474+
Field: fields.Everything(),
1475+
Limit: 4,
1476+
Continue: encodeContinueOrDie(createdPods[2].Namespace+"/"+createdPods[2].Name+"\x00", int64(mustAtoi(updatedPod.ResourceVersion))),
1477+
},
1478+
expectedOut: []example.Pod{*createdPods[3], *createdPods[4]},
1479+
expectRV: updatedPod.ResourceVersion,
1480+
},
1481+
{
1482+
name: "test List with continue, resource version after writes",
1483+
prefix: "/pods/",
1484+
pred: storage.SelectionPredicate{
1485+
Label: labels.Everything(),
1486+
Field: fields.Everything(),
1487+
Limit: 1,
1488+
Continue: encodeContinueOrDie(updatedPod.Namespace+"/"+updatedPod.Name+"\x00", int64(continueRV+1)),
1489+
},
1490+
expectedOut: []example.Pod{*createdPods[1]},
1491+
expectRV: fmt.Sprint(continueRV + 1),
1492+
expectContinue: true,
1493+
expectContinueExact: encodeContinueOrDie(createdPods[1].Namespace+"/"+createdPods[1].Name+"\x00", int64(continueRV+1)),
1494+
expectedRemainingItemCount: utilpointer.Int64(3),
1495+
},
11921496
}
11931497

11941498
for _, tt := range tests {

0 commit comments

Comments
 (0)