@@ -1430,6 +1430,89 @@ var _ = Describe("Client", func() {
1430
1430
close (done )
1431
1431
}, serverSideTimeoutSeconds )
1432
1432
1433
+ It ("should filter results using limit and continue options" , func () {
1434
+
1435
+ makeDeployment := func (suffix string ) * appsv1.Deployment {
1436
+ return & appsv1.Deployment {
1437
+ ObjectMeta : metav1.ObjectMeta {
1438
+ Name : fmt .Sprintf ("deployment-%s" , suffix ),
1439
+ },
1440
+ Spec : appsv1.DeploymentSpec {
1441
+ Selector : & metav1.LabelSelector {
1442
+ MatchLabels : map [string ]string {"foo" : "bar" },
1443
+ },
1444
+ Template : corev1.PodTemplateSpec {
1445
+ ObjectMeta : metav1.ObjectMeta {Labels : map [string ]string {"foo" : "bar" }},
1446
+ Spec : corev1.PodSpec {Containers : []corev1.Container {{Name : "nginx" , Image : "nginx" }}},
1447
+ },
1448
+ },
1449
+ }
1450
+ }
1451
+
1452
+ By ("creating 4 deployments" )
1453
+ dep1 := makeDeployment ("1" )
1454
+ dep1 , err := clientset .AppsV1 ().Deployments (ns ).Create (dep1 )
1455
+ Expect (err ).NotTo (HaveOccurred ())
1456
+ defer deleteDeployment (dep1 , ns )
1457
+
1458
+ dep2 := makeDeployment ("2" )
1459
+ dep2 , err = clientset .AppsV1 ().Deployments (ns ).Create (dep2 )
1460
+ Expect (err ).NotTo (HaveOccurred ())
1461
+ defer deleteDeployment (dep2 , ns )
1462
+
1463
+ dep3 := makeDeployment ("3" )
1464
+ dep3 , err = clientset .AppsV1 ().Deployments (ns ).Create (dep3 )
1465
+ Expect (err ).NotTo (HaveOccurred ())
1466
+ defer deleteDeployment (dep3 , ns )
1467
+
1468
+ dep4 := makeDeployment ("4" )
1469
+ dep4 , err = clientset .AppsV1 ().Deployments (ns ).Create (dep4 )
1470
+ Expect (err ).NotTo (HaveOccurred ())
1471
+ defer deleteDeployment (dep4 , ns )
1472
+
1473
+ cl , err := client .New (cfg , client.Options {})
1474
+ Expect (err ).NotTo (HaveOccurred ())
1475
+
1476
+ By ("listing 1 deployment when limit=1 is used" )
1477
+ deps := & appsv1.DeploymentList {}
1478
+ err = cl .List (context .Background (), deps ,
1479
+ client .Limit (1 ),
1480
+ )
1481
+ Expect (err ).NotTo (HaveOccurred ())
1482
+
1483
+ Expect (deps .Items ).To (HaveLen (1 ))
1484
+ Expect (deps .Continue ).NotTo (BeEmpty ())
1485
+ Expect (deps .Items [0 ].Name ).To (Equal (dep1 .Name ))
1486
+
1487
+ continueToken := deps .Continue
1488
+
1489
+ By ("listing the next deployment when previous continuation token is used and limit=1" )
1490
+ deps = & appsv1.DeploymentList {}
1491
+ err = cl .List (context .Background (), deps ,
1492
+ client .Limit (1 ),
1493
+ client .Continue (continueToken ),
1494
+ )
1495
+ Expect (err ).NotTo (HaveOccurred ())
1496
+
1497
+ Expect (deps .Items ).To (HaveLen (1 ))
1498
+ Expect (deps .Continue ).NotTo (BeEmpty ())
1499
+ Expect (deps .Items [0 ].Name ).To (Equal (dep2 .Name ))
1500
+
1501
+ continueToken = deps .Continue
1502
+
1503
+ By ("listing the 2 remaining deployments when previous continuation token is used without a limit" )
1504
+ deps = & appsv1.DeploymentList {}
1505
+ err = cl .List (context .Background (), deps ,
1506
+ client .Continue (continueToken ),
1507
+ )
1508
+ Expect (err ).NotTo (HaveOccurred ())
1509
+
1510
+ Expect (deps .Items ).To (HaveLen (2 ))
1511
+ Expect (deps .Continue ).To (BeEmpty ())
1512
+ Expect (deps .Items [0 ].Name ).To (Equal (dep3 .Name ))
1513
+ Expect (deps .Items [1 ].Name ).To (Equal (dep4 .Name ))
1514
+ }, serverSideTimeoutSeconds )
1515
+
1433
1516
PIt ("should fail if the object doesn't have meta" , func () {
1434
1517
1435
1518
})
@@ -1838,6 +1921,50 @@ var _ = Describe("Client", func() {
1838
1921
Expect (lo .Namespace ).To (Equal ("test" ))
1839
1922
})
1840
1923
1924
+ It ("should be able to set Limit" , func () {
1925
+ lo := & client.ListOptions {}
1926
+ lo = lo .SetLimit (1 )
1927
+ Expect (lo .Limit ).To (Equal (int64 (1 )))
1928
+ })
1929
+
1930
+ It ("should be created from Limit" , func () {
1931
+ lo := & client.ListOptions {}
1932
+ client .Limit (1 )(lo )
1933
+ Expect (lo ).NotTo (BeNil ())
1934
+ Expect (lo .Limit ).To (Equal (int64 (1 )))
1935
+ })
1936
+
1937
+ It ("should ignore Limit when converted to metav1.ListOptions and watch is true" , func () {
1938
+ lo := & client.ListOptions {
1939
+ Raw : & metav1.ListOptions {Watch : true },
1940
+ }
1941
+ mlo := lo .SetLimit (1 ).AsListOptions ()
1942
+ Expect (mlo ).NotTo (BeNil ())
1943
+ Expect (mlo .Limit ).To (BeZero ())
1944
+ })
1945
+
1946
+ It ("should be able to set Continue token" , func () {
1947
+ lo := & client.ListOptions {}
1948
+ lo = lo .SetContinue ("foo" )
1949
+ Expect (lo .Continue ).To (Equal ("foo" ))
1950
+ })
1951
+
1952
+ It ("should be created from Continue" , func () {
1953
+ lo := & client.ListOptions {}
1954
+ client .Continue ("foo" )(lo )
1955
+ Expect (lo ).NotTo (BeNil ())
1956
+ Expect (lo .Continue ).To (Equal ("foo" ))
1957
+ })
1958
+
1959
+ It ("should ignore Continue token when converted to metav1.ListOptions and watch is true" , func () {
1960
+ lo := & client.ListOptions {
1961
+ Raw : & metav1.ListOptions {Watch : true },
1962
+ }
1963
+ mlo := lo .SetContinue ("foo" ).AsListOptions ()
1964
+ Expect (mlo ).NotTo (BeNil ())
1965
+ Expect (mlo .Limit ).To (BeZero ())
1966
+ })
1967
+
1841
1968
It ("should allow pre-built ListOptions" , func () {
1842
1969
lo := & client.ListOptions {}
1843
1970
newLo := & client.ListOptions {}
0 commit comments