@@ -1904,6 +1904,89 @@ var _ = Describe("Client", func() {
1904
1904
close (done )
1905
1905
}, serverSideTimeoutSeconds )
1906
1906
1907
+ It ("should filter results using limit and continue options" , func () {
1908
+
1909
+ makeDeployment := func (suffix string ) * appsv1.Deployment {
1910
+ return & appsv1.Deployment {
1911
+ ObjectMeta : metav1.ObjectMeta {
1912
+ Name : fmt .Sprintf ("deployment-%s" , suffix ),
1913
+ },
1914
+ Spec : appsv1.DeploymentSpec {
1915
+ Selector : & metav1.LabelSelector {
1916
+ MatchLabels : map [string ]string {"foo" : "bar" },
1917
+ },
1918
+ Template : corev1.PodTemplateSpec {
1919
+ ObjectMeta : metav1.ObjectMeta {Labels : map [string ]string {"foo" : "bar" }},
1920
+ Spec : corev1.PodSpec {Containers : []corev1.Container {{Name : "nginx" , Image : "nginx" }}},
1921
+ },
1922
+ },
1923
+ }
1924
+ }
1925
+
1926
+ By ("creating 4 deployments" )
1927
+ dep1 := makeDeployment ("1" )
1928
+ dep1 , err := clientset .AppsV1 ().Deployments (ns ).Create (dep1 )
1929
+ Expect (err ).NotTo (HaveOccurred ())
1930
+ defer deleteDeployment (dep1 , ns )
1931
+
1932
+ dep2 := makeDeployment ("2" )
1933
+ dep2 , err = clientset .AppsV1 ().Deployments (ns ).Create (dep2 )
1934
+ Expect (err ).NotTo (HaveOccurred ())
1935
+ defer deleteDeployment (dep2 , ns )
1936
+
1937
+ dep3 := makeDeployment ("3" )
1938
+ dep3 , err = clientset .AppsV1 ().Deployments (ns ).Create (dep3 )
1939
+ Expect (err ).NotTo (HaveOccurred ())
1940
+ defer deleteDeployment (dep3 , ns )
1941
+
1942
+ dep4 := makeDeployment ("4" )
1943
+ dep4 , err = clientset .AppsV1 ().Deployments (ns ).Create (dep4 )
1944
+ Expect (err ).NotTo (HaveOccurred ())
1945
+ defer deleteDeployment (dep4 , ns )
1946
+
1947
+ cl , err := client .New (cfg , client.Options {})
1948
+ Expect (err ).NotTo (HaveOccurred ())
1949
+
1950
+ By ("listing 1 deployment when limit=1 is used" )
1951
+ deps := & appsv1.DeploymentList {}
1952
+ err = cl .List (context .Background (), deps ,
1953
+ client .Limit (1 ),
1954
+ )
1955
+ Expect (err ).NotTo (HaveOccurred ())
1956
+
1957
+ Expect (deps .Items ).To (HaveLen (1 ))
1958
+ Expect (deps .Continue ).NotTo (BeEmpty ())
1959
+ Expect (deps .Items [0 ].Name ).To (Equal (dep1 .Name ))
1960
+
1961
+ continueToken := deps .Continue
1962
+
1963
+ By ("listing the next deployment when previous continuation token is used and limit=1" )
1964
+ deps = & appsv1.DeploymentList {}
1965
+ err = cl .List (context .Background (), deps ,
1966
+ client .Limit (1 ),
1967
+ client .Continue (continueToken ),
1968
+ )
1969
+ Expect (err ).NotTo (HaveOccurred ())
1970
+
1971
+ Expect (deps .Items ).To (HaveLen (1 ))
1972
+ Expect (deps .Continue ).NotTo (BeEmpty ())
1973
+ Expect (deps .Items [0 ].Name ).To (Equal (dep2 .Name ))
1974
+
1975
+ continueToken = deps .Continue
1976
+
1977
+ By ("listing the 2 remaining deployments when previous continuation token is used without a limit" )
1978
+ deps = & appsv1.DeploymentList {}
1979
+ err = cl .List (context .Background (), deps ,
1980
+ client .Continue (continueToken ),
1981
+ )
1982
+ Expect (err ).NotTo (HaveOccurred ())
1983
+
1984
+ Expect (deps .Items ).To (HaveLen (2 ))
1985
+ Expect (deps .Continue ).To (BeEmpty ())
1986
+ Expect (deps .Items [0 ].Name ).To (Equal (dep3 .Name ))
1987
+ Expect (deps .Items [1 ].Name ).To (Equal (dep4 .Name ))
1988
+ }, serverSideTimeoutSeconds )
1989
+
1907
1990
PIt ("should fail if the object doesn't have meta" , func () {
1908
1991
1909
1992
})
@@ -2309,11 +2392,15 @@ var _ = Describe("Client", func() {
2309
2392
client .MatchingField ("field1" , "bar" ),
2310
2393
client .InNamespace ("test-namespace" ),
2311
2394
client.MatchingLabels {"foo" : "bar" },
2395
+ client .Limit (1 ),
2396
+ client .Continue ("foo" ),
2312
2397
})
2313
2398
mlo := lo .AsListOptions ()
2314
2399
Expect (mlo ).NotTo (BeNil ())
2315
2400
Expect (mlo .LabelSelector ).To (Equal ("foo=bar" ))
2316
2401
Expect (mlo .FieldSelector ).To (Equal ("field1=bar" ))
2402
+ Expect (mlo .Limit ).To (Equal (int64 (1 )))
2403
+ Expect (mlo .Continue ).To (Equal ("foo" ))
2317
2404
})
2318
2405
2319
2406
It ("should be populated by MatchingLabels" , func () {
@@ -2343,6 +2430,58 @@ var _ = Describe("Client", func() {
2343
2430
do = & client.ListOptions {}
2344
2431
Expect (do .AsListOptions ()).To (Equal (& metav1.ListOptions {}))
2345
2432
})
2433
+
2434
+ It ("should be populated by Limit" , func () {
2435
+ lo := & client.ListOptions {}
2436
+ client .Limit (1 ).ApplyToList (lo )
2437
+ Expect (lo ).NotTo (BeNil ())
2438
+ Expect (lo .Limit ).To (Equal (int64 (1 )))
2439
+ })
2440
+
2441
+ It ("should ignore Limit when converted to metav1.ListOptions and watch is true" , func () {
2442
+ lo := & client.ListOptions {
2443
+ Raw : & metav1.ListOptions {Watch : true },
2444
+ }
2445
+ lo .ApplyOptions ([]client.ListOption {
2446
+ client .Limit (1 ),
2447
+ })
2448
+ mlo := lo .AsListOptions ()
2449
+ Expect (mlo ).NotTo (BeNil ())
2450
+ Expect (mlo .Limit ).To (BeZero ())
2451
+ })
2452
+
2453
+ It ("should be populated by Continue" , func () {
2454
+ lo := & client.ListOptions {}
2455
+ client .Continue ("foo" ).ApplyToList (lo )
2456
+ Expect (lo ).NotTo (BeNil ())
2457
+ Expect (lo .Continue ).To (Equal ("foo" ))
2458
+ })
2459
+
2460
+ It ("should ignore Continue token when converted to metav1.ListOptions and watch is true" , func () {
2461
+ lo := & client.ListOptions {
2462
+ Raw : & metav1.ListOptions {Watch : true },
2463
+ }
2464
+ lo .ApplyOptions ([]client.ListOption {
2465
+ client .Continue ("foo" ),
2466
+ })
2467
+ mlo := lo .AsListOptions ()
2468
+ Expect (mlo ).NotTo (BeNil ())
2469
+ Expect (mlo .Continue ).To (BeEmpty ())
2470
+ })
2471
+
2472
+ It ("should ignore both Limit and Continue token when converted to metav1.ListOptions and watch is true" , func () {
2473
+ lo := & client.ListOptions {
2474
+ Raw : & metav1.ListOptions {Watch : true },
2475
+ }
2476
+ lo .ApplyOptions ([]client.ListOption {
2477
+ client .Limit (1 ),
2478
+ client .Continue ("foo" ),
2479
+ })
2480
+ mlo := lo .AsListOptions ()
2481
+ Expect (mlo ).NotTo (BeNil ())
2482
+ Expect (mlo .Limit ).To (BeZero ())
2483
+ Expect (mlo .Continue ).To (BeEmpty ())
2484
+ })
2346
2485
})
2347
2486
2348
2487
Describe ("UpdateOptions" , func () {
0 commit comments