1
0
mirror of https://github.com/rancher/steve.git synced 2025-04-28 03:10:32 +00:00

Fix the ListOptions sort field.

Instead of making it a single array-ish field, convert it into a
true array of Sort Directives.  Easier to read, less bending backwards.
This commit is contained in:
Eric Promislow 2025-04-24 14:57:32 -07:00
parent ec49b857fa
commit a0d591a9b5
3 changed files with 5 additions and 37 deletions

View File

@ -6,7 +6,6 @@ import (
"encoding/gob"
"errors"
"fmt"
"github.com/rancher/steve/pkg/sqlcache/sqltypes"
"regexp"
"sort"
"strconv"

View File

@ -817,27 +817,6 @@ func TestListByOptions(t *testing.T) {
expectedErr: nil,
})
tests = append(tests, testCase{
description: "ListByOptions sorting when # fields != # sort orders should return an error",
listOptions: sqltypes.ListOptions{
Sort: sqltypes.Sort{
Fields: [][]string{{"metadata", "somefield"}, {"status", "someotherfield"}},
Orders: []sqltypes.SortOrder{sqltypes.DESC, sqltypes.ASC, sqltypes.ASC},
},
},
partitions: []partition.Partition{},
ns: "",
expectedStmt: `SELECT o.object, o.objectnonce, o.dekid FROM "something" o
JOIN "something_fields" f ON o.key = f.key
WHERE
(FALSE)
ORDER BY f."metadata.somefield" DESC, f."status.someotherfield" ASC`,
returnList: []any{&unstructured.Unstructured{Object: unstrTestObjectMap}, &unstructured.Unstructured{Object: unstrTestObjectMap}},
expectedList: &unstructured.UnstructuredList{Object: map[string]interface{}{"items": []map[string]interface{}{unstrTestObjectMap, unstrTestObjectMap}}, Items: []unstructured.Unstructured{{Object: unstrTestObjectMap}, {Object: unstrTestObjectMap}}},
expectedContToken: "",
expectedErr: fmt.Errorf("sort fields length 2 != sort orders length 3"),
})
tests = append(tests, testCase{
description: "ListByOptions with Pagination.PageSize set should set limit to PageSize in prepared sql.Stmt",
listOptions: sqltypes.ListOptions{

View File

@ -40,10 +40,10 @@ type ListOptions struct {
//
// If more than one value is given for the `Match` field, we do an "IN (<values>)" test
type Filter struct {
Field []string
Matches []string
Op Op
Partial bool
Field []string
Matches []string
Op Op
Partial bool
}
// OrFilter represents a set of possible fields to filter by, where an item may match any filter in the set to be included in the result.
@ -65,20 +65,10 @@ type SortList struct {
SortDirectives []Sort
}
type SortList struct {
SortDirectives []Sort
}
// Pagination represents how to return paginated results.
type Pagination struct {
PageSize int
Page int
}
func NewSortList() *SortList {
return &SortList{
SortDirectives: []Sort{},
}
Page int
}
func NewSortList() *SortList {