| 58 | } |
| 59 | |
| 60 | func (r *mockReader) List(ctx context.Context, list client.ObjectList, opts ...client.ListOption) error { |
| 61 | items := reflect.ValueOf(list).Elem().FieldByName("Items") |
| 62 | if !items.IsValid() { |
| 63 | return fmt.Errorf("ObjectList has no Items field: %s", list.GetObjectKind().GroupVersionKind().String()) |
| 64 | } |
| 65 | objects := reflect.MakeSlice(items.Type(), 0, 0) |
| 66 | |
| 67 | listOpts := &client.ListOptions{} |
| 68 | for _, opt := range opts { |
| 69 | opt.ApplyToList(listOpts) |
| 70 | } |
| 71 | for i, o := range r.objs { |
| 72 | // ignore the GVK check |
| 73 | if listOpts.LabelSelector != nil { |
| 74 | if listOpts.LabelSelector.Matches(labels.Set(o.GetLabels())) { |
| 75 | objects = reflect.Append(objects, reflect.ValueOf(r.objs[i]).Elem()) |
| 76 | } |
| 77 | } |
| 78 | } |
| 79 | if objects.Len() != 0 { |
| 80 | items.Set(objects) |
| 81 | return nil |
| 82 | } |
| 83 | return r.cli.List(ctx, list, opts...) |
| 84 | } |
| 85 | |
| 86 | var mockKBAgentClient = func(mock func(*kbacli.MockClientMockRecorder)) { |
| 87 | cli := kbacli.NewMockClient(gomock.NewController(GinkgoT())) |