@@ -85,7 +85,7 @@ func TestListClusteredResources(t *testing.T) {
85
85
86
86
// Test ListClusteredResources
87
87
ctx := context .Background ()
88
- list , err := testClient .ListClusteredResources (ctx , gvr , "" )
88
+ list , err := testClient .ListClusteredResources (ctx , gvr , "" , 0 , "" )
89
89
90
90
// Verify there was no error
91
91
assert .NoError (t , err , "ListClusteredResources should not return an error" )
@@ -95,7 +95,7 @@ func TestListClusteredResources(t *testing.T) {
95
95
assert .Equal (t , "test-cluster-role" , list .Items [0 ].GetName (), "Expected name 'test-cluster-role'" )
96
96
97
97
// Test ListClusteredResources with label selector
98
- list , err = testClient .ListClusteredResources (ctx , gvr , "app=test-app" )
98
+ list , err = testClient .ListClusteredResources (ctx , gvr , "app=test-app" , 0 , "" )
99
99
100
100
// Verify there was no error
101
101
assert .NoError (t , err , "ListClusteredResources should not return an error" )
@@ -178,7 +178,7 @@ func TestListNamespacedResources(t *testing.T) {
178
178
179
179
// Test ListNamespacedResources
180
180
ctx := context .Background ()
181
- list , err := testClient .ListNamespacedResources (ctx , gvr , "default" , "" )
181
+ list , err := testClient .ListNamespacedResources (ctx , gvr , "default" , "" , 0 , "" )
182
182
183
183
// Verify there was no error
184
184
assert .NoError (t , err , "ListNamespacedResources should not return an error" )
@@ -188,7 +188,7 @@ func TestListNamespacedResources(t *testing.T) {
188
188
assert .Equal (t , "test-service" , list .Items [0 ].GetName (), "Expected name 'test-service'" )
189
189
190
190
// Test ListNamespacedResources with label selector
191
- list , err = testClient .ListNamespacedResources (ctx , gvr , "default" , "app=test-app" )
191
+ list , err = testClient .ListNamespacedResources (ctx , gvr , "default" , "app=test-app" , 0 , "" )
192
192
193
193
// Verify there was no error
194
194
assert .NoError (t , err , "ListNamespacedResources should not return an error" )
@@ -198,6 +198,123 @@ func TestListNamespacedResources(t *testing.T) {
198
198
assert .Equal (t , "test-service-2" , list .Items [0 ].GetName (), "Expected name 'test-service-2'" )
199
199
}
200
200
201
+ // TestListClusteredResourcesWithPagination tests that pagination parameters are correctly handled
202
+ func TestListClusteredResourcesWithPagination (t * testing.T ) {
203
+ // Since the fake client doesn't properly pass through ListOptions in the reactor,
204
+ // we'll test that our functions correctly build the ListOptions and that the
205
+ // response's continue token is properly preserved
206
+
207
+ scheme := runtime .NewScheme ()
208
+ listKinds := map [schema.GroupVersionResource ]string {
209
+ {Group : "rbac.authorization.k8s.io" , Version : "v1" , Resource : "clusterroles" }: "ClusterRoleList" ,
210
+ }
211
+
212
+ client := dynamicfake .NewSimpleDynamicClientWithCustomListKinds (scheme , listKinds )
213
+ testClient := & Client {
214
+ dynamicClient : client ,
215
+ }
216
+
217
+ gvr := schema.GroupVersionResource {
218
+ Group : "rbac.authorization.k8s.io" ,
219
+ Version : "v1" ,
220
+ Resource : "clusterroles" ,
221
+ }
222
+
223
+ // Add a reactor that returns a list with a continue token
224
+ client .PrependReactor ("list" , "clusterroles" , func (_ ktesting.Action ) (handled bool , ret runtime.Object , err error ) {
225
+ list := & unstructured.UnstructuredList {
226
+ Object : map [string ]interface {}{
227
+ "metadata" : map [string ]interface {}{
228
+ "continue" : "test-continue-token" ,
229
+ },
230
+ },
231
+ Items : []unstructured.Unstructured {
232
+ {
233
+ Object : map [string ]interface {}{
234
+ "apiVersion" : "rbac.authorization.k8s.io/v1" ,
235
+ "kind" : "ClusterRole" ,
236
+ "metadata" : map [string ]interface {}{
237
+ "name" : "test-role" ,
238
+ },
239
+ },
240
+ },
241
+ },
242
+ }
243
+ return true , list , nil
244
+ })
245
+
246
+ // Test that the function accepts pagination parameters and returns results
247
+ ctx := context .Background ()
248
+
249
+ // Test with limit
250
+ list , err := testClient .ListClusteredResources (ctx , gvr , "" , 10 , "" )
251
+ assert .NoError (t , err , "ListClusteredResources with limit should not return an error" )
252
+ assert .NotNil (t , list , "List should not be nil" )
253
+ assert .Equal (t , "test-continue-token" , list .GetContinue (), "Continue token should be preserved in response" )
254
+
255
+ // Test with continue token
256
+ list , err = testClient .ListClusteredResources (ctx , gvr , "" , 0 , "my-continue-token" )
257
+ assert .NoError (t , err , "ListClusteredResources with continue token should not return an error" )
258
+ assert .NotNil (t , list , "List should not be nil" )
259
+ }
260
+
261
+ // TestListNamespacedResourcesWithPagination tests that pagination parameters are correctly handled
262
+ func TestListNamespacedResourcesWithPagination (t * testing.T ) {
263
+ scheme := runtime .NewScheme ()
264
+ listKinds := map [schema.GroupVersionResource ]string {
265
+ {Group : "" , Version : "v1" , Resource : "pods" }: "PodList" ,
266
+ }
267
+
268
+ client := dynamicfake .NewSimpleDynamicClientWithCustomListKinds (scheme , listKinds )
269
+ testClient := & Client {
270
+ dynamicClient : client ,
271
+ }
272
+
273
+ gvr := schema.GroupVersionResource {
274
+ Group : "" ,
275
+ Version : "v1" ,
276
+ Resource : "pods" ,
277
+ }
278
+
279
+ // Add a reactor that returns a list with a continue token
280
+ client .PrependReactor ("list" , "pods" , func (_ ktesting.Action ) (handled bool , ret runtime.Object , err error ) {
281
+ list := & unstructured.UnstructuredList {
282
+ Object : map [string ]interface {}{
283
+ "metadata" : map [string ]interface {}{
284
+ "continue" : "pod-continue-token" ,
285
+ },
286
+ },
287
+ Items : []unstructured.Unstructured {
288
+ {
289
+ Object : map [string ]interface {}{
290
+ "apiVersion" : "v1" ,
291
+ "kind" : "Pod" ,
292
+ "metadata" : map [string ]interface {}{
293
+ "name" : "test-pod" ,
294
+ "namespace" : "default" ,
295
+ },
296
+ },
297
+ },
298
+ },
299
+ }
300
+ return true , list , nil
301
+ })
302
+
303
+ // Test that the function accepts pagination parameters and returns results
304
+ ctx := context .Background ()
305
+
306
+ // Test with limit
307
+ list , err := testClient .ListNamespacedResources (ctx , gvr , "default" , "" , 5 , "" )
308
+ assert .NoError (t , err , "ListNamespacedResources with limit should not return an error" )
309
+ assert .NotNil (t , list , "List should not be nil" )
310
+ assert .Equal (t , "pod-continue-token" , list .GetContinue (), "Continue token should be preserved in response" )
311
+
312
+ // Test with continue token
313
+ list , err = testClient .ListNamespacedResources (ctx , gvr , "default" , "" , 0 , "pod-token" )
314
+ assert .NoError (t , err , "ListNamespacedResources with continue token should not return an error" )
315
+ assert .NotNil (t , list , "List should not be nil" )
316
+ }
317
+
201
318
func TestApplyClusteredResource (t * testing.T ) {
202
319
// Create a fake dynamic client
203
320
scheme := runtime .NewScheme ()
0 commit comments