mirror of
https://github.com/rancher/steve.git
synced 2025-09-15 23:08:26 +00:00
Keep track of events for SQL cache watches (#661)
* Keep track of past events * Clarify RV acronym * Fix comment typo * Rename listEvents variables * Improve filter readability * Move defer
This commit is contained in:
@@ -143,10 +143,10 @@ func (mr *MockUnstructuredStoreMockRecorder) Delete(arg0, arg1, arg2 any) *gomoc
|
||||
}
|
||||
|
||||
// ListByPartitions mocks base method.
|
||||
func (m *MockUnstructuredStore) ListByPartitions(arg0 *types.APIRequest, arg1 *types.APISchema, arg2 []partition.Partition) ([]unstructured.Unstructured, int, string, error) {
|
||||
func (m *MockUnstructuredStore) ListByPartitions(arg0 *types.APIRequest, arg1 *types.APISchema, arg2 []partition.Partition) (*unstructured.UnstructuredList, int, string, error) {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "ListByPartitions", arg0, arg1, arg2)
|
||||
ret0, _ := ret[0].([]unstructured.Unstructured)
|
||||
ret0, _ := ret[0].(*unstructured.UnstructuredList)
|
||||
ret1, _ := ret[1].(int)
|
||||
ret2, _ := ret[2].(string)
|
||||
ret3, _ := ret[3].(error)
|
||||
|
@@ -29,7 +29,7 @@ type UnstructuredStore interface {
|
||||
Update(apiOp *types.APIRequest, schema *types.APISchema, data types.APIObject, id string) (*unstructured.Unstructured, []types.Warning, error)
|
||||
Delete(apiOp *types.APIRequest, schema *types.APISchema, id string) (*unstructured.Unstructured, []types.Warning, error)
|
||||
|
||||
ListByPartitions(apiOp *types.APIRequest, schema *types.APISchema, partitions []partition.Partition) ([]unstructured.Unstructured, int, string, error)
|
||||
ListByPartitions(apiOp *types.APIRequest, schema *types.APISchema, partitions []partition.Partition) (*unstructured.UnstructuredList, int, string, error)
|
||||
WatchByPartitions(apiOp *types.APIRequest, schema *types.APISchema, wr types.WatchRequest, partitions []partition.Partition) (chan watch.Event, error)
|
||||
}
|
||||
|
||||
|
@@ -92,7 +92,7 @@ func (s *Store) List(apiOp *types.APIRequest, schema *types.APISchema) (types.AP
|
||||
|
||||
result.Count = total
|
||||
|
||||
for _, item := range list {
|
||||
for _, item := range list.Items {
|
||||
item := item.DeepCopy()
|
||||
// the sql cache automatically adds the ID through a transformFunc. Because of this, we have a different set of reserved fields for the SQL cache
|
||||
result.Objects = append(result.Objects, partition.ToAPI(schema, item, nil, s.sqlReservedFields))
|
||||
@@ -100,6 +100,7 @@ func (s *Store) List(apiOp *types.APIRequest, schema *types.APISchema) (types.AP
|
||||
|
||||
result.Revision = ""
|
||||
result.Continue = continueToken
|
||||
result.Revision = list.GetResourceVersion()
|
||||
return result, nil
|
||||
}
|
||||
|
||||
|
@@ -51,16 +51,18 @@ func TestList(t *testing.T) {
|
||||
Schema: &schemas.Schema{},
|
||||
}
|
||||
partitions := make([]partition.Partition, 0)
|
||||
uListToReturn := []unstructured.Unstructured{
|
||||
{
|
||||
Object: map[string]interface{}{
|
||||
"kind": "apple",
|
||||
"metadata": map[string]interface{}{
|
||||
"name": "fuji",
|
||||
"namespace": "fruitsnamespace",
|
||||
},
|
||||
"data": map[string]interface{}{
|
||||
"color": "pink",
|
||||
uListToReturn := &unstructured.UnstructuredList{
|
||||
Items: []unstructured.Unstructured{
|
||||
{
|
||||
Object: map[string]interface{}{
|
||||
"kind": "apple",
|
||||
"metadata": map[string]interface{}{
|
||||
"name": "fuji",
|
||||
"namespace": "fruitsnamespace",
|
||||
},
|
||||
"data": map[string]interface{}{
|
||||
"color": "pink",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -88,7 +90,7 @@ func TestList(t *testing.T) {
|
||||
}
|
||||
p.EXPECT().All(req, schema, "list", "").Return(partitions, nil)
|
||||
p.EXPECT().Store().Return(us)
|
||||
us.EXPECT().ListByPartitions(req, schema, partitions).Return(uListToReturn, len(uListToReturn), "", nil)
|
||||
us.EXPECT().ListByPartitions(req, schema, partitions).Return(uListToReturn, len(uListToReturn.Items), "", nil)
|
||||
l, err := s.List(req, schema)
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, expectedAPIObjList, l)
|
||||
|
Reference in New Issue
Block a user