I'm trying to list CRD objects using Limit as follows:
...
someObjList := v1alpha1.SomeObjList{}
_ = cl.List(ctx, &someObjList, client.InNamespace(lib.Namespace), &listOptions)
When testing, I add 25 objects to a fake client then call the list function with a Limit of 10:
opts := client.ListOptions{
Limit: 10,
}
result, _ := lib.List(context.Background(), opts)
assert.Equal(t, 10, len(result))
But the test fails with:
assertion failed: 10 (int) != 25 (int)
I'm not sure if I need to add something specific to the fake client in order to make this work. This is the current client I use in tests:
func makeClient(t *testing.T, clusterState ...runtime.Object) client.Client {
scheme := runtime.NewScheme()
schemeBuilder := runtime.SchemeBuilder{
...
}
err := schemeBuilder.AddToScheme(scheme)
if err != nil {
t.Fatal(err)
}
return fake.NewClientBuilder().
WithScheme(scheme).
WithRuntimeObjects(clusterState...).
Build()
}