@@ -1430,6 +1430,130 @@ var _ = Describe("Client", func() {
1430
1430
close (done )
1431
1431
}, serverSideTimeoutSeconds )
1432
1432
1433
+ It ("should filter results using limit and continue options" , func (done Done ) {
1434
+ By ("creating 4 deployments" )
1435
+ dep1 := & appsv1.Deployment {
1436
+ ObjectMeta : metav1.ObjectMeta {
1437
+ Name : "deployment-1" ,
1438
+ },
1439
+ Spec : appsv1.DeploymentSpec {
1440
+ Selector : & metav1.LabelSelector {
1441
+ MatchLabels : map [string ]string {"foo" : "bar" },
1442
+ },
1443
+ Template : corev1.PodTemplateSpec {
1444
+ ObjectMeta : metav1.ObjectMeta {Labels : map [string ]string {"foo" : "bar" }},
1445
+ Spec : corev1.PodSpec {Containers : []corev1.Container {{Name : "nginx" , Image : "nginx" }}},
1446
+ },
1447
+ },
1448
+ }
1449
+ dep1 , err := clientset .AppsV1 ().Deployments (ns ).Create (dep1 )
1450
+ Expect (err ).NotTo (HaveOccurred ())
1451
+ dep2 := & appsv1.Deployment {
1452
+ ObjectMeta : metav1.ObjectMeta {
1453
+ Name : "deployment-2" ,
1454
+ },
1455
+ Spec : appsv1.DeploymentSpec {
1456
+ Selector : & metav1.LabelSelector {
1457
+ MatchLabels : map [string ]string {"foo" : "bar" },
1458
+ },
1459
+ Template : corev1.PodTemplateSpec {
1460
+ ObjectMeta : metav1.ObjectMeta {Labels : map [string ]string {"foo" : "bar" }},
1461
+ Spec : corev1.PodSpec {Containers : []corev1.Container {{Name : "nginx" , Image : "nginx" }}},
1462
+ },
1463
+ },
1464
+ }
1465
+ dep2 , err = clientset .AppsV1 ().Deployments (ns ).Create (dep2 )
1466
+ Expect (err ).NotTo (HaveOccurred ())
1467
+ dep3 := & appsv1.Deployment {
1468
+ ObjectMeta : metav1.ObjectMeta {
1469
+ Name : "deployment-3" ,
1470
+ },
1471
+ Spec : appsv1.DeploymentSpec {
1472
+ Selector : & metav1.LabelSelector {
1473
+ MatchLabels : map [string ]string {"foo" : "bar" },
1474
+ },
1475
+ Template : corev1.PodTemplateSpec {
1476
+ ObjectMeta : metav1.ObjectMeta {Labels : map [string ]string {"foo" : "bar" }},
1477
+ Spec : corev1.PodSpec {Containers : []corev1.Container {{Name : "nginx" , Image : "nginx" }}},
1478
+ },
1479
+ },
1480
+ }
1481
+ dep3 , err = clientset .AppsV1 ().Deployments (ns ).Create (dep3 )
1482
+ Expect (err ).NotTo (HaveOccurred ())
1483
+ dep4 := & appsv1.Deployment {
1484
+ ObjectMeta : metav1.ObjectMeta {
1485
+ Name : "deployment-4" ,
1486
+ },
1487
+ Spec : appsv1.DeploymentSpec {
1488
+ Selector : & metav1.LabelSelector {
1489
+ MatchLabels : map [string ]string {"foo" : "bar" },
1490
+ },
1491
+ Template : corev1.PodTemplateSpec {
1492
+ ObjectMeta : metav1.ObjectMeta {Labels : map [string ]string {"foo" : "bar" }},
1493
+ Spec : corev1.PodSpec {Containers : []corev1.Container {{Name : "nginx" , Image : "nginx" }}},
1494
+ },
1495
+ },
1496
+ }
1497
+ dep4 , err = clientset .AppsV1 ().Deployments (ns ).Create (dep4 )
1498
+ Expect (err ).NotTo (HaveOccurred ())
1499
+
1500
+ cl , err := client .New (cfg , client.Options {})
1501
+ Expect (err ).NotTo (HaveOccurred ())
1502
+
1503
+ By ("listing 1 deployment when limit=1 is used" )
1504
+ deps := & appsv1.DeploymentList {}
1505
+ err = cl .List (context .Background (), deps ,
1506
+ client .Limit (1 ),
1507
+ )
1508
+ Expect (err ).NotTo (HaveOccurred ())
1509
+
1510
+ Expect (deps .Items ).NotTo (BeEmpty ())
1511
+ Expect (1 ).To (Equal (len (deps .Items )))
1512
+ Expect (deps .Continue ).NotTo (BeEmpty ())
1513
+ actual := deps .Items [0 ]
1514
+ Expect (actual .Name ).To (Equal (dep1 .Name ))
1515
+
1516
+ continueToken := deps .Continue
1517
+
1518
+ By ("listing the next deployment when previous continuation token is used and limit=1" )
1519
+ deps = & appsv1.DeploymentList {}
1520
+ err = cl .List (context .Background (), deps ,
1521
+ client .Limit (1 ),
1522
+ client .Continue (continueToken ),
1523
+ )
1524
+ Expect (err ).NotTo (HaveOccurred ())
1525
+
1526
+ Expect (deps .Items ).NotTo (BeEmpty ())
1527
+ Expect (1 ).To (Equal (len (deps .Items )))
1528
+ Expect (deps .Continue ).NotTo (BeEmpty ())
1529
+ actual = deps .Items [0 ]
1530
+ Expect (actual .Name ).To (Equal (dep2 .Name ))
1531
+
1532
+ continueToken = deps .Continue
1533
+
1534
+ By ("listing the 2 remaining deployments when previous continuation token is used without a limit" )
1535
+ deps = & appsv1.DeploymentList {}
1536
+ err = cl .List (context .Background (), deps ,
1537
+ client .Continue (continueToken ),
1538
+ )
1539
+ Expect (err ).NotTo (HaveOccurred ())
1540
+
1541
+ Expect (deps .Items ).NotTo (BeEmpty ())
1542
+ Expect (2 ).To (Equal (len (deps .Items )))
1543
+ Expect (deps .Continue ).To (BeEmpty ())
1544
+ first := deps .Items [0 ]
1545
+ Expect (first .Name ).To (Equal (dep3 .Name ))
1546
+ second := deps .Items [1 ]
1547
+ Expect (second .Name ).To (Equal (dep4 .Name ))
1548
+
1549
+ deleteDeployment (dep1 , ns )
1550
+ deleteDeployment (dep2 , ns )
1551
+ deleteDeployment (dep3 , ns )
1552
+ deleteDeployment (dep4 , ns )
1553
+
1554
+ close (done )
1555
+ }, serverSideTimeoutSeconds )
1556
+
1433
1557
PIt ("should fail if the object doesn't have meta" , func () {
1434
1558
1435
1559
})
@@ -1838,6 +1962,50 @@ var _ = Describe("Client", func() {
1838
1962
Expect (lo .Namespace ).To (Equal ("test" ))
1839
1963
})
1840
1964
1965
+ It ("should be able to set Limit" , func () {
1966
+ lo := & client.ListOptions {}
1967
+ lo = lo .SetLimit (1 )
1968
+ Expect (lo .Limit ).To (Equal (int64 (1 )))
1969
+ })
1970
+
1971
+ It ("should be created from Limit" , func () {
1972
+ lo := & client.ListOptions {}
1973
+ client .Limit (1 )(lo )
1974
+ Expect (lo ).NotTo (BeNil ())
1975
+ Expect (lo .Limit ).To (Equal (int64 (1 )))
1976
+ })
1977
+
1978
+ It ("should ignore Limit when converted to metav1.ListOptions and watch is true" , func () {
1979
+ lo := & client.ListOptions {
1980
+ Raw : & metav1.ListOptions {Watch : true },
1981
+ }
1982
+ mlo := lo .SetLimit (1 ).AsListOptions ()
1983
+ Expect (mlo ).NotTo (BeNil ())
1984
+ Expect (mlo .Limit ).To (BeZero ())
1985
+ })
1986
+
1987
+ It ("should be able to set Continue token" , func () {
1988
+ lo := & client.ListOptions {}
1989
+ lo = lo .SetContinueToken ("foo" )
1990
+ Expect (lo .Continue ).To (Equal ("foo" ))
1991
+ })
1992
+
1993
+ It ("should be created from Continue" , func () {
1994
+ lo := & client.ListOptions {}
1995
+ client .Continue ("foo" )(lo )
1996
+ Expect (lo ).NotTo (BeNil ())
1997
+ Expect (lo .Continue ).To (Equal ("foo" ))
1998
+ })
1999
+
2000
+ It ("should ignore Continue token when converted to metav1.ListOptions and watch is true" , func () {
2001
+ lo := & client.ListOptions {
2002
+ Raw : & metav1.ListOptions {Watch : true },
2003
+ }
2004
+ mlo := lo .SetContinueToken ("foo" ).AsListOptions ()
2005
+ Expect (mlo ).NotTo (BeNil ())
2006
+ Expect (mlo .Limit ).To (BeZero ())
2007
+ })
2008
+
1841
2009
It ("should allow pre-built ListOptions" , func () {
1842
2010
lo := & client.ListOptions {}
1843
2011
newLo := & client.ListOptions {}
0 commit comments