mirror of
https://github.com/rancher/steve.git
synced 2025-09-15 23:08:26 +00:00
sql: bugfix: return total resource count correctly (#236)
* sql: drop dead code Signed-off-by: Silvio Moioli <silvio@moioli.net> * sql: bugfix: return total resource count correctly Signed-off-by: Silvio Moioli <silvio@moioli.net> * adapt tests Signed-off-by: Silvio Moioli <silvio@moioli.net> * adapt mocks Signed-off-by: Silvio Moioli <silvio@moioli.net> * TEMP: remove this when bumping lasso to include https://github.com/rancher/lasso/pull/84 Signed-off-by: Silvio Moioli <silvio@moioli.net> * Use latest lasso instead of fork --------- Signed-off-by: Silvio Moioli <silvio@moioli.net> Co-authored-by: Tom Lebreux <tom.lebreux@suse.com>
This commit is contained in:
@@ -44,8 +44,13 @@ type ListOptions struct {
|
||||
}
|
||||
|
||||
type Cache interface {
|
||||
// ListByOptions returns objects according to the specified list options and partitions
|
||||
ListByOptions(ctx context.Context, lo informer.ListOptions, partitions []partition.Partition, namespace string) (*unstructured.UnstructuredList, string, error)
|
||||
// ListByOptions returns objects according to the specified list options and partitions.
|
||||
// Specifically:
|
||||
// - an unstructured list of resources belonging to any of the specified partitions
|
||||
// - the total number of resources (returned list might be a subset depending on pagination options in lo)
|
||||
// - a continue token, if there are more pages after the returned one
|
||||
// - an error instead of all of the above if anything went wrong
|
||||
ListByOptions(ctx context.Context, lo informer.ListOptions, partitions []partition.Partition, namespace string) (*unstructured.UnstructuredList, int, string, error)
|
||||
}
|
||||
|
||||
// ParseQuery parses the query params of a request and returns a ListOptions.
|
||||
@@ -160,7 +165,7 @@ func getLimit(apiOp *types.APIRequest) int {
|
||||
func parseNamespaceOrProjectFilters(ctx context.Context, projOrNS string, op informer.Op, namespaceInformer Cache) ([]informer.Filter, error) {
|
||||
var filters []informer.Filter
|
||||
for _, pn := range strings.Split(projOrNS, ",") {
|
||||
uList, _, err := namespaceInformer.ListByOptions(ctx, informer.ListOptions{
|
||||
uList, _, _, err := namespaceInformer.ListByOptions(ctx, informer.ListOptions{
|
||||
Filters: []informer.OrFilter{
|
||||
{
|
||||
Filters: []informer.Filter{
|
||||
|
@@ -101,7 +101,7 @@ func TestParseQuery(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
}, []partition.Partition{{Passthrough: true}}, "").Return(list, "", nil)
|
||||
}, []partition.Partition{{Passthrough: true}}, "").Return(list, len(list.Items), "", nil)
|
||||
return nsc
|
||||
},
|
||||
})
|
||||
@@ -151,7 +151,7 @@ func TestParseQuery(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
}, []partition.Partition{{Passthrough: true}}, "").Return(nil, "", fmt.Errorf("error"))
|
||||
}, []partition.Partition{{Passthrough: true}}, "").Return(nil, 0, "", fmt.Errorf("error"))
|
||||
return nsi
|
||||
},
|
||||
})
|
||||
@@ -204,7 +204,7 @@ func TestParseQuery(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
}, []partition.Partition{{Passthrough: true}}, "").Return(list, "", nil)
|
||||
}, []partition.Partition{{Passthrough: true}}, "").Return(list, len(list.Items), "", nil)
|
||||
return nsi
|
||||
},
|
||||
})
|
||||
|
@@ -38,13 +38,14 @@ func (m *MockCache) EXPECT() *MockCacheMockRecorder {
|
||||
}
|
||||
|
||||
// ListByOptions mocks base method.
|
||||
func (m *MockCache) ListByOptions(arg0 context.Context, arg1 informer.ListOptions, arg2 []partition.Partition, arg3 string) (*unstructured.UnstructuredList, string, error) {
|
||||
func (m *MockCache) ListByOptions(arg0 context.Context, arg1 informer.ListOptions, arg2 []partition.Partition, arg3 string) (*unstructured.UnstructuredList, int, string, error) {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "ListByOptions", arg0, arg1, arg2, arg3)
|
||||
ret0, _ := ret[0].(*unstructured.UnstructuredList)
|
||||
ret1, _ := ret[1].(string)
|
||||
ret2, _ := ret[2].(error)
|
||||
return ret0, ret1, ret2
|
||||
ret1, _ := ret[1].(int)
|
||||
ret2, _ := ret[2].(string)
|
||||
ret3, _ := ret[3].(error)
|
||||
return ret0, ret1, ret2, ret3
|
||||
}
|
||||
|
||||
// ListByOptions indicates an expected call of ListByOptions.
|
||||
|
Reference in New Issue
Block a user